Spaces:
Running
Running
File size: 5,169 Bytes
693b4bc | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | 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>
);
}
|