import { useState } from 'react'; import { Card } from '@/components/ui/card'; import { Label } from '@/components/ui/label'; import { Badge } from '@/components/ui/badge'; import { Button } from '@/components/ui/button'; import { Image as ImageIcon, ImagePlus, X } from 'lucide-react'; import { UppyPhotoUploadLazy } from './UppyPhotoUploadLazy'; import { getCloudflareImageUrl } from '@/lib/cloudflareImageUtils'; export type ImageType = 'logo' | 'banner' | 'card'; interface ImageSlot { type: ImageType; url?: string; id?: string; } interface EntityImageUploaderProps { images: { logo?: { url?: string; id?: string }; banner?: { url?: string; id?: string }; card?: { url?: string; id?: string }; }; onImagesChange: (images: { logo_url?: string; banner_image_id?: string; banner_image_url?: string; card_image_id?: string; card_image_url?: string; }) => void; showLogo?: boolean; entityType?: string; } const IMAGE_SPECS = { logo: { label: 'Logo', aspect: '1:1', dimensions: '400x400', description: 'Square logo image' }, banner: { label: 'Banner', aspect: '21:9', dimensions: '1920x820', description: 'Wide header image' }, card: { label: 'Card', aspect: '16:9', dimensions: '1200x675', description: 'Preview thumbnail' } }; export function EntityImageUploader({ images, onImagesChange, showLogo = true, entityType = 'entity' }: EntityImageUploaderProps) { const [activeSlot, setActiveSlot] = useState(null); const handleUploadComplete = (type: ImageType, urls: string[]) => { if (urls.length === 0) return; const url = urls[0]; const id = url.split('/').pop()?.split('?')[0] || ''; const updates: any = {}; if (type === 'logo') { updates.logo_url = url; } else if (type === 'banner') { updates.banner_image_id = id; updates.banner_image_url = url; } else if (type === 'card') { updates.card_image_id = id; updates.card_image_url = url; } onImagesChange({ logo_url: type === 'logo' ? url : images.logo?.url, banner_image_id: type === 'banner' ? id : images.banner?.id, banner_image_url: type === 'banner' ? url : images.banner?.url, card_image_id: type === 'card' ? id : images.card?.id, card_image_url: type === 'card' ? url : images.card?.url }); setActiveSlot(null); }; const handleRemoveImage = (type: ImageType) => { const updates: any = { logo_url: images.logo?.url, banner_image_id: images.banner?.id, banner_image_url: images.banner?.url, card_image_id: images.card?.id, card_image_url: images.card?.url }; if (type === 'logo') { updates.logo_url = undefined; } else if (type === 'banner') { updates.banner_image_id = undefined; updates.banner_image_url = undefined; } else if (type === 'card') { updates.card_image_id = undefined; updates.card_image_url = undefined; } onImagesChange(updates); }; const renderImageSlot = (type: ImageType) => { if (type === 'logo' && !showLogo) return null; const spec = IMAGE_SPECS[type]; const currentImage = type === 'logo' ? images.logo : type === 'banner' ? images.banner : images.card; const hasImage = currentImage?.url; if (activeSlot === type) { return (
{spec.aspect} • {spec.dimensions}

{spec.description}

handleUploadComplete(type, urls)} maxFiles={1} variant="compact" allowedFileTypes={['image/jpeg', 'image/jpg', 'image/png', 'image/webp']} />
); } return ( {hasImage ? (
{`${spec.label}
{spec.label}
) : ( )}
); }; return (
Recommended formats: JPG, PNG, WebP
{showLogo && renderImageSlot('logo')} {renderImageSlot('banner')} {renderImageSlot('card')}
); }