import React, { useState } from 'react'; import { Button } from './ui/button'; import { Input } from './ui/input'; import { Save, FileJson, FileBox } from 'lucide-react'; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from './ui/dialog'; import { useProjects } from '../lib/hooks/useProjects'; import { useWindStore } from '../store/appStore'; interface SaveModuleDialogProps { moduleType: 'galpao' | 'cilindro' | 'vault' | 'dome' | 'sign' | 'isolated-roof' | 'bar' | 'bridge' | 'dynamics' | 'piperack'; inputs: Record; triggerButton?: React.ReactNode; } export const SaveModuleDialog: React.FC = ({ moduleType, inputs, triggerButton }) => { const { save } = useProjects(); const windStore = useWindStore(); const [open, setOpen] = useState(false); const [name, setName] = useState(''); const [type, setType] = useState<'projeto' | 'template'>('projeto'); // Gera um nome sugerido ao abrir React.useEffect(() => { if (open && !name) { const date = new Date().toLocaleDateString('pt-BR').replace(/\//g, ''); const prefix = type === 'projeto' ? 'PRJ' : 'TPL'; const modName = moduleType.charAt(0).toUpperCase() + moduleType.slice(1); setName(`${prefix}-${modName}-${date}`); } }, [open, type, moduleType, name]); const handleSave = async () => { if (!name.trim()) return; const windData = type === 'projeto' ? { v0: windStore.v0, s1: windStore.s1, s3: windStore.s3, s3Group: windStore.s3Group, terrainCategory: windStore.terrainCategory, largestDimension: windStore.largestDimension, heightZ: windStore.heightZ, } : undefined; await save({ name, type, module: moduleType, inputs, windData, createdAt: Date.now(), updatedAt: Date.now(), }); setOpen(false); }; return ( {triggerButton || ( )} Salvar Módulo Escolha como deseja salvar este módulo. Projetos incluem os dados de vento atuais. Templates salvam apenas a geometria da estrutura.
setName(e.target.value)} placeholder="Digite um nome para identificar..." />
); };