import React, { useCallback, useState } from 'react'; import { getSectorDisplay } from '@/constants.tsx'; import { useTranslation } from '@/hooks/useI18n.tsx'; import { useToggle } from '@/hooks/useToggle'; import { getTranslatedSectorName, mapBackendSectorToTranslationKey } from '@/lib/sector-mapper.ts'; import { getOrganizationSubtypeLabel } from '@/schemas/organizationSubtype.ts'; import { Organization } from '@/types.ts'; import { Pencil } from 'lucide-react'; import Badge from '@/components/ui/Badge.tsx'; import Button from '@/components/ui/Button.tsx'; import { Card } from '@/components/ui/Card.tsx'; import ImageGallery from '@/components/ui/ImageGallery.tsx'; import ImageUpload from '@/components/ui/ImageUpload.tsx'; import VerifiedBadge from '@/components/ui/VerifiedBadge.tsx'; interface OrganizationHeaderProps { organization: Organization; onUpdateOrganization?: (org: Organization) => void; } const OrganizationHeader = ({ organization, onUpdateOrganization }: OrganizationHeaderProps) => { const { t } = useTranslation(); const isEditingLogo = useToggle(false); const isEditingGallery = useToggle(false); const [logo, setLogo] = useState(organization.LogoURL); const [galleryImages, setGalleryImages] = useState(organization.GalleryImages || []); const sectorDisplay = getSectorDisplay(organization.Sector); const handleSaveLogo = useCallback(() => { if (onUpdateOrganization) { onUpdateOrganization({ ...organization, LogoURL: logo }); } isEditingLogo.setFalse(); }, [onUpdateOrganization, organization, logo, isEditingLogo]); const handleCancelLogoEdit = useCallback(() => { setLogo(organization.LogoURL); isEditingLogo.setFalse(); }, [organization.LogoURL, isEditingLogo]); const handleSaveGallery = useCallback(() => { if (onUpdateOrganization) { onUpdateOrganization({ ...organization, GalleryImages: galleryImages }); } isEditingGallery.setFalse(); }, [onUpdateOrganization, organization, galleryImages, isEditingGallery]); const handleCancelGalleryEdit = useCallback(() => { setGalleryImages(organization.GalleryImages || []); isEditingGallery.setFalse(); }, [organization.GalleryImages, isEditingGallery]); return (
{organization.LogoURL ? ( {t('imageUpload.logoAlt', { (e.target as HTMLImageElement).style.display = 'none'; }} className="max-w-full max-h-full object-contain" /> ) : ( React.cloneElement(sectorDisplay.icon, { className: 'w-16 h-16 text-muted-foreground', }) )}
{onUpdateOrganization && ( )}

{organization.Name}

{getTranslatedSectorName(organization.Sector, t)}

{organization.Subtype && ( <> · {getOrganizationSubtypeLabel(organization.Subtype)} )} {organization.Verified && ( <> · )}
{isEditingLogo.value && onUpdateOrganization && (
)} {/* Gallery Images Section */} {(organization.GalleryImages?.length > 0 || (onUpdateOrganization && isEditingGallery.value)) && (

{t('organizationPage.gallery.title')}

{onUpdateOrganization && ( )}
{isEditingGallery.value && onUpdateOrganization ? (
) : ( )}
)}
); }; export default React.memo(OrganizationHeader);