const { Card, Button, Icon, IconButton, Input, Select, Modal, Badge, StatusPill, PriorityBadge, EmptyState, DataTable, StatCard, Textarea } = window.ACRFlowDesignSystem_ba1e9c; const slugify = (s) => s.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, "").replace(/[^a-z0-9]+/g, "_").replace(/(^_|_$)/g, ""); const TONES = [ { value: "st-aberta", label: "Azul — recém aberta" }, { value: "st-triagem", label: "Roxo — triagem" }, { value: "st-andamento", label: "Verde — em execução" }, { value: "st-aguardando", label: "Âmbar — aguardando" }, { value: "st-aprovacao", label: "Índigo — aprovação" }, { value: "st-encerrada", label: "Cinza — encerrada" }, { value: "st-reaberta", label: "Vermelho — reaberta" }, ]; const PRIO_TONES = [{ value: "baixa", label: "Baixa" }, { value: "normal", label: "Normal" }, { value: "alta", label: "Alta" }, { value: "urgente", label: "Urgente" }]; function WorkflowScreen({ onToast }) { const D = window.useStore(); const S = window.ACRStore; const statuses = D.statuses || []; const priorities = D.priorities || []; const [salvando, setSalvando] = React.useState(false); const falhou = (r) => { if (!r.ok) { onToast({ tone: "danger", title: "Não foi possível gravar", message: r.error }); return true; } return false; }; const [statusForm, setStatusForm] = React.useState(null); const [prioForm, setPrioForm] = React.useState(null); const [remove, setRemove] = React.useState(null); const useCount = (kind, id) => D.demands.filter((d) => (kind === "status" ? d.status : d.priority) === id).length; const saveStatus = async () => { const f = statusForm; if (!f.name || !f.name.trim()) { onToast({ tone: "danger", title: "Informe o nome", message: "O nome do status é obrigatório." }); return; } setSalvando(true); const r = await S.salvarStatus({ ...f, existing: !!f.id }); setSalvando(false); if (falhou(r)) return; onToast({ tone: "success", title: f.id ? "Status atualizado" : "Status criado", message: f.name }); setStatusForm(null); }; const savePrio = async () => { const f = prioForm; if (!f.name || !f.name.trim()) { onToast({ tone: "danger", title: "Informe o nome", message: "O nome da prioridade é obrigatório." }); return; } setSalvando(true); const r = await S.salvarPrioridade({ ...f, existing: !!f.id }); setSalvando(false); if (falhou(r)) return; onToast({ tone: "success", title: f.id ? "Prioridade atualizada" : "Prioridade criada", message: f.name }); setPrioForm(null); }; const doRemove = async () => { setSalvando(true); const r = remove.kind === "status" ? await S.removerStatus(remove.item.id) : await S.removerPrioridade(remove.item.id); setSalvando(false); if (falhou(r)) return; onToast({ tone: "danger", title: remove.kind === "status" ? "Status removido" : "Prioridade removida", message: remove.item.name }); setRemove(null); }; return (