import { useState, useRef } from 'react' import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter } from '@/components/ui/dialog' import { Button } from '@/components/ui/button' import { Input } from '@/components/ui/input' import { Label } from '@/components/ui/label' import type { FloorMapConfig } from '@/types' interface FloorMapModalProps { open: boolean onClose: () => void onSubmit: (config: FloorMapConfig) => void onRemove: () => void initial: FloorMapConfig | null } export function FloorMapModal({ open, onClose, onSubmit, onRemove, initial }: FloorMapModalProps) { const [imageData, setImageData] = useState(initial?.imageData ?? '') const [width, setWidth] = useState(initial?.width ?? 800) const [height, setHeight] = useState(initial?.height ?? 600) const [opacity, setOpacity] = useState(initial?.opacity ?? 0.8) const [locked, setLocked] = useState(initial?.locked ?? false) const [enabled, setEnabled] = useState(initial?.enabled ?? true) const fileRef = useRef(null) const handleFile = (e: React.ChangeEvent) => { const file = e.target.files?.[0] if (!file) return const reader = new FileReader() reader.onload = (ev) => { const dataUrl = ev.target?.result as string setImageData(dataUrl) const img = new Image() img.onload = () => { setWidth(img.naturalWidth) setHeight(img.naturalHeight) } img.src = dataUrl } reader.readAsDataURL(file) } const handleSubmit = () => { if (!imageData) return onSubmit({ imageData, posX: initial?.posX ?? 0, posY: initial?.posY ?? 0, width, height, opacity, locked, enabled, }) } const hasImage = !!imageData return ( { if (!o) onClose() }}> {initial ? 'Edit Floor Plan' : 'Import Floor Plan'}
{!hasImage ? (
fileRef.current?.click()} > Click to select a floor plan image PNG, JPEG or WebP
) : ( <>
Floor plan preview
setWidth(Math.max(80, Number(e.target.value)))} className="bg-[#21262d] border-[#30363d] text-xs h-8" />
setHeight(Math.max(80, Number(e.target.value)))} className="bg-[#21262d] border-[#30363d] text-xs h-8" />
setOpacity(Number(e.target.value))} className="w-full accent-[#00d4ff]" />
)}
{hasImage && initial && ( )}
) }