1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-zO3nSPIa.js","assets/vendor-three-BGGFfWe7.js","assets/index-CT5dCvr7.css"])))=>i.map(i=>d[i]); 2import{j as e,r as w,d as Se}from"./vendor-three-BGGFfWe7.js";import{bL as ke,aS as Ee,ee as Ae,V as qe,ej as De,cZ as Le,ek as Pe,aa as Te,bj as Fe,ab as se,el as Je,u as O,aM as be,ae as I,R as ae,aP as ge,ak as K,d$ as Re,a9 as $e,em as Ie,en as he,eo as fe,d as ve,z as B,ay as Ke,aK as je,a8 as Me,c6 as Oe,aD as Be,ep as Qe,_ as Ve,bm as Ge,a as He,an as Ue,bF as ze,eh as te,L as We,eq as ce,bs as Xe,b as ue}from"./index-zO3nSPIa.js";import{j as J}from"./journeyIntegrations-JDwnQRS9.js";import{u as Ze,a as Ye,R as et,N as me,T as xe}from"./RecordLayoutEditor-DwW1cWHC.js";import tt,{DEFAULT_ACTIONS_MENU as at}from"./RecordHeaderCard--QgBLzqJ.js";import{H as st}from"./hand-BZ37xoV_.js";import{f as rt}from"./formIntegrations-gLbNzCIG.js";import{F as pe}from"./file-stack-By46rjbf.js";import"./maximize-2-BtQSNMu7.js";import"./GovBrFileDropzone-Ds6UK-Gw.js";import"./saveComposition-DsESjB1n.js";import"./popover-ck287Se2.js";const Q=[{id:"document_collection",label:"Coleta de documentos",icon:ke,color:"text-blue-600",bg:"bg-blue-50",border:"border-blue-200"},{id:"form_submission",label:"Formulário",icon:Ee,color:"text-purple-600",bg:"bg-purple-50",border:"border-purple-200"},{id:"video_watching",label:"VÃdeo",icon:Ae,color:"text-red-600",bg:"bg-red-50",border:"border-red-200"},{id:"meeting",label:"Reunião",icon:qe,color:"text-emerald-600",bg:"bg-emerald-50",border:"border-emerald-200"},{id:"review",label:"Revisão",icon:De,color:"text-amber-600",bg:"bg-amber-50",border:"border-amber-200"},{id:"automated",label:"Automação",icon:Le,color:"text-indigo-600",bg:"bg-indigo-50",border:"border-indigo-200"},{id:"manual",label:"Manual",icon:st,color:"text-foreground/70",bg:"bg-muted",border:"border-border"}];function Ne(t){return Q.find(c=>c.id===t)||Q[Q.length-1]}function ot({step:t,index:c,total:l,onEdit:b,onDuplicate:y,onDelete:S,dragHandleProps:r,formsMap:g}){var C;const o=Ne(t.kind),h=o.icon;return e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:`rounded-xl border ${o.border} ${o.bg} bg-card p-3 shadow-sm transition-shadow hover:shadow-md`,children:e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx("div",{...r,className:"flex h-8 w-8 shrink-0 cursor-grab items-center justify-center rounded-lg text-muted-foreground/70 hover:bg-muted active:cursor-grabbing",children:e.jsx(Pe,{className:"h-4 w-4"})}),e.jsx("div",{className:`flex h-9 w-9 shrink-0 items-center justify-center rounded-xl ${o.bg} ${o.color}`,children:e.jsx(h,{className:"h-4 w-4"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-[9px] font-semibold uppercase tracking-wide text-muted-foreground/70",children:["Etapa ",t.order||c+1]}),e.jsx("span",{className:`rounded-full ${o.bg} ${o.color} px-1.5 py-0.5 text-[9px] font-medium`,children:o.label}),t.required&&e.jsx("span",{className:"rounded-full bg-rose-50 px-1.5 py-0.5 text-[9px] font-medium text-rose-600",children:"obrigatória"})]}),e.jsx("h3",{className:"mt-0.5 text-sm font-semibold text-foreground",children:t.title||"Sem tÃtulo"}),t.description&&e.jsx("p",{className:"mt-0.5 line-clamp-2 text-xs text-muted-foreground",children:t.description}),((C=t.document_requirements)==null?void 0:C.length)>0&&e.jsxs("p",{className:"mt-1 text-[10px] text-muted-foreground/70",children:[t.document_requirements.length," documento(s) exigido(s)"]}),t.estimated_duration_minutes&&e.jsxs("p",{className:"mt-0.5 text-[10px] text-muted-foreground/70",children:["~",t.estimated_duration_minutes," min"]}),t.kind==="form_submission"&&t.form_definition_id&&e.jsx("p",{className:"mt-0.5 truncate text-[10px] font-medium text-purple-600",children:(g==null?void 0:g.get(t.form_definition_id))||"Formulário vinculado"})]}),e.jsxs("div",{className:"flex shrink-0 gap-0.5",children:[e.jsx("button",{type:"button",onClick:()=>b(t,c),className:"flex h-7 w-7 items-center justify-center rounded-lg text-muted-foreground
2/70 hover:bg-card hover:text-primary","aria-label":"Editar etapa",children:e.jsx(Te,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button",onClick:()=>y(t,c),className:"flex h-7 w-7 items-center justify-center rounded-lg text-muted-foreground/70 hover:bg-card hover:text-blue-600","aria-label":"Duplicar etapa",children:e.jsx(Fe,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button",onClick:()=>S(t,c),className:"flex h-7 w-7 items-center justify-center rounded-lg text-muted-foreground/70 hover:bg-card hover:text-rose-600","aria-label":"Excluir etapa",children:e.jsx(se,{className:"h-3.5 w-3.5"})})]})]})}),c<l-1&&e.jsx("div",{className:"flex justify-center py-1",children:e.jsx(Je,{className:"h-4 w-4 text-muted-foreground/60"})})]})}function ye(){const t=O({queryKey:["forms-catalog"],queryFn:()=>rt.list(),staleTime:6e4,retry:!1}),c=t.data||[],l=new Map(c.map(b=>[b.id,b.name||b.slug||"Formulário"]));return{forms:c,formsMap:l,isLoading:t.isLoading}}const nt=[{id:"send_email",label:"Enviar e-mail ao cliente",description:"Dispara e-mail transacional quando a etapa inicia"},{id:"create_task",label:"Criar tarefa para a equipe",description:"Gera uma tarefa no módulo Tarefas ao concluir"},{id:"schedule_meeting",label:"Agendar reunião",description:"Abre o agendamento no Google Calendar"},{id:"request_documents",label:"Solicitar documentos",description:"Envia solicitação de documentos ao cliente"},{id:"notify_whatsapp",label:"Notificar via WhatsApp",description:"Envia mensagem no Balcão ao iniciar/concluir"},{id:"transition_case_phase",label:"Transição de fase do caso",description:"Avança a fase jurÃdica do caso ao concluir"}],it=[{id:"open_form",label:"Abrir formulário",description:"Cliente preenche um formulário vinculado"},{id:"watch_video",label:"Assistir vÃdeo",description:"Cliente assiste a um vÃdeo educativo"},{id:"upload_docs",label:"Enviar documentos",description:"Cliente anexa documentos solicitados"},{id:"book_meeting",label:"Agendar horário",description:"Cliente escolhe horário no calendário"},{id:"sign_contract",label:"Assinar contrato",description:"Cliente assina via assinatura eletrônica"},{id:"make_payment",label:"Realizar pagamento",description:"Cliente paga via portal financeiro"}];function lt({step:t,index:c,onSave:l,onClose:b}){const{forms:y,isLoading:S}=ye(),[r,g]=w.useState(()=>({id:(t==null?void 0:t.id)||`step-${Date.now().toString(36)}`,title:(t==null?void 0:t.title)||"",description:(t==null?void 0:t.description)||"",order:(t==null?void 0:t.order)||c+1,kind:(t==null?void 0:t.kind)||"manual",required:(t==null?void 0:t.required)!==!1,document_requirements:(t==null?void 0:t.document_requirements)||[],video_url:(t==null?void 0:t.video_url)||"",estimated_duration_minutes:(t==null?void 0:t.estimated_duration_minutes)||null,meeting_type:(t==null?void 0:t.meeting_type)||"",form_definition_id:(t==null?void 0:t.form_definition_id)||"",gate_logic:(t==null?void 0:t.gate_logic)||"",scoring_weight:(t==null?void 0:t.scoring_weight)||null,automations:(t==null?void 0:t.automations)||[],cta_actions:(t==null?void 0:t.cta_actions)||[]})),o=(s,i)=>g(a=>({...a,[s]:i})),h=()=>o("document_requirements",[...r.document_requirements,{document_type:"",description:"",required:!0}]),C=(s,i,a)=>o("document_requirements",r.document_requirements.map((L,q)=>q===s?{...L,[i]:a}:L)),D=s=>o("document_requirements",r.document_requirements.filter((i,a)=>a!==s)),j=s=>{const i=r.automations.includes(s.id);o("automations",i?r.automations.filter(a=>a!==s.id):[...r.automations,s.id])},A=s=>{const i=r.cta_actions.includes(s.id);o("cta_actions",i?r.cta_actions.filter(a=>a!==s.id):[...r.cta_actions,s.id])},R=()=>{r.title.trim()&&l(r,c)},k=Ne(r.kind),T=r.kind==="document_collection",m=r.kind==="video_watching",f=r.kind==="meeting",_=r.kind==="form_submission";return e.jsx("div",{className:"fixed inset-0 z-[60] flex items-center justify-center bg-black/30 p-4",onClick:b,children:e.jsxs("div",{className:"flex max-h-[90vh] w-full max-w-2xl flex-col overflow-hidden rounded-2xl bg-card shadow-2xl",onClick:s=>s.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-gray-100 px-5 py-3.5",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:`flex h-9 w-9 items-center justify-center rounded-xl ${k.bg} ${k.color}`,children:e.jsx(k.icon,{className:"h-4 w-4"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-sm font-semibold text-foreground",children:t?"Editar etapa":"Nova etapa"}
2),e.jsx("p",{className:"text-[10px] text-muted-foreground/70",children:"Configure o conteúdo, automações e CTAs"})]})]}),e.jsx("button",{type:"button",onClick:b,className:"flex h-8 w-8 items-center justify-center rounded-lg text-muted-foreground/70 hover:bg-muted",children:e.jsx(be,{className:"h-4 w-4"})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto px-5 py-4",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-xs font-medium text-foreground/70",children:"TÃtulo"}),e.jsx(I,{value:r.title,onChange:s=>o("title",s.target.value),placeholder:"Ex: Coleta de documentos pessoais"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-xs font-medium text-foreground/70",children:"Tipo de etapa"}),e.jsx("select",{value:r.kind,onChange:s=>o("kind",s.target.value),className:"h-9 w-full rounded-lg border border-border bg-card px-3 text-sm outline-none focus:ring-2 focus:border-primary/20",children:Q.map(s=>e.jsx("option",{value:s.id,children:s.label},s.id))})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-xs font-medium text-foreground/70",children:"Descrição"}),e.jsx("textarea",{value:r.description,onChange:s=>o("description",s.target.value),rows:2,placeholder:"O que acontece nesta etapa?",className:"w-full rounded-lg border border-border bg-card p-2.5 text-sm outline-none focus:ring-2 focus:border-primary/20"})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("label",{className:"flex items-center gap-2 text-xs font-medium text-foreground/70",children:[e.jsx("input",{type:"checkbox",checked:r.required,onChange:s=>o("required",s.target.checked),className:"h-4 w-4 rounded border-border text-primary focus:border-primary"}),"Etapa obrigatória"]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("label",{className:"text-xs font-medium text-foreground/70",children:"Duração (min):"}),e.jsx(I,{type:"number",value:r.estimated_duration_minutes||"",onChange:s=>o("estimated_duration_minutes",s.target.value?Number(s.target.value):null),className:"h-8 w-20",placeholder:"â"})]})]}),T&&e.jsxs("div",{className:"rounded-xl border border-blue-100 bg-blue-50/50 p-3",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[e.jsx("label",{className:"text-xs font-semibold text-blue-700",children:"Documentos exigidos"}),e.jsxs("button",{type:"button",onClick:h,className:"flex items-center gap-1 text-[10px] font-medium text-blue-600 hover:text-blue-800",children:[e.jsx(ae,{className:"h-3 w-3"})," Adicionar"]})]}),e.jsxs("div",{className:"space-y-2",children:[r.document_requirements.map((s,i)=>e.jsxs("div",{className:"flex items-center gap-2 rounded-lg bg-card p-2",children:[e.jsx(I,{value:s.document_type,onChange:a=>C(i,"document_type",a.target.value),placeholder:"Tipo (RG, comprovante...)",className:"h-8 flex-1"}),e.jsx(I,{value:s.description,onChange:a=>C(i,"description",a.target.value),placeholder:"Descrição",className:"h-8 flex-1"}),e.jsx("button",{type:"button",onClick:()=>D(i),className:"flex h-7 w-7 items-center justify-center rounded text-rose-500 hover:bg-rose-50",children:e.jsx(se,{className:"h-3.5 w-3.5"})})]},i)),!r.document_requirements.length&&e.jsx("p",{className:"text-[10px] text-muted-foreground/70",children:"Nenhum documento exigido."})]})]}),m&&e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-xs font-medium text-foreground/70",children:"URL do vÃdeo"}),e.jsx(I,{value:r.video_url,onChange:s=>o("video_url",s.target.value),placeholder:"https://youtube.com/watch?v=..."})]}),f&&e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-xs font-medium text-foreground/70",children:"Tipo de reunião"}),e.jsxs("select",{value:r.meeting_type,onChange:s=>o("meeting_type",s.target.value),className:"h-9 w-full rounded-lg border border-border bg-card px-3 text-sm outline-none focus:ring-2 focus:border-primary/20",children:[e.jsx("option",{value:"",children:"Selecione"}),e.jsx("option",{value:"cejusc",children:"CEJUSC"}),e.jsx("option",{value:"consulta",children:"Consulta"}),e.jsx("option",{value:"reuniao",children:"Reunião"}),e.jsx("option",{value:"audiencia",children:"Audiência"})]})]}),_&&e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-xs font-medium text-foreground
2/70",children:"Formulário vinculado"}),S?e.jsx("p",{className:"text-[10px] text-muted-foreground/70",children:"Carregando formuláriosâ¦"}):y.length===0?e.jsx("p",{className:"text-[10px] text-muted-foreground/70",children:"Nenhum formulário disponÃvel. Crie formulários no módulo Formulários."}):e.jsxs("select",{value:r.form_definition_id,onChange:s=>o("form_definition_id",s.target.value),className:"h-9 w-full rounded-lg border border-border bg-card px-3 text-sm outline-none focus:ring-2 focus:border-primary/20",children:[e.jsx("option",{value:"",children:"Selecione um formulário"}),y.map(s=>e.jsxs("option",{value:s.id,children:[s.name," · ",s.status==="published"?"publicado":"rascunho"]},s.id))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-xs font-medium text-foreground/70",children:"Lógica de gate (condição para avançar)"}),e.jsx(I,{value:r.gate_logic,onChange:s=>o("gate_logic",s.target.value),placeholder:'Ex: {"depends_on":"step-1","operator":"completed"}'})]}),e.jsxs("div",{className:"rounded-xl border border-indigo-100 bg-indigo-50/40 p-3",children:[e.jsx("label",{className:"mb-2 block text-xs font-semibold text-indigo-700",children:"Automações (gatilhos integrados ao portal)"}),e.jsx("div",{className:"grid gap-1.5 sm:grid-cols-2",children:nt.map(s=>{const i=r.automations.includes(s.id);return e.jsxs("button",{type:"button",onClick:()=>j(s),className:`rounded-lg border p-2 text-left text-xs transition-colors ${i?"border-indigo-300 bg-indigo-100":"border-border bg-card hover:border-indigo-200"}`,children:[e.jsx("span",{className:"font-medium text-foreground/80",children:s.label}),e.jsx("span",{className:"mt-0.5 block text-[10px] text-muted-foreground/70",children:s.description})]},s.id)})})]}),e.jsxs("div",{className:"rounded-xl border border-emerald-100 bg-emerald-50/40 p-3",children:[e.jsx("label",{className:"mb-2 block text-xs font-semibold text-emerald-700",children:"CTAs (ações do cliente no portal)"}),e.jsx("div",{className:"grid gap-1.5 sm:grid-cols-2",children:it.map(s=>{const i=r.cta_actions.includes(s.id);return e.jsxs("button",{type:"button",onClick:()=>A(s),className:`rounded-lg border p-2 text-left text-xs transition-colors ${i?"border-emerald-300 bg-emerald-100":"border-border bg-card hover:border-emerald-200"}`,children:[e.jsx("span",{className:"font-medium text-foreground/80",children:s.label}),e.jsx("span",{className:"mt-0.5 block text-[10px] text-muted-foreground/70",children:s.description})]},s.id)})})]})]})}),e.jsxs("div",{className:"flex items-center justify-end gap-2 border-t border-gray-100 px-5 py-3",children:[e.jsx("button",{type:"button",onClick:b,className:"h-9 rounded-lg border border-border px-4 text-xs font-medium text-foreground/70 hover:bg-muted",children:"Cancelar"}),e.jsx("button",{type:"button",onClick:R,disabled:!r.title.trim(),className:"h-9 rounded-lg bg-primary px-4 text-xs font-medium text-white disabled:opacity-40 hover:bg-primary",children:"Salvar etapa"})]})]})})}const dt=["Onboarding de superendividamento: coleta de documentos, análise financeira, audiência no CEJUSC e acompanhamento","Consultoria inicial: triagem, diagnóstico jurÃdico, proposta de honorários e contratação","Renegociação de dÃvidas: levantamento de credores, proposta de pagamento, homologação judicial","Defesa do consumidor: análise do caso, coleta de provas, proposta de acordo ou judicial"];function ct({purpose:t,kind:c,produtoTitulo:l,existingSteps:b,onApply:y,onClose:S}){const[r,g]=w.useState(""),[o,h]=w.useState(!1),[C,D]=w.useState(""),[j,A]=w.useState(null),R=async()=>{var m;if(!(!r.trim()||o)){h(!0),D(""),A(null);try{const{base44:f}=await Se(async()=>{const{base44:s}=await import("./index-zO3nSPIa.js").then(i=>i.kK);return{base44:s}},__vite__mapDeps([0,1,2])),_=await f.functions.invoke("generateJourneySteps",{prompt:r.trim(),purpose:t,kind:c||"outro",produto_titulo:l||null,existing_steps:b||[]});(m=_==null?void 0:_.steps)!=null&&m.length?A(_):D("A IA não retornou etapas. Tente reformular o prompt.")}catch(f){D((f==null?void 0:f.message)||"Não foi possÃvel gerar as etapas.")}finally{h(!1)}}},k=()=>{j!=null&&j.steps&&y(j.steps)},T=()=>{j!=null&&j.steps&&y(j.steps,!0)};return e.jsxs("div",{className:"rounded-xl border border-violet-200 bg-gradient-to-br from-violet-50/60 to-white p-4",children:[e.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[e.jsx("div",{className:"flex h-9 w-9 items-center justify-center rounded-xl bg-violet-100 text-violet-600",children:e.jsx(ge,{className:"h-4 w-4"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-foreground",children:"Assistente de IA"}
2),e.jsx("p",{className:"text-[10px] text-muted-foreground/70",children:"Descreva o fluxo e a IA gera as etapas estruturadas"})]}),S&&e.jsx("button",{type:"button",onClick:S,className:"ml-auto flex h-7 w-7 items-center justify-center rounded-lg text-muted-foreground/70 hover:bg-muted",children:e.jsx(be,{className:"h-4 w-4"})})]}),e.jsx("textarea",{value:r,onChange:m=>g(m.target.value),rows:3,placeholder:"Ex: Onboarding de superendividamento com coleta de documentos, análise financeira e audiência no CEJUSC...",className:"w-full rounded-lg border border-violet-200 bg-card p-2.5 text-sm outline-none focus:ring-2 focus:ring-violet-300/30",disabled:o}),e.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:dt.map((m,f)=>e.jsxs("button",{type:"button",onClick:()=>g(m),disabled:o,className:"rounded-full border border-violet-200 bg-violet-50/50 px-2.5 py-1 text-[10px] text-violet-600 hover:bg-violet-100 disabled:opacity-40",children:[m.slice(0,40),"â¦"]},f))}),e.jsx("div",{className:"mt-3 flex items-center gap-2",children:e.jsxs("button",{type:"button",onClick:R,disabled:!r.trim()||o,className:"inline-flex h-9 items-center gap-1.5 rounded-lg bg-violet-600 px-4 text-xs font-medium text-white disabled:opacity-40 hover:bg-violet-700",children:[o?e.jsx(K,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Re,{className:"h-3.5 w-3.5"}),o?"Gerandoâ¦":"Gerar etapas"]})}),C&&e.jsx("div",{className:"mt-2 rounded-lg border border-rose-200 bg-rose-50 p-2.5 text-xs text-rose-700",children:C}),j&&e.jsxs("div",{className:"mt-3 space-y-2",children:[j.rationale&&e.jsxs("div",{className:"rounded-lg bg-violet-50/60 p-2.5 text-[11px] leading-relaxed text-violet-700",children:[e.jsx("strong",{children:"Justificativa:"})," ",j.rationale]}),e.jsx("div",{className:"space-y-1.5",children:j.steps.map((m,f)=>e.jsxs("div",{className:"flex items-center gap-2 rounded-lg border border-gray-100 bg-card p-2",children:[e.jsx("span",{className:"flex h-5 w-5 shrink-0 items-center justify-center rounded-full bg-violet-100 text-[10px] font-semibold text-violet-600",children:f+1}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-xs font-medium text-foreground/80",children:m.title}),e.jsxs("p",{className:"truncate text-[10px] text-muted-foreground/70",children:[m.kind," · ",m.description]})]}),e.jsx($e,{className:"ml-auto h-3.5 w-3.5 shrink-0 text-emerald-500"})]},m.id||f))}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:k,className:"flex-1 h-8 rounded-lg bg-violet-600 text-xs font-medium text-white hover:bg-violet-700",children:"Adicionar à s existentes"}),e.jsx("button",{type:"button",onClick:T,className:"flex-1 h-8 rounded-lg border border-violet-300 bg-card text-xs font-medium text-violet-600 hover:bg-violet-50",children:"Substituir todas"})]})]})]})}function ut({onAddStep:t}){return e.jsxs("div",{className:"lg:w-44 lg:shrink-0",children:[e.jsxs("div",{className:"mb-1.5 flex items-center gap-1.5",children:[e.jsx(Ie,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx("h3",{className:"text-xs font-semibold text-foreground/80",children:"Paleta de etapas"})]}),e.jsx("p",{className:"mb-2 text-[10px] text-muted-foreground/70",children:"Arraste para o fluxo ou clique"}),e.jsx(he,{droppableId:"palette",isDropDisabled:!0,children:c=>e.jsxs("div",{ref:c.innerRef,...c.droppableProps,className:"flex gap-2 overflow-x-auto pb-1 lg:flex-col lg:gap-1.5 lg:overflow-visible lg:pb-0",children:[Q.map((l,b)=>e.jsx(fe,{draggableId:`palette-${l.id}`,index:b,children:(y,S)=>e.jsx("div",{ref:y.innerRef,...y.draggableProps,...y.dragHandleProps,onClick:()=>t(l.id),role:"button",tabIndex:0,onKeyDown:r=>{(r.key==="Enter"||r.key===" ")&&(r.preventDefault(),t(l.id))},className:`shrink-0 cursor-grab rounded-xl border ${l.border} ${l.bg} p-2.5 transition-shadow hover:shadow-sm active:cursor-grabbing lg:w-full ${S.isDragging?"opacity-40":""}`,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:`flex h-8 w-8 shrink-0 items-center justify-center rounded-lg ${l.bg} ${l.color}`,children:e.jsx(l.icon,{className:"h-4 w-4"})}
2),e.jsx("span",{className:"text-xs font-medium text-foreground/80",children:l.label})]})})},l.id)),c.placeholder]})})]})}const mt={staff_training:"Capacitação",sales:"Comercial",staff_delivery:"Entrega interna",client:"Jornada do cliente"};function xt({templateId:t,onClose:c,inline:l=!1}){var ne,ie,le,de;const b=ve(),[y,S]=w.useState(""),[r,g]=w.useState(""),[o,h]=w.useState([]),[C,D]=w.useState(!1),[j,A]=w.useState(!1),[R,k]=w.useState(null),[T,m]=w.useState(null),[f,_]=w.useState(!1),{formsMap:s}=ye(),i=O({queryKey:["journey-edit",t],queryFn:()=>J.getJourney(t),enabled:!!t,staleTime:0,retry:!1});w.useEffect(()=>{i.data&&(S(i.data.title||""),g(i.data.description||""),h(Array.isArray(i.data.steps)?i.data.steps:[]),_(!1))},[i.data]);const a=B({mutationFn:()=>J.updateJourney(t,{title:y.trim(),description:r.trim()||null,steps:o}),onSuccess:async()=>{_(!1),await b.invalidateQueries({queryKey:["journey-edit",t]}),await b.invalidateQueries({queryKey:["product-journeys"]})}}),L=B({mutationFn:()=>J.publish(t),onSuccess:async()=>{await b.invalidateQueries({queryKey:["journey-edit",t]}),await b.invalidateQueries({queryKey:["product-journeys"]}),c()}}),q=()=>_(!0),F=()=>{k(null),m(null),A(!0)},V=x=>{const p={id:`step-${Date.now().toString(36)}`,kind:x,title:"",description:"",order:o.length+1,required:!0,document_requirements:[],automations:[],cta_actions:[]};h(u=>[...u,p]),k(p),m(o.length),A(!0),q()},G=(x,p)=>{k(x),m(p),A(!0)},H=(x,p)=>{p==null?h(u=>[...u,{...x,order:u.length+1}]):h(u=>u.map((N,v)=>v===p?x:N)),A(!1),k(null),m(null),q()},U=(x,p)=>{const u={...x,id:`step-${Date.now().toString(36)}`,title:`${x.title} (cópia)`,order:p+2};h(N=>
2[...N.slice(0,p+1),u,...N.slice(p+1)].map((v,M)=>({...v,order:M+1}))),q()},z=(x,p)=>{h(u=>u.filter((N,v)=>v!==p).map((N,v)=>({...N,order:v+1}))),q()},W=x=>{const{source:p,destination:u,draggableId:N}=x;if(u){if(p.droppableId==="palette"&&u.droppableId==="canvas"){const v=N.replace("palette-",""),M={id:`step-${Date.now().toString(36)}`,kind:v,title:"",description:"",required:!0,document_requirements:[],automations:[],cta_actions:[]};h(ee=>{const Y=[...ee];return Y.splice(u.index,0,M),Y.map((_e,Ce)=>({..._e,order:Ce+1}))}),k(M),m(u.index),A(!0),q()}else if(p.droppableId==="canvas"&&u.droppableId==="canvas"){if(p.index===u.index)return;const v=Array.from(o),[M]=v.splice(p.index,1);v.splice(u.index,0,M),h(v.map((ee,Y)=>({...ee,order:Y+1}))),q()}}},n=(x,p)=>{h(p?x.map((u,N)=>({...u,order:N+1})):u=>[...u,...x].map((N,v)=>({...N,order:v+1}))),D(!1),q()},$=()=>a.mutate(),P=()=>{f?a.mutateAsync().then(()=>L.mutate()):L.mutate()},d=i.data,X=i.isLoading,Z=i.isError,E=(d==null?void 0:d.status)||"draft",we=mt[d==null?void 0:d.purpose]||(d==null?void 0:d.purpose)||"",re=e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("div",{className:"text-[10px] text-muted-foreground/70",children:f?"Alterações não salvas":o.length>0?`${o.length} etapa(s)`:"Nenhuma etapa"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{type:"button",onClick:$,disabled:!f||a.isPending,className:"inline-flex h-9 items-center gap-1.5 rounded-lg border border-border px-3 text-xs font-medium text-foreground/70 disabled:opacity-40 hover:bg-muted",children:[a.isPending?e.jsx(K,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Ke,{className:"h-3.5 w-3.5"}),"Salvar rascunho"]}),e.jsxs("button",{type:"button",onClick:P,disabled:!o.length||L.isPending||a.isPending,className:"inline-flex h-9 items-center gap-1.5 rounded-lg bg-primary px-4 text-xs font-medium text-white disabled:opacity-40 hover:bg-primary",children:[L.isPending?e.jsx(K,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(je,{className:"h-3.5 w-3.5"}),"Publicar"]})]})]}),oe=e.jsxs(e.Fragment,{children:[X?e.jsx("div",{className:"flex items-center justify-center py-16",children:e.jsx(K,{className:"h-6 w-6 animate-spin text-primary"})}):Z?e.jsxs("div",{className:"flex flex-col items-center gap-2 rounded-xl border border-rose-200 bg-rose-50 p-6 text-center",children:[e.jsx(Me,{className:"h-6 w-6 text-rose-500"}),e.jsx("p",{className:"text-xs text-rose-700",children:"Não foi possÃvel carregar a jornada."})]}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-xs font-medium text-foreground/70",children:"TÃtulo da jornada"}),e.jsx(I,{value:y,onChange:x=>{S(x.target.value),q()},placeholder:"Nome da jornada"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-xs font-medium text-foreground/70",children:"Descrição"}),e.jsx("textarea",{value:r,onChange:x=>{g(x.target.value),q()},rows:2,placeholder:"Objetivo e escopo da jornada",className:"w-full rounded-lg border border-border bg-card p-2.5 text-sm outline-none focus:ring-2 focus:border-primary/20"})]})]}),e.jsxs("button",{type:"button",onClick:()=>D(!C),className:"flex w-full items-center justify-between rounded-xl border border-violet-200 bg-violet-50/40 px-3 py-2.5 text-left transition-colors hover:bg-violet-50",children:[e.jsxs("span",{className:"flex items-center gap-2 text-xs font-medium text-violet-700",children:[e.jsx(ge,{className:"h-4 w-4"}),"Assistente de IA â gerar etapas"]}),C?e.jsx(Oe,{className:"h-4 w-4 text-violet-400"}):e.jsx(Be,{className:"h-4 w-4 text-violet-400"})]}),C&&e.jsx(ct,{purpose:d==null?void 0:d.purpose,kind:(ne=d==null?void 0:d._template)==null?void 0:ne.kind,produtoTitulo:(ie=d==null?void 0:d._template)==null?void 0:ie.produto_id,existingSteps:o,onApply:n,onClose:()=>D(!1)}),e.jsxs(Qe,{onDragEnd:W,children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[e.jsxs("h3",{className:"flex items-center gap-1.5 text-xs font-semibold text-foreground
2/80",children:[e.jsx(pe,{className:"h-3.5 w-3.5"}),"Fluxo de etapas"]}),e.jsxs("button",{type:"button",onClick:F,className:"inline-flex h-7 items-center gap-1 rounded-lg bg-muted px-2.5 text-[10px] font-medium text-foreground/70 hover:bg-muted",children:[e.jsx(ae,{className:"h-3 w-3"})," Nova etapa"]})]}),e.jsxs("div",{className:"flex flex-col gap-3 lg:flex-row",children:[e.jsx(ut,{onAddStep:V}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx(he,{droppableId:"canvas",children:(x,p)=>e.jsxs("div",{ref:x.innerRef,...x.droppableProps,className:`min-h-[120px] rounded-xl transition-colors ${o.length===0?`border border-dashed p-8 text-center ${p.isDraggingOver?"border-primary bg-[#FFF7F2]":"border-border bg-muted/50"}`:"space-y-0"}`,children:[o.length===0?e.jsxs(e.Fragment,{children:[e.jsx(pe,{className:"mx-auto h-6 w-6 text-muted-foreground/60"}),e.jsx("p",{className:"mt-2 text-xs text-muted-foreground/70",children:"Arraste um tipo de etapa da paleta ou use a IA."})]}):e.jsx(e.Fragment,{children:o.map((u,N)=>e.jsx(fe,{draggableId:String(u.id||N),index:N,children:v=>e.jsx("div",{ref:v.innerRef,...v.draggableProps,children:e.jsx(ot,{step:u,index:N,total:o.length,onEdit:G,onDuplicate:U,onDelete:z,dragHandleProps:v.dragHandleProps,formsMap:s})})},u.id||N))}),x.placeholder]})}),o.length>0&&e.jsxs("button",{type:"button",onClick:F,className:"mt-2 flex w-full items-center justify-center gap-1.5 rounded-xl border border-dashed border-border py-2.5 text-xs text-muted-foreground/70 hover:border-primary hover:text-primary",children:[e.jsx(ae,{className:"h-3.5 w-3.5"})," Adicionar etapa"]})]})]})]}),a.isError&&e.jsx("div",{className:"rounded-lg border border-rose-200 bg-rose-50 p-2.5 text-xs text-rose-700",children:((le=a.error)==null?void 0:le.message)||"Erro ao salvar."}),L.isError&&e.jsx("div",{className:"rounded-lg border border-rose-200 bg-rose-50 p-2.5 text-xs text-rose-700",children:((de=L.error)==null?void 0:de.message)||"Erro ao publicar."})]}),j&&e.jsx(lt,{step:R,index:T,onSave:H,onClose:()=>{A(!1),k(null),m(null)}})]});return l?e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex items-center justify-between gap-2 border-b border-border pb-3",children:re}),oe]}):e.jsx(Ve,{open:!!t,onClose:c,title:y||"Editar jornada",subtitle:`${we} · v${(d==null?void 0:d.version)||1} · ${E==="active"?"publicada":"rascunho"}`,maxWidth:"780px",footer:re,children:oe})}function pt({templateId:t,onClose:c}){return t?e.jsx(xt,{templateId:t,onClose:c,inline:!0}):e.jsx("p",{className:"py-8 text-center text-xs text-muted-foreground",children:"Selecione uma jornada"})}function kt(){var W;const{jornadaId:t}=Ge(),c=He(),{toast:l}=Ue(),b=ve(),[y,S]=w.useState(!1),[r,g]=w.useState(null),[o,h]=w.useState(null),{layout:C,isDirty:D,isSaving:j,updateLayout:A,saveLayout:R,resetLayout:k,availableFields:T}=Ze("jornada"),{cardLibrary:m}=Ye("jornada"),f=O({queryKey:["journey-detail",t],queryFn:()=>J.getJourney(t),enabled:!!t,staleTime:15e3,retry:!1}),_=O({queryKey:["journey-versions",t],queryFn:async()=>{const n=await ue.entities.JourneyTemplateVersion.filter({journey_template_id:t},"-version",50);return Array.isArray(n)?n:[]},enabled:!!t,staleTime:3e4,retry:!1}),s=O({queryKey:["journey-instances",t],queryFn:async()=>{const n=await ue.entities.JourneyInstance.filter({journey_template_id:t},"-updated_date",50);return Array.isArray(n)?n:[]},enabled:!!t,staleTime:3e4,retry:!1}),i=async()=>{await b.invalidateQueries({queryKey:["journey-detail",t]}),await b.invalidateQueries({queryKey:["journey-versions",t]}),await b.invalidateQueries({queryKey:["journey-instances",t]})},a=f.data||null,L=B({mutationFn:()=>J.createVersion(t),onSuccess:async()=>{await i(),l({title:"Nova versão criada"})},onError:n=>l({title:"Não foi possÃvel versionar",description:n==null?void 0:n.message,variant:"destructive"})}),q=B({mutationFn:()=>J.publish(t),onSuccess:async()=>{await i(),l({title:"Jornada publicada"})},onError:n=>l({title:"Publicação bloqueada",description:n==null?void 0:n.message,variant:"destructive"})}),F=B({mutationFn:()=>J.deleteJourney(t),onSuccess:async()=>
2{l({title:"Jornada excluÃda"}),c("/jornadas")},onError:n=>l({title:"Não foi possÃvel excluir",description:n==null?void 0:n.message,variant:"destructive"})}),V=async(n,$)=>{var P;(P=a==null?void 0:a._template)!=null&&P.id&&(await J.updateJourney(a._template.id,{[n]:$}),i(),l({title:"Propriedade atualizada"}))},G=n=>{var $,P,d,X,Z;return n==="overview"?e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{className:"rounded-xl border border-border bg-card p-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(te,{className:"h-4 w-4 text-primary"}),e.jsx("h3",{className:"text-sm font-semibold text-foreground",children:(a==null?void 0:a.title)||"Jornada"})]}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:(a==null?void 0:a.description)||"Sem descrição."}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2 text-[10px] text-muted-foreground",children:[e.jsxs("span",{className:"rounded-md bg-muted px-2 py-1",children:["v",(a==null?void 0:a.version)||1]}),e.jsxs("span",{className:"rounded-md bg-muted px-2 py-1",children:[(($=a==null?void 0:a.steps)==null?void 0:$.length)||0," etapa(s)"]}),e.jsxs("span",{className:"rounded-md bg-muted px-2 py-1",children:[((P=_.data)==null?void 0:P.length)||0," versão(ões)"]}),e.jsxs("span",{className:"rounded-md bg-muted px-2 py-1",children:[((d=s.data)==null?void 0:d.length)||0," instância(s)"]})]})]})}):n==="etapas"?e.jsx(pt,{templateId:t,onClose:()=>{}}):n==="versoes"?e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-semibold text-foreground",children:"Versões"}),_.isLoading?e.jsx(K,{className:"h-5 w-5 animate-spin text-primary"}):(X=_.data)!=null&&X.length?e.jsx("div",{className:"space-y-2",children:_.data.map(E=>e.jsxs("div",{className:"flex items-center justify-between rounded-lg border border-border p-3",children:[e.jsxs("div",{children:[e.jsxs("span",{className:"font-mono text-[10px] text-muted-foreground",children:["v",E.version]}),e.jsx("span",{className:`ml-2 rounded-md px-2 py-0.5 text-[9px] ${E.status==="published"?"bg-emerald-50 text-emerald-700":"bg-muted text-muted-foreground"}`,children:E.status})]}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:E.published_at?new Date(E.published_at).toLocaleString("pt-BR"):"â"})]},E.id))}):e.jsx("p",{className:"rounded-lg bg-muted p-3 text-xs text-muted-foreground",children:"Nenhuma versão."})]}):n==="instancias"?e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-semibold text-foreground",children:"Instâncias ativas"}),s.isLoading?e.jsx(K,{className:"h-5 w-5 animate-spin text-primary"}):(Z=s.data)!=null&&Z.length?e.jsx("div",{className:"space-y-2",children:s.data.map(E=>e.jsxs("div",{className:"flex items-center justify-between rounded-lg border border-border p-3",children:[e.jsxs("div",{children:[e.jsx("span",{className:"font-mono text-[10px] text-muted-foreground",children:E.id}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:E.status||"â"})]}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:E.updated_date?new Date(E.updated_date).toLocaleString("pt-BR"):"â"})]},E.id))}):e.jsx("p",{className:"rounded-lg bg-muted p-3 text-xs text-muted-foreground",children:"Nenhuma instância ativa."})]}):null},H=n=>{var P;switch((P=n.association_config)==null?void 0:P.entity){case"versoes":return{items:(_.data||[]).slice(0,5).map(d=>({id:d.id,label:`v${d.version}`,sublabel:d.status})),emptyHint:"Nenhuma versão"};case"instancias":return{items:(s.data||[]).slice(0,5).map(d=>({id:d.id,label:d.id,sublabel:d.status||""})),emptyHint:"Nenhuma instância"};default:return{items:[],emptyHint:"Nenhum registro"}}},U=e.jsx(tt,{breadcrumb:{label:"Jornadas",href:"/jornadas"},title:(a==null?void 0:a.title)||"Jornada",icon:te,metadata:[{label:"Tipo",value:a==null?void 0:a.kind},{label:"Finalidade",value:a==null?void 0:a.purpose},{label:"Status",value:a==null?void 0:a.status},{label:"Versão",value:a==null?void 0:a.version}],onComposer:g,onEditLayout:()=>S(!0),moreActions:[{icon:ze,label:"Nova versão",onClick:()=>L.mutate()},{icon:je,label:"Publicar",onClick:()=>q.mutate(),locked:(a==null?void 0:a.status)!=="draft"},{icon:se,label:"Excluir",onClick:()=>h(a)}],actionsMenu:at});if(f.isLoading)return e.jsx("div",{className:"flex min-h-[60vh] items-center justify-center",children:e.jsx(K,{className:"h-8 w-8 animate-spin text-primary"})});if(f.isError||!a)return e.jsxs("div",{className:"flex min-h-[60vh] flex-col items-center justify-center gap-3 text-center",children:[e.jsx(te,{className:"h-12 w-12 text-muted-foreground"}),e.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:"Jornada não encontrada"}),e.jsx(We,{to:"/jornadas",className:"rounded-lg border border-border bg-card px-4 py-2 text-sm font-medium text-muted-foreground",children:"Voltar para Jornadas"})]});const z={...a,...a._template};return y?e.jsxs(e.Fragment,{children:[e.jsx(et,{layout:C,record:z,availableFields:T||ce,onLayoutChange:A,onSave:R,onExit:()=>{D&&k(),S(!1)},isSaving:j,cardLibrary:m,renderCenterTab:G,renderAssociation:H,onPropertySave:V,headerExtra:U,moduleLabel:"Jornada página do registro"}),e.jsx(me,{open:r==="note",onClose:()=>g(null),recordLabel:(a==null?void 0:a.title)||"Jornada",onSubmit:()=>{l({title:"Observação criada"}),g(null)}}),e.jsx(xe,{open:r==="task",onClose:()=>g(null),recordLabel:(a==null?void 0:a.title)||"Jornada",onSubmit:n=>{l({title:"Tarefa criada",description:n.title}),g(null)}})]}):e.jsxs(e.Fragment,{children:[e.jsx(Xe,{layout:C,record:z,availableFields:T||ce,editMode:!1,cardLibrary:m,renderCenterTab:G,renderAssociation:H,onPropertySave:V,headerExtra:U}),e.jsx(me,{open:r==="note",onClose:()=>g(null),recordLabel:(a==null?void 0:a.title)||"Jornada",onSubmit:()=>{l({title:"Observação criada"}),g(null)}}),e.jsx(xe,{open:r==="task",onClose:()=>g(null),recordLabel:(a==null?void 0:a.title)||"Jornada",onSubmit:n=>{l({title:"Tarefa criada",description:n.title}),g(null)}}),o&&e.jsx("div",{className:"fixed inset-0 z-[60] flex items-center justify-center bg-black/30 p-4",onClick:()=>h(null),children:e.jsxs("div",{className:"w-full max-w-md rounded-2xl bg-card p-5 border border-border",onClick:n=>n.stopPropagation(),children:[e.jsx("h3",{className:"text-sm font-semibold text-foreground",children:"Excluir jornada"}),e.jsxs("p",{className:"mt-2 text-xs text-muted-foreground",children:["Tem certeza que deseja excluir ",e.jsx("strong",{children:o.title}),"? Todas as versões serão removidas permanentemente."]}),F.isError&&e.jsx("div",{className:"mt-2 rounded-lg border border-destructive/30 bg-destructive/10 p-2 text-[10px] text-destructive",children:((W=F.error)==null?void 0:W.message)||"Erro ao excluir."}),e.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:()=>h(null),className:"h-9 rounded-lg border border-border px-4 text-xs font-medium text-muted-foreground hover:bg-muted",children:"Cancelar"}),e.jsx("button",{type:"button",onClick:()=>F.mutate(),disabled:F.isPending,className:"h-9 rounded-lg bg-destructive px-4 text-xs font-medium text-destructive-foreground disabled:opacity-40 hover:bg-destructive/90",children:F.isPending?"Excluindoâ¦":"Excluir"})]})]})})]})}export{kt as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.