simuladorcnc / src /components /ProjectModal.jsx
amauricunha's picture
feat: reestrutura simulador cnc em react modular com threejs e tailwindcss
693b4bc
Raw History Blame Contribute Delete
5.17 kB
import React, { useState, useEffect } from 'react';
import { TOOL_CATALOG } from '../constants/tools.js';
export default function ProjectModal({
isOpen,
mode, // 'create' | 'edit' | 'delete'
activeProject,
onClose,
onConfirm
}) {
const [title, setTitle] = useState('');
const [toolNum, setToolNum] = useState('08');
const [template, setTemplate] = useState('template');
useEffect(() => {
if (mode === 'create') {
setTitle('Novo Projeto CNC');
setToolNum('08');
setTemplate('template');
} else if (mode === 'edit' && activeProject) {
setTitle(activeProject.title || '');
setToolNum(activeProject.toolNumber || '08');
}
}, [mode, activeProject, isOpen]);
if (!isOpen) return null;
const handleConfirm = () => {
onConfirm({
mode,
title: title.trim() || 'Projeto Sem Nome',
toolNum,
template
});
};
return (
<div className="fixed inset-0 bg-black/60 backdrop-blur-sm z-50 flex items-center justify-center p-4">
<div className="bg-slate-900 border-2 border-blue-500/70 rounded-2xl p-4 shadow-2xl max-w-md w-full flex flex-col gap-3 animate-scale-in">
<div className="flex items-center justify-between border-b border-slate-800 pb-2">
<span className="text-sm font-bold text-sky-400">
{mode === 'create' && '✨ Cadastrar Novo Projeto CNC'}
{mode === 'edit' && '✏️ Editar Projeto Atual'}
{mode === 'delete' && '🗑️ Confirmar Exclusão'}
</span>
<button
type="button"
onClick={onClose}
className="text-slate-400 hover:text-white text-base font-bold px-1"
>
✕
</button>
</div>
{mode === 'delete' ? (
<p className="text-xs text-slate-300 leading-relaxed py-2">
Deseja realmente excluir o projeto <strong className="text-rose-400 font-bold">"{activeProject?.title}"</strong>? Esta ação não pode ser desfeita.
</p>
) : (
<div className="flex flex-col gap-3 py-1">
<div>
<label className="block text-[10px] font-bold uppercase text-slate-400 mb-1">
Nome / Título do Projeto:
</label>
<input
type="text"
value={title}
onChange={(e) => setTitle(e.target.value)}
placeholder="Ex: Peça com Canais e Furos"
className="w-full bg-slate-950 border border-slate-700 rounded-lg px-3 py-2 text-xs text-white focus:outline-none focus:border-blue-500 shadow-inner"
/>
</div>
<div className="grid grid-cols-2 gap-2">
<div>
<label className="block text-[10px] font-bold uppercase text-slate-400 mb-1">
Ferramenta Inicial:
</label>
<select
value={toolNum}
onChange={(e) => setToolNum(e.target.value)}
className="w-full bg-slate-950 border border-slate-700 rounded-lg px-2 py-2 text-xs text-amber-300 font-mono focus:outline-none focus:border-blue-500"
>
{Object.values(TOOL_CATALOG).map((t) => (
<option key={t.num} value={t.num}>
T{t.num} - {t.name}
</option>
))}
</select>
</div>
{mode === 'create' && (
<div>
<label className="block text-[10px] font-bold uppercase text-slate-400 mb-1">
Código Inicial:
</label>
<select
value={template}
onChange={(e) => setTemplate(e.target.value)}
className="w-full bg-slate-950 border border-slate-700 rounded-lg px-2 py-2 text-xs text-slate-200 focus:outline-none focus:border-blue-500"
>
<option value="template">Template ISO Padrão</option>
<option value="current">Copiar Código Atual</option>
<option value="empty">Cabeçalho Mínimo</option>
</select>
</div>
)}
</div>
</div>
)}
<div className="flex items-center justify-end gap-2 pt-2 border-t border-slate-800">
<button
type="button"
onClick={onClose}
className="px-3.5 py-1.5 bg-slate-800 hover:bg-slate-700 text-slate-300 rounded-lg text-xs font-semibold transition-colors"
>
Cancelar
</button>
<button
type="button"
onClick={handleConfirm}
className={`px-4 py-1.5 text-white rounded-lg text-xs font-bold shadow-md transition-colors ${
mode === 'delete'
? 'bg-rose-600 hover:bg-rose-500'
: 'bg-emerald-600 hover:bg-emerald-500'
}`}
>
{mode === 'delete' ? 'Excluir Projeto' : 'Confirmar'}
</button>
</div>
</div>
</div>
);
}