@danhachuel/leadmaster 0.1.18 → 0.1.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +39 -0
- package/backend/__pycache__/main.cpython-311.pyc +0 -0
- package/backend/main.py +42 -2
- package/backend/services/__pycache__/__init__.cpython-311.pyc +0 -0
- package/backend/services/__pycache__/agents.cpython-311.pyc +0 -0
- package/backend/services/__pycache__/crm_agent.cpython-311.pyc +0 -0
- package/backend/services/__pycache__/extractors.cpython-311.pyc +0 -0
- package/backend/services/__pycache__/flags.cpython-311.pyc +0 -0
- package/backend/services/__pycache__/llm.cpython-311.pyc +0 -0
- package/backend/services/__pycache__/storage.cpython-311.pyc +0 -0
- package/backend/tests/__pycache__/conftest.cpython-311-pytest-8.4.2.pyc +0 -0
- package/backend/tests/__pycache__/test_campaigns_routes.cpython-311-pytest-8.4.2.pyc +0 -0
- package/backend/tests/__pycache__/test_cnpj_extractor.cpython-311-pytest-8.4.2.pyc +0 -0
- package/backend/tests/__pycache__/test_config.cpython-311-pytest-8.4.2.pyc +0 -0
- package/backend/tests/__pycache__/test_crm_routes.cpython-311-pytest-8.4.2.pyc +0 -0
- package/backend/tests/__pycache__/test_instagram_extractor.cpython-311-pytest-8.4.2.pyc +0 -0
- package/backend/tests/__pycache__/test_launcher_protections.cpython-311-pytest-8.4.2.pyc +0 -0
- package/backend/tests/__pycache__/test_maps_extractor.cpython-311-pytest-8.4.2.pyc +0 -0
- package/backend/tests/__pycache__/test_metrics.cpython-311-pytest-8.4.2.pyc +0 -0
- package/backend/tests/__pycache__/test_process_flags.cpython-311-pytest-8.4.2.pyc +0 -0
- package/backend/tests/test_config.py +90 -0
- package/frontend/dist/assets/{index-DFVTLg-7.js → index-CXuYUAoQ.js} +2 -2
- package/frontend/dist/assets/{index-BKo_OphM.css → index-ib1LXo9v.css} +1 -1
- package/frontend/dist/index.html +2 -2
- package/package.json +1 -1
|
@@ -64,7 +64,7 @@ Error generating stack: `+i.message+`
|
|
|
64
64
|
* LICENSE.md file in the root directory of this source tree.
|
|
65
65
|
*
|
|
66
66
|
* @license MIT
|
|
67
|
-
*/function Al(){return Al=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var s in n)({}).hasOwnProperty.call(n,s)&&(t[s]=n[s])}return t},Al.apply(null,arguments)}function py(t,e){if(t==null)return{};var n={};for(var s in t)if({}.hasOwnProperty.call(t,s)){if(e.indexOf(s)!==-1)continue;n[s]=t[s]}return n}function WS(t){return!!(t.metaKey||t.altKey||t.ctrlKey||t.shiftKey)}function HS(t,e){return t.button===0&&(!e||e==="_self")&&!WS(t)}function Rd(t){return t===void 0&&(t=""),new URLSearchParams(typeof t=="string"||Array.isArray(t)||t instanceof URLSearchParams?t:Object.keys(t).reduce((e,n)=>{let s=t[n];return e.concat(Array.isArray(s)?s.map(r=>[n,r]):[[n,s]])},[]))}function VS(t,e){let n=Rd(t);return e&&e.forEach((s,r)=>{n.has(r)||e.getAll(r).forEach(i=>{n.append(r,i)})}),n}const QS=["onClick","relative","reloadDocument","replace","state","target","to","preventScrollReset","viewTransition"],KS=["aria-current","caseSensitive","className","end","style","to","viewTransition","children"],YS="6";try{window.__reactRouterVersion=YS}catch{}const XS=S.createContext({isTransitioning:!1}),qS="startTransition",Qp=ib[qS];function GS(t){let{basename:e,children:n,future:s,window:r}=t,i=S.useRef();i.current==null&&(i.current=tS({window:r,v5Compat:!0}));let o=i.current,[a,l]=S.useState({action:o.action,location:o.location}),{v7_startTransition:c}=s||{},d=S.useCallback(f=>{c&&Qp?Qp(()=>l(f)):l(f)},[l,c]);return S.useLayoutEffect(()=>o.listen(d),[o,d]),S.useEffect(()=>BS(s),[s]),S.createElement($S,{basename:e,children:n,location:a.location,navigationType:a.action,navigator:o,future:s})}const JS=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",ZS=/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i,e_=S.forwardRef(function(e,n){let{onClick:s,relative:r,reloadDocument:i,replace:o,state:a,target:l,to:c,preventScrollReset:d,viewTransition:f}=e,h=py(e,QS),{basename:p}=S.useContext(Rs),m,g=!1;if(typeof c=="string"&&ZS.test(c)&&(m=c,JS))try{let v=new URL(window.location.href),_=c.startsWith("//")?new URL(v.protocol+c):new URL(c),w=pi(_.pathname,p);_.origin===v.origin&&w!=null?c=w+_.search+_.hash:g=!0}catch{}let b=CS(c,{relative:r}),y=n_(c,{replace:o,state:a,target:l,preventScrollReset:d,relative:r,viewTransition:f});function x(v){s&&s(v),v.defaultPrevented||y(v)}return S.createElement("a",Al({},h,{href:m||b,onClick:g||i?s:x,ref:n,target:l}))}),gy=S.forwardRef(function(e,n){let{"aria-current":s="page",caseSensitive:r=!1,className:i="",end:o=!1,style:a,to:l,viewTransition:c,children:d}=e,f=py(e,KS),h=vc(l,{relative:f.relative}),p=Os(),m=S.useContext(ly),{navigator:g,basename:b}=S.useContext(Rs),y=m!=null&&r_(h)&&c===!0,x=g.encodeLocation?g.encodeLocation(h).pathname:h.pathname,v=p.pathname,_=m&&m.navigation&&m.navigation.location?m.navigation.location.pathname:null;r||(v=v.toLowerCase(),_=_?_.toLowerCase():null,x=x.toLowerCase()),_&&b&&(_=pi(_,b)||_);const w=x!=="/"&&x.endsWith("/")?x.length-1:x.length;let k=v===x||!o&&v.startsWith(x)&&v.charAt(w)==="/",C=_!=null&&(_===x||!o&&_.startsWith(x)&&_.charAt(x.length)==="/"),j={isActive:k,isPending:C,isTransitioning:y},M=k?s:void 0,E;typeof i=="function"?E=i(j):E=[i,k?"active":null,C?"pending":null,y?"transitioning":null].filter(Boolean).join(" ");let P=typeof a=="function"?a(j):a;return S.createElement(e_,Al({},f,{"aria-current":M,className:E,ref:n,style:P,to:l,viewTransition:c}),typeof d=="function"?d(j):d)});var Od;(function(t){t.UseScrollRestoration="useScrollRestoration",t.UseSubmit="useSubmit",t.UseSubmitFetcher="useSubmitFetcher",t.UseFetcher="useFetcher",t.useViewTransitionState="useViewTransitionState"})(Od||(Od={}));var Kp;(function(t){t.UseFetcher="useFetcher",t.UseFetchers="useFetchers",t.UseScrollRestoration="useScrollRestoration"})(Kp||(Kp={}));function t_(t){let e=S.useContext(xc);return e||je(!1),e}function n_(t,e){let{target:n,replace:s,state:r,preventScrollReset:i,relative:o,viewTransition:a}=e===void 0?{}:e,l=bi(),c=Os(),d=vc(t,{relative:o});return S.useCallback(f=>{if(HS(f,n)){f.preventDefault();let h=s!==void 0?s:Ll(c)===Ll(d);l(t,{replace:h,state:r,preventScrollReset:i,relative:o,viewTransition:a})}},[c,l,d,s,r,n,t,i,o,a])}function s_(t){let e=S.useRef(Rd(t)),n=S.useRef(!1),s=Os(),r=S.useMemo(()=>VS(s.search,n.current?null:e.current),[s.search]),i=bi(),o=S.useCallback((a,l)=>{const c=Rd(typeof a=="function"?a(r):a);n.current=!0,i("?"+c,l)},[i,r]);return[r,o]}function r_(t,e){e===void 0&&(e={});let n=S.useContext(XS);n==null&&je(!1);let{basename:s}=t_(Od.useViewTransitionState),r=vc(t,{relative:e.relative});if(!n.isTransitioning)return!1;let i=pi(n.currentLocation.pathname,s)||n.currentLocation.pathname,o=pi(n.nextLocation.pathname,s)||n.nextLocation.pathname;return Md(r.pathname,o)!=null||Md(r.pathname,i)!=null}const i_="/api";class o_ extends Error{constructor(n,s){super(s);B(this,"status");this.status=n,this.name="ApiError"}}async function U(t,e={}){const n=await fetch(i_+t,{...e,headers:e.body?{"Content-Type":"application/json",...e.headers||{}}:e.headers});if(!n.ok){let s=`Erro HTTP ${n.status}`;try{const r=await n.json();s=String(r.detail||r.mensagem||s)}catch{}throw new o_(n.status,s)}if(n.status!==204)return n.json()}const Me=t=>({method:"POST",body:JSON.stringify(t)}),W={health:()=>U("/health"),doctor:()=>U("/doctor"),shutdown:()=>U("/shutdown",Me({})),metricas:()=>U("/metrics"),leads:{listar:()=>U("/leads"),criar:t=>U("/leads",Me(t)),atualizar:(t,e)=>U(`/leads/${t}`,{method:"PATCH",body:JSON.stringify(e)}),remover:t=>U(`/leads/${t}`,{method:"DELETE"}),importar:t=>U("/leads/import",Me({leads:t})),enriquecer:t=>U(`/leads/${t}/enrich`,Me({}))},crm:{leadsListar:()=>U("/crm/leads"),criarLead:t=>U("/crm/leads",Me(t)),moverLead:(t,e)=>U(`/crm/leads/${t}/etapa`,{method:"PUT",body:JSON.stringify({etapa:e})}),sugestoes:()=>U("/crm/sugestoes"),aplicar:(t,e)=>U("/crm/sugestoes/aplicar",Me({lead_id:t,para:e}))},campanhas:{listar:()=>U("/campaigns"),criar:t=>U("/campaigns",Me(t)),status:(t,e)=>U(`/campaigns/${t}/status`,{method:"PUT",body:JSON.stringify({status:e})}),iniciar:t=>U(`/campaigns/${t}/start`,Me({})),pausar:t=>U(`/campaigns/${t}/pause`,Me({})),parar:t=>U(`/campaigns/${t}/stop`,Me({})),remover:t=>U(`/campaigns/${t}`,{method:"DELETE"})},extrair:{maps:t=>U("/extractors/maps",Me(t)),instagram:(t,e)=>U("/extractors/instagram",Me({profile_url:t,limit:e})),cnpj:t=>U("/extract/cnpj",Me({cnpj:t})),cnpjBusca:t=>U("/extract/cnpj/search",Me(t)),cnpjExtract:t=>U("/extractors/cnpj",Me(t))},config:{obter:()=>U("/config"),salvar:t=>U("/config",{method:"PUT",body:JSON.stringify(t)}),testarLlm:()=>U("/config/test/llm",Me({})),testarIntegracao:t=>U("/config/test/integracao",Me({url:t}))},integracoes:()=>U("/integrations/status"),agentes:{templates:()=>U("/agents/templates"),salvarTemplates:t=>U("/agents/templates",{method:"PUT",body:JSON.stringify(t)}),testarTemplate:(t,e)=>U("/agents/templates/test",Me({template:t,lead_id:e})),chat:t=>U("/agents/attendance/chat",Me({mensagens:t}))},webhook:{obter:()=>U("/webhook"),salvar:t=>U("/webhook",{method:"PUT",body:JSON.stringify(t)}),testar:t=>U("/webhook/test",Me({url:t}))}};function H(...t){return t.filter(Boolean).join(" ")}function a_(t){return(t||"?").trim().charAt(0).toUpperCase()||"?"}function Il(t){if(!t)return"—";try{return new Date(t).toLocaleString("pt-BR",{day:"2-digit",month:"2-digit",year:"2-digit",hour:"2-digit",minute:"2-digit"})}catch{return t}}function na(t){const e=(t||"").replace(/\D/g,"");return e?e.length===11?`(${e.slice(0,2)}) ${e.slice(2,7)}-${e.slice(7)}`:e.length===10?`(${e.slice(0,2)}) ${e.slice(2,6)}-${e.slice(6)}`:t||"—":"—"}function l_(t){const e=["nome","telefone","email","empresa","cidade","observacoes"],n=e.filter(s=>String(t[s]||"").trim().length>0);return Math.round(n.length/e.length*100)}function c_(t){const e={nome:"nome",telefone:"telefone",email:"e-mail",empresa:"empresa",cidade:"cidade",observacoes:"observações"};return["nome","telefone","email","empresa","cidade","observacoes"].filter(s=>String(t[s]||"").trim().length===0).map(s=>e[s])}function u_(t,e){if(t>=100)return"Lead 100% completo — excelente! 🎉";const n=e.slice(0,2).join(" e ");return`Faltam ${100-t}% (${n}${e.length>2?"...":""}) para o lead ficar completo`}function d_(t,e){const n=new Blob([JSON.stringify(t,null,2)],{type:"application/json"}),s=URL.createObjectURL(n),r=document.createElement("a");r.href=s,r.download=e,r.click(),URL.revokeObjectURL(s)}const f_={md:"max-w-lg",lg:"max-w-2xl",xl:"max-w-4xl"};function Xt({aberto:t,onFechar:e,titulo:n,children:s,icone:r="fas fa-circle-info",largura:i="md"}){return S.useEffect(()=>{const o=a=>{a.key==="Escape"&&e()};return t&&window.addEventListener("keydown",o),()=>window.removeEventListener("keydown",o)},[t,e]),t?u.jsx("div",{className:"fixed inset-0 z-50 bg-black/40 flex items-center justify-center p-4",onMouseDown:o=>{o.target===o.currentTarget&&e()},children:u.jsxs("div",{className:H("bg-white rounded-2xl shadow-xl w-full",f_[i]),children:[u.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-gray-100",children:[u.jsxs("h3",{className:"text-base font-semibold text-gray-800 flex items-center gap-2",children:[u.jsx("i",{className:H(r,"text-indigo-500")})," ",n]}),u.jsx("button",{onClick:e,className:"text-gray-400 hover:text-gray-600","aria-label":"Fechar",children:u.jsx("i",{className:"fas fa-times"})})]}),u.jsx("div",{className:"px-6 py-5 max-h-[70vh] overflow-y-auto",children:s})]})}):null}const h_=[{icone:"fas fa-users",texto:"Cadastre leads manualmente ou importe pelos Extratores (Maps, Instagram, CNPJ)."},{icone:"fas fa-columns",texto:"Arraste os cards no CRM conforme avança no funil (Leads → Em contato → Proposta → Fechado)."},{icone:"fas fa-bullhorn",texto:"Monte campanhas de disparo com seus templates e acompanhe as taxas no Painel."},{icone:"fas fa-robot",texto:"Use os Agentes (disparo e atendimento) e configure o LLM em Ferramentas para turbiná-los."}];function p_({titulo:t,nomeUsuario:e}){const[n,s]=S.useState(!1);return u.jsxs("header",{className:"bg-white shadow-sm px-8 py-4 flex items-center justify-between shrink-0",children:[u.jsx("div",{children:u.jsx("h2",{className:"text-lg font-semibold text-gray-800",children:t})}),u.jsxs("div",{className:"flex items-center space-x-4",children:[u.jsxs("button",{onClick:()=>s(!0),className:"text-sm text-indigo-600 hover:text-indigo-800 font-medium",children:[u.jsx("i",{className:"fas fa-play-circle mr-1"})," Ver tutorial"]}),u.jsx("div",{className:"w-8 h-8 rounded-full bg-indigo-100 flex items-center justify-center text-indigo-600 font-bold text-sm",children:a_(e)}),u.jsx("span",{className:"text-sm font-medium text-gray-700",children:e})]}),u.jsxs(Xt,{aberto:n,onFechar:()=>s(!1),titulo:"Tutorial rápido",icone:"fas fa-graduation-cap",children:[u.jsx("ol",{className:"space-y-4",children:h_.map((r,i)=>u.jsxs("li",{className:"flex gap-3 items-start",children:[u.jsx("span",{className:"w-8 h-8 rounded-full bg-indigo-100 text-indigo-600 flex items-center justify-center shrink-0",children:u.jsx("i",{className:r.icone})}),u.jsx("p",{className:"text-sm text-gray-600 pt-1.5",children:r.texto})]},i))}),u.jsx("p",{className:"text-xs text-gray-400 mt-5",children:"Dica: o LLM (para enriquecimento e agentes) é configurado em Ferramentas."})]})]})}const g_=[{itens:[{para:"/",icone:"fas fa-chart-pie text-indigo-300",rotulo:"Painel",fim:!0}]},{secao:"Conexões",itens:[{para:"/leads",icone:"fas fa-users",rotulo:"Leads"},{para:"/agentes",icone:"fas fa-robot",rotulo:"Agentes"},{para:"/ferramentas",icone:"fas fa-tools",rotulo:"Ferramentas"}]},{itens:[{para:"/extrator-maps",icone:"fas fa-map-marked-alt",rotulo:"Extrator Maps"},{para:"/extrator-instagram",icone:"fab fa-instagram",rotulo:"Extrator Instagram"},{para:"/extrator-cnpj",icone:"fas fa-building",rotulo:"Extrator CNPJ"}]},{secao:"Gestão",itens:[{para:"/disparos",icone:"fas fa-bullhorn",rotulo:"Disparos"},{para:"/crm",icone:"fas fa-columns",rotulo:"CRM"}]},{secao:"Integrações",itens:[{para:"/webhook",icone:"fas fa-link",rotulo:"Webhook"},{para:"/suporte",icone:"fas fa-headset",rotulo:"Suporte"}]}];function m_({onSair:t}){const e=Os(),[n,s]=S.useState(!1);S.useEffect(()=>{e.pathname==="/agentes"&&s(!0)},[e.pathname]);const r=i=>{if(i.rotulo==="Agentes")return e.pathname==="/agentes";const[o,a]=i.para.split("?");return a?e.pathname===o&&e.search.includes(a):i.fim?e.pathname===o:e.pathname.startsWith(o)};return u.jsxs("aside",{className:"w-64 bg-[#1e1b4b] text-white flex flex-col shrink-0 h-screen sticky top-0",children:[u.jsx("div",{className:"p-6 border-b border-gray-700",children:u.jsxs("h1",{className:"text-2xl font-bold tracking-tight flex items-center gap-2",children:[u.jsx("span",{className:"text-2xl",children:"⚡"}),"LeadMaster",u.jsxs("span",{className:"text-[10px] font-medium text-indigo-300 border border-indigo-400/40 rounded-md px-1.5 py-0.5",children:["v","0.1.18"]})]})}),u.jsx("nav",{className:"flex-1 overflow-y-auto py-4",children:u.jsx("ul",{className:"space-y-1",children:g_.map((i,o)=>u.jsx("li",{children:u.jsxs("ul",{children:[i.secao&&u.jsx("li",{className:"px-6 py-2 text-xs font-semibold text-gray-400 uppercase tracking-wider list-none",children:i.secao}),i.itens.map(a=>a.rotulo==="Agentes"?u.jsxs("li",{children:[u.jsxs("button",{type:"button",onClick:()=>s(l=>!l),className:H("sidebar-link w-full flex items-center px-6 py-2.5 text-sm",r(a)&&"active"),children:[u.jsx("i",{className:H(a.icone,"w-5 text-gray-400")}),u.jsx("span",{className:"ml-3",children:a.rotulo}),u.jsx("i",{className:H("fas fa-chevron-down ml-auto text-xs text-gray-400 transition-transform",n&&"rotate-180")})]}),n&&u.jsxs("ul",{className:"pl-12 space-y-1 mt-1",children:[u.jsx("li",{children:u.jsx(Yp,{para:"/agentes?tab=disparo",rotulo:"Agente de Disparo",ativo:e.pathname==="/agentes"&&e.search.includes("disparo")})}),u.jsx("li",{children:u.jsx(Yp,{para:"/agentes?tab=atendimento",rotulo:"Agente de Atendimento",ativo:e.pathname==="/agentes"&&e.search.includes("atendimento")})})]})]},"agentes"):u.jsx("li",{children:u.jsxs(gy,{to:a.para,className:H("sidebar-link flex items-center px-6 py-2.5 text-sm",r(a)&&"active"),children:[u.jsx("i",{className:H(a.icone,"w-5 text-gray-400")}),u.jsx("span",{className:"ml-3",children:a.rotulo})]})},a.para))]})},o))})}),u.jsx("div",{className:"p-4 border-t border-gray-700",children:u.jsxs("button",{onClick:t,className:"w-full flex items-center justify-center px-4 py-2.5 bg-gradient-to-r from-indigo-500 to-purple-500 rounded-lg text-sm font-medium hover:opacity-90 transition",children:[u.jsx("i",{className:"fas fa-sign-out-alt mr-2"})," Sair"]})})]})}function Yp({para:t,rotulo:e,ativo:n}){return u.jsx(gy,{to:t,className:H("sidebar-link block px-4 py-2 text-xs text-gray-300 rounded",n&&"active"),children:e})}const my=S.createContext({toast:()=>{}});function en(){return S.useContext(my)}const x_={sucesso:"bg-green-600",erro:"bg-red-600",info:"bg-indigo-600"},y_={sucesso:"fas fa-check-circle",erro:"fas fa-exclamation-circle",info:"fas fa-info-circle"};function v_({children:t}){const[e,n]=S.useState([]),s=S.useRef(0),r=S.useCallback((i,o)=>{const a=++s.current;n(l=>[...l,{id:a,tipo:i,mensagem:o}]),setTimeout(()=>n(l=>l.filter(c=>c.id!==a)),4500)},[]);return u.jsxs(my.Provider,{value:{toast:r},children:[t,u.jsx("div",{className:"fixed top-4 right-4 z-[100] space-y-2 w-80",children:e.map(i=>u.jsxs("div",{className:H(x_[i.tipo],"text-white text-sm rounded-lg shadow-lg px-4 py-3 flex items-start gap-2 animate-pulse-once"),role:"status",children:[u.jsx("i",{className:H(y_[i.tipo],"mt-0.5")}),u.jsx("span",{className:"flex-1",children:i.mensagem}),u.jsx("button",{className:"opacity-70 hover:opacity-100",onClick:()=>n(o=>o.filter(a=>a.id!==i.id)),"aria-label":"Fechar",children:u.jsx("i",{className:"fas fa-times"})})]},i.id))})]})}function Pa({rotulo:t,valor:e,subtitulo:n,children:s,icone:r}){return u.jsxs("div",{className:"bg-white rounded-xl shadow-sm p-5 border border-gray-100",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx("p",{className:"text-sm text-gray-500 font-medium",children:t}),r&&u.jsx("i",{className:`${r} text-indigo-300`})]}),s??u.jsxs(u.Fragment,{children:[u.jsx("p",{className:"text-2xl font-bold text-gray-800 mt-1",children:e}),n&&u.jsx("p",{className:"text-xs text-gray-400 mt-0.5",children:n})]})]})}/*!
|
|
67
|
+
*/function Al(){return Al=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var s in n)({}).hasOwnProperty.call(n,s)&&(t[s]=n[s])}return t},Al.apply(null,arguments)}function py(t,e){if(t==null)return{};var n={};for(var s in t)if({}.hasOwnProperty.call(t,s)){if(e.indexOf(s)!==-1)continue;n[s]=t[s]}return n}function WS(t){return!!(t.metaKey||t.altKey||t.ctrlKey||t.shiftKey)}function HS(t,e){return t.button===0&&(!e||e==="_self")&&!WS(t)}function Rd(t){return t===void 0&&(t=""),new URLSearchParams(typeof t=="string"||Array.isArray(t)||t instanceof URLSearchParams?t:Object.keys(t).reduce((e,n)=>{let s=t[n];return e.concat(Array.isArray(s)?s.map(r=>[n,r]):[[n,s]])},[]))}function VS(t,e){let n=Rd(t);return e&&e.forEach((s,r)=>{n.has(r)||e.getAll(r).forEach(i=>{n.append(r,i)})}),n}const QS=["onClick","relative","reloadDocument","replace","state","target","to","preventScrollReset","viewTransition"],KS=["aria-current","caseSensitive","className","end","style","to","viewTransition","children"],YS="6";try{window.__reactRouterVersion=YS}catch{}const XS=S.createContext({isTransitioning:!1}),qS="startTransition",Qp=ib[qS];function GS(t){let{basename:e,children:n,future:s,window:r}=t,i=S.useRef();i.current==null&&(i.current=tS({window:r,v5Compat:!0}));let o=i.current,[a,l]=S.useState({action:o.action,location:o.location}),{v7_startTransition:c}=s||{},d=S.useCallback(f=>{c&&Qp?Qp(()=>l(f)):l(f)},[l,c]);return S.useLayoutEffect(()=>o.listen(d),[o,d]),S.useEffect(()=>BS(s),[s]),S.createElement($S,{basename:e,children:n,location:a.location,navigationType:a.action,navigator:o,future:s})}const JS=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",ZS=/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i,e_=S.forwardRef(function(e,n){let{onClick:s,relative:r,reloadDocument:i,replace:o,state:a,target:l,to:c,preventScrollReset:d,viewTransition:f}=e,h=py(e,QS),{basename:p}=S.useContext(Rs),m,g=!1;if(typeof c=="string"&&ZS.test(c)&&(m=c,JS))try{let v=new URL(window.location.href),_=c.startsWith("//")?new URL(v.protocol+c):new URL(c),w=pi(_.pathname,p);_.origin===v.origin&&w!=null?c=w+_.search+_.hash:g=!0}catch{}let b=CS(c,{relative:r}),y=n_(c,{replace:o,state:a,target:l,preventScrollReset:d,relative:r,viewTransition:f});function x(v){s&&s(v),v.defaultPrevented||y(v)}return S.createElement("a",Al({},h,{href:m||b,onClick:g||i?s:x,ref:n,target:l}))}),gy=S.forwardRef(function(e,n){let{"aria-current":s="page",caseSensitive:r=!1,className:i="",end:o=!1,style:a,to:l,viewTransition:c,children:d}=e,f=py(e,KS),h=vc(l,{relative:f.relative}),p=Os(),m=S.useContext(ly),{navigator:g,basename:b}=S.useContext(Rs),y=m!=null&&r_(h)&&c===!0,x=g.encodeLocation?g.encodeLocation(h).pathname:h.pathname,v=p.pathname,_=m&&m.navigation&&m.navigation.location?m.navigation.location.pathname:null;r||(v=v.toLowerCase(),_=_?_.toLowerCase():null,x=x.toLowerCase()),_&&b&&(_=pi(_,b)||_);const w=x!=="/"&&x.endsWith("/")?x.length-1:x.length;let k=v===x||!o&&v.startsWith(x)&&v.charAt(w)==="/",C=_!=null&&(_===x||!o&&_.startsWith(x)&&_.charAt(x.length)==="/"),j={isActive:k,isPending:C,isTransitioning:y},M=k?s:void 0,E;typeof i=="function"?E=i(j):E=[i,k?"active":null,C?"pending":null,y?"transitioning":null].filter(Boolean).join(" ");let P=typeof a=="function"?a(j):a;return S.createElement(e_,Al({},f,{"aria-current":M,className:E,ref:n,style:P,to:l,viewTransition:c}),typeof d=="function"?d(j):d)});var Od;(function(t){t.UseScrollRestoration="useScrollRestoration",t.UseSubmit="useSubmit",t.UseSubmitFetcher="useSubmitFetcher",t.UseFetcher="useFetcher",t.useViewTransitionState="useViewTransitionState"})(Od||(Od={}));var Kp;(function(t){t.UseFetcher="useFetcher",t.UseFetchers="useFetchers",t.UseScrollRestoration="useScrollRestoration"})(Kp||(Kp={}));function t_(t){let e=S.useContext(xc);return e||je(!1),e}function n_(t,e){let{target:n,replace:s,state:r,preventScrollReset:i,relative:o,viewTransition:a}=e===void 0?{}:e,l=bi(),c=Os(),d=vc(t,{relative:o});return S.useCallback(f=>{if(HS(f,n)){f.preventDefault();let h=s!==void 0?s:Ll(c)===Ll(d);l(t,{replace:h,state:r,preventScrollReset:i,relative:o,viewTransition:a})}},[c,l,d,s,r,n,t,i,o,a])}function s_(t){let e=S.useRef(Rd(t)),n=S.useRef(!1),s=Os(),r=S.useMemo(()=>VS(s.search,n.current?null:e.current),[s.search]),i=bi(),o=S.useCallback((a,l)=>{const c=Rd(typeof a=="function"?a(r):a);n.current=!0,i("?"+c,l)},[i,r]);return[r,o]}function r_(t,e){e===void 0&&(e={});let n=S.useContext(XS);n==null&&je(!1);let{basename:s}=t_(Od.useViewTransitionState),r=vc(t,{relative:e.relative});if(!n.isTransitioning)return!1;let i=pi(n.currentLocation.pathname,s)||n.currentLocation.pathname,o=pi(n.nextLocation.pathname,s)||n.nextLocation.pathname;return Md(r.pathname,o)!=null||Md(r.pathname,i)!=null}const i_="/api";class o_ extends Error{constructor(n,s){super(s);B(this,"status");this.status=n,this.name="ApiError"}}async function U(t,e={}){const n=await fetch(i_+t,{...e,headers:e.body?{"Content-Type":"application/json",...e.headers||{}}:e.headers});if(!n.ok){let s=`Erro HTTP ${n.status}`;try{const r=await n.json();s=String(r.detail||r.mensagem||s)}catch{}throw new o_(n.status,s)}if(n.status!==204)return n.json()}const Me=t=>({method:"POST",body:JSON.stringify(t)}),W={health:()=>U("/health"),doctor:()=>U("/doctor"),shutdown:()=>U("/shutdown",Me({})),metricas:()=>U("/metrics"),leads:{listar:()=>U("/leads"),criar:t=>U("/leads",Me(t)),atualizar:(t,e)=>U(`/leads/${t}`,{method:"PATCH",body:JSON.stringify(e)}),remover:t=>U(`/leads/${t}`,{method:"DELETE"}),importar:t=>U("/leads/import",Me({leads:t})),enriquecer:t=>U(`/leads/${t}/enrich`,Me({}))},crm:{leadsListar:()=>U("/crm/leads"),criarLead:t=>U("/crm/leads",Me(t)),moverLead:(t,e)=>U(`/crm/leads/${t}/etapa`,{method:"PUT",body:JSON.stringify({etapa:e})}),sugestoes:()=>U("/crm/sugestoes"),aplicar:(t,e)=>U("/crm/sugestoes/aplicar",Me({lead_id:t,para:e}))},campanhas:{listar:()=>U("/campaigns"),criar:t=>U("/campaigns",Me(t)),status:(t,e)=>U(`/campaigns/${t}/status`,{method:"PUT",body:JSON.stringify({status:e})}),iniciar:t=>U(`/campaigns/${t}/start`,Me({})),pausar:t=>U(`/campaigns/${t}/pause`,Me({})),parar:t=>U(`/campaigns/${t}/stop`,Me({})),remover:t=>U(`/campaigns/${t}`,{method:"DELETE"})},extrair:{maps:t=>U("/extractors/maps",Me(t)),instagram:(t,e)=>U("/extractors/instagram",Me({profile_url:t,limit:e})),cnpj:t=>U("/extract/cnpj",Me({cnpj:t})),cnpjBusca:t=>U("/extract/cnpj/search",Me(t)),cnpjExtract:t=>U("/extractors/cnpj",Me(t))},config:{obter:()=>U("/config"),salvar:t=>U("/config",{method:"PUT",body:JSON.stringify(t)}),testarLlm:()=>U("/config/test/llm",Me({})),testarIntegracao:t=>U("/config/test/integracao",Me({url:t}))},integracoes:()=>U("/integrations/status"),agentes:{templates:()=>U("/agents/templates"),salvarTemplates:t=>U("/agents/templates",{method:"PUT",body:JSON.stringify(t)}),testarTemplate:(t,e)=>U("/agents/templates/test",Me({template:t,lead_id:e})),chat:t=>U("/agents/attendance/chat",Me({mensagens:t}))},webhook:{obter:()=>U("/webhook"),salvar:t=>U("/webhook",{method:"PUT",body:JSON.stringify(t)}),testar:t=>U("/webhook/test",Me({url:t}))}};function H(...t){return t.filter(Boolean).join(" ")}function a_(t){return(t||"?").trim().charAt(0).toUpperCase()||"?"}function Il(t){if(!t)return"—";try{return new Date(t).toLocaleString("pt-BR",{day:"2-digit",month:"2-digit",year:"2-digit",hour:"2-digit",minute:"2-digit"})}catch{return t}}function na(t){const e=(t||"").replace(/\D/g,"");return e?e.length===11?`(${e.slice(0,2)}) ${e.slice(2,7)}-${e.slice(7)}`:e.length===10?`(${e.slice(0,2)}) ${e.slice(2,6)}-${e.slice(6)}`:t||"—":"—"}function l_(t){const e=["nome","telefone","email","empresa","cidade","observacoes"],n=e.filter(s=>String(t[s]||"").trim().length>0);return Math.round(n.length/e.length*100)}function c_(t){const e={nome:"nome",telefone:"telefone",email:"e-mail",empresa:"empresa",cidade:"cidade",observacoes:"observações"};return["nome","telefone","email","empresa","cidade","observacoes"].filter(s=>String(t[s]||"").trim().length===0).map(s=>e[s])}function u_(t,e){if(t>=100)return"Lead 100% completo — excelente! 🎉";const n=e.slice(0,2).join(" e ");return`Faltam ${100-t}% (${n}${e.length>2?"...":""}) para o lead ficar completo`}function d_(t,e){const n=new Blob([JSON.stringify(t,null,2)],{type:"application/json"}),s=URL.createObjectURL(n),r=document.createElement("a");r.href=s,r.download=e,r.click(),URL.revokeObjectURL(s)}const f_={md:"max-w-lg",lg:"max-w-2xl",xl:"max-w-4xl"};function Xt({aberto:t,onFechar:e,titulo:n,children:s,icone:r="fas fa-circle-info",largura:i="md"}){return S.useEffect(()=>{const o=a=>{a.key==="Escape"&&e()};return t&&window.addEventListener("keydown",o),()=>window.removeEventListener("keydown",o)},[t,e]),t?u.jsx("div",{className:"fixed inset-0 z-50 bg-black/40 flex items-center justify-center p-4",onMouseDown:o=>{o.target===o.currentTarget&&e()},children:u.jsxs("div",{className:H("bg-white rounded-2xl shadow-xl w-full",f_[i]),children:[u.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-gray-100",children:[u.jsxs("h3",{className:"text-base font-semibold text-gray-800 flex items-center gap-2",children:[u.jsx("i",{className:H(r,"text-indigo-500")})," ",n]}),u.jsx("button",{onClick:e,className:"text-gray-400 hover:text-gray-600","aria-label":"Fechar",children:u.jsx("i",{className:"fas fa-times"})})]}),u.jsx("div",{className:"px-6 py-5 max-h-[70vh] overflow-y-auto",children:s})]})}):null}const h_=[{icone:"fas fa-users",texto:"Cadastre leads manualmente ou importe pelos Extratores (Maps, Instagram, CNPJ)."},{icone:"fas fa-columns",texto:"Arraste os cards no CRM conforme avança no funil (Leads → Em contato → Proposta → Fechado)."},{icone:"fas fa-bullhorn",texto:"Monte campanhas de disparo com seus templates e acompanhe as taxas no Painel."},{icone:"fas fa-robot",texto:"Use os Agentes (disparo e atendimento) e configure o LLM em Ferramentas para turbiná-los."}];function p_({titulo:t,nomeUsuario:e}){const[n,s]=S.useState(!1);return u.jsxs("header",{className:"bg-white shadow-sm px-8 py-4 flex items-center justify-between shrink-0",children:[u.jsx("div",{children:u.jsx("h2",{className:"text-lg font-semibold text-gray-800",children:t})}),u.jsxs("div",{className:"flex items-center space-x-4",children:[u.jsxs("button",{onClick:()=>s(!0),className:"text-sm text-indigo-600 hover:text-indigo-800 font-medium",children:[u.jsx("i",{className:"fas fa-play-circle mr-1"})," Ver tutorial"]}),u.jsx("div",{className:"w-8 h-8 rounded-full bg-indigo-100 flex items-center justify-center text-indigo-600 font-bold text-sm",children:a_(e)}),u.jsx("span",{className:"text-sm font-medium text-gray-700",children:e})]}),u.jsxs(Xt,{aberto:n,onFechar:()=>s(!1),titulo:"Tutorial rápido",icone:"fas fa-graduation-cap",children:[u.jsx("ol",{className:"space-y-4",children:h_.map((r,i)=>u.jsxs("li",{className:"flex gap-3 items-start",children:[u.jsx("span",{className:"w-8 h-8 rounded-full bg-indigo-100 text-indigo-600 flex items-center justify-center shrink-0",children:u.jsx("i",{className:r.icone})}),u.jsx("p",{className:"text-sm text-gray-600 pt-1.5",children:r.texto})]},i))}),u.jsx("p",{className:"text-xs text-gray-400 mt-5",children:"Dica: o LLM (para enriquecimento e agentes) é configurado em Ferramentas."})]})]})}const g_=[{itens:[{para:"/",icone:"fas fa-chart-pie text-indigo-300",rotulo:"Painel",fim:!0}]},{secao:"Conexões",itens:[{para:"/leads",icone:"fas fa-users",rotulo:"Leads"},{para:"/agentes",icone:"fas fa-robot",rotulo:"Agentes"},{para:"/ferramentas",icone:"fas fa-tools",rotulo:"Ferramentas"}]},{itens:[{para:"/extrator-maps",icone:"fas fa-map-marked-alt",rotulo:"Extrator Maps"},{para:"/extrator-instagram",icone:"fab fa-instagram",rotulo:"Extrator Instagram"},{para:"/extrator-cnpj",icone:"fas fa-building",rotulo:"Extrator CNPJ"}]},{secao:"Gestão",itens:[{para:"/disparos",icone:"fas fa-bullhorn",rotulo:"Disparos"},{para:"/crm",icone:"fas fa-columns",rotulo:"CRM"}]},{secao:"Integrações",itens:[{para:"/webhook",icone:"fas fa-link",rotulo:"Webhook"},{para:"/suporte",icone:"fas fa-headset",rotulo:"Suporte"}]}];function m_({onSair:t}){const e=Os(),[n,s]=S.useState(!1);S.useEffect(()=>{e.pathname==="/agentes"&&s(!0)},[e.pathname]);const r=i=>{if(i.rotulo==="Agentes")return e.pathname==="/agentes";const[o,a]=i.para.split("?");return a?e.pathname===o&&e.search.includes(a):i.fim?e.pathname===o:e.pathname.startsWith(o)};return u.jsxs("aside",{className:"w-64 bg-[#1e1b4b] text-white flex flex-col shrink-0 h-screen sticky top-0",children:[u.jsx("div",{className:"p-6 border-b border-gray-700",children:u.jsxs("h1",{className:"text-2xl font-bold tracking-tight flex items-center gap-2",children:[u.jsx("span",{className:"text-2xl",children:"⚡"}),"LeadMaster",u.jsxs("span",{className:"text-[10px] font-medium text-indigo-300 border border-indigo-400/40 rounded-md px-1.5 py-0.5",children:["v","0.1.19"]})]})}),u.jsx("nav",{className:"flex-1 overflow-y-auto py-4",children:u.jsx("ul",{className:"space-y-1",children:g_.map((i,o)=>u.jsx("li",{children:u.jsxs("ul",{children:[i.secao&&u.jsx("li",{className:"px-6 py-2 text-xs font-semibold text-gray-400 uppercase tracking-wider list-none",children:i.secao}),i.itens.map(a=>a.rotulo==="Agentes"?u.jsxs("li",{children:[u.jsxs("button",{type:"button",onClick:()=>s(l=>!l),className:H("sidebar-link w-full flex items-center px-6 py-2.5 text-sm",r(a)&&"active"),children:[u.jsx("i",{className:H(a.icone,"w-5 text-gray-400")}),u.jsx("span",{className:"ml-3",children:a.rotulo}),u.jsx("i",{className:H("fas fa-chevron-down ml-auto text-xs text-gray-400 transition-transform",n&&"rotate-180")})]}),n&&u.jsxs("ul",{className:"pl-12 space-y-1 mt-1",children:[u.jsx("li",{children:u.jsx(Yp,{para:"/agentes?tab=disparo",rotulo:"Agente de Disparo",ativo:e.pathname==="/agentes"&&e.search.includes("disparo")})}),u.jsx("li",{children:u.jsx(Yp,{para:"/agentes?tab=atendimento",rotulo:"Agente de Atendimento",ativo:e.pathname==="/agentes"&&e.search.includes("atendimento")})})]})]},"agentes"):u.jsx("li",{children:u.jsxs(gy,{to:a.para,className:H("sidebar-link flex items-center px-6 py-2.5 text-sm",r(a)&&"active"),children:[u.jsx("i",{className:H(a.icone,"w-5 text-gray-400")}),u.jsx("span",{className:"ml-3",children:a.rotulo})]})},a.para))]})},o))})}),u.jsx("div",{className:"p-4 border-t border-gray-700",children:u.jsxs("button",{onClick:t,className:"w-full flex items-center justify-center px-4 py-2.5 bg-gradient-to-r from-indigo-500 to-purple-500 rounded-lg text-sm font-medium hover:opacity-90 transition",children:[u.jsx("i",{className:"fas fa-sign-out-alt mr-2"})," Sair"]})})]})}function Yp({para:t,rotulo:e,ativo:n}){return u.jsx(gy,{to:t,className:H("sidebar-link block px-4 py-2 text-xs text-gray-300 rounded",n&&"active"),children:e})}const my=S.createContext({toast:()=>{}});function en(){return S.useContext(my)}const x_={sucesso:"bg-green-600",erro:"bg-red-600",info:"bg-indigo-600"},y_={sucesso:"fas fa-check-circle",erro:"fas fa-exclamation-circle",info:"fas fa-info-circle"};function v_({children:t}){const[e,n]=S.useState([]),s=S.useRef(0),r=S.useCallback((i,o)=>{const a=++s.current;n(l=>[...l,{id:a,tipo:i,mensagem:o}]),setTimeout(()=>n(l=>l.filter(c=>c.id!==a)),4500)},[]);return u.jsxs(my.Provider,{value:{toast:r},children:[t,u.jsx("div",{className:"fixed top-4 right-4 z-[100] space-y-2 w-80",children:e.map(i=>u.jsxs("div",{className:H(x_[i.tipo],"text-white text-sm rounded-lg shadow-lg px-4 py-3 flex items-start gap-2 animate-pulse-once"),role:"status",children:[u.jsx("i",{className:H(y_[i.tipo],"mt-0.5")}),u.jsx("span",{className:"flex-1",children:i.mensagem}),u.jsx("button",{className:"opacity-70 hover:opacity-100",onClick:()=>n(o=>o.filter(a=>a.id!==i.id)),"aria-label":"Fechar",children:u.jsx("i",{className:"fas fa-times"})})]},i.id))})]})}function Pa({rotulo:t,valor:e,subtitulo:n,children:s,icone:r}){return u.jsxs("div",{className:"bg-white rounded-xl shadow-sm p-5 border border-gray-100",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx("p",{className:"text-sm text-gray-500 font-medium",children:t}),r&&u.jsx("i",{className:`${r} text-indigo-300`})]}),s??u.jsxs(u.Fragment,{children:[u.jsx("p",{className:"text-2xl font-bold text-gray-800 mt-1",children:e}),n&&u.jsx("p",{className:"text-xs text-gray-400 mt-0.5",children:n})]})]})}/*!
|
|
68
68
|
* @kurkle/color v0.3.4
|
|
69
69
|
* https://github.com/kurkle/color#readme
|
|
70
70
|
* (c) 2024 Jukka Kurkela
|
|
@@ -85,6 +85,6 @@ Error generating stack: `+i.message+`
|
|
|
85
85
|
To pick up a draggable item, press the space bar.
|
|
86
86
|
While dragging, use the arrow keys to move the item.
|
|
87
87
|
Press space again to drop the item in its new position, or press escape to cancel.
|
|
88
|
-
`},TN={onDragStart(t){let{active:e}=t;return"Picked up draggable item "+e.id+"."},onDragOver(t){let{active:e,over:n}=t;return n?"Draggable item "+e.id+" was moved over droppable area "+n.id+".":"Draggable item "+e.id+" is no longer over a droppable area."},onDragEnd(t){let{active:e,over:n}=t;return n?"Draggable item "+e.id+" was dropped over droppable area "+n.id:"Draggable item "+e.id+" was dropped."},onDragCancel(t){let{active:e}=t;return"Dragging was cancelled. Draggable item "+e.id+" was dropped."}};function DN(t){let{announcements:e=TN,container:n,hiddenTextDescribedById:s,screenReaderInstructions:r=ON}=t;const{announce:i,announcement:o}=MN(),a=aa("DndLiveRegion"),[l,c]=S.useState(!1);if(S.useEffect(()=>{c(!0)},[]),PN(S.useMemo(()=>({onDragStart(f){let{active:h}=f;i(e.onDragStart({active:h}))},onDragMove(f){let{active:h,over:p}=f;e.onDragMove&&i(e.onDragMove({active:h,over:p}))},onDragOver(f){let{active:h,over:p}=f;i(e.onDragOver({active:h,over:p}))},onDragEnd(f){let{active:h,over:p}=f;i(e.onDragEnd({active:h,over:p}))},onDragCancel(f){let{active:h,over:p}=f;i(e.onDragCancel({active:h,over:p}))}}),[i,e])),!l)return null;const d=pe.createElement(pe.Fragment,null,pe.createElement(NN,{id:s,value:r.draggable}),pe.createElement(EN,{id:a,announcement:o}));return n?Ar.createPortal(d,n):d}var Te;(function(t){t.DragStart="dragStart",t.DragMove="dragMove",t.DragEnd="dragEnd",t.DragCancel="dragCancel",t.DragOver="dragOver",t.RegisterDroppable="registerDroppable",t.SetDroppableDisabled="setDroppableDisabled",t.UnregisterDroppable="unregisterDroppable"})(Te||(Te={}));function Zl(){}function LN(t,e){return S.useMemo(()=>({sensor:t,options:e??{}}),[t,e])}function AN(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];return S.useMemo(()=>[...e].filter(s=>s!=null),[...e])}const Zt=Object.freeze({x:0,y:0});function IN(t,e){return Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2))}function FN(t,e){const n=Jl(t);if(!n)return"0 0";const s={x:(n.x-e.left)/e.width*100,y:(n.y-e.top)/e.height*100};return s.x+"% "+s.y+"%"}function zN(t,e){let{data:{value:n}}=t,{data:{value:s}}=e;return n-s}function BN(t,e){let{data:{value:n}}=t,{data:{value:s}}=e;return s-n}function am(t){let{left:e,top:n,height:s,width:r}=t;return[{x:e,y:n},{x:e+r,y:n},{x:e,y:n+s},{x:e+r,y:n+s}]}function $N(t,e){if(!t||t.length===0)return null;const[n]=t;return n[e]}const UN=t=>{let{collisionRect:e,droppableRects:n,droppableContainers:s}=t;const r=am(e),i=[];for(const o of s){const{id:a}=o,l=n.get(a);if(l){const c=am(l),d=r.reduce((h,p,m)=>h+IN(c[m],p),0),f=Number((d/4).toFixed(4));i.push({id:a,data:{droppableContainer:o,value:f}})}}return i.sort(zN)};function WN(t,e){const n=Math.max(e.top,t.top),s=Math.max(e.left,t.left),r=Math.min(e.left+e.width,t.left+t.width),i=Math.min(e.top+e.height,t.top+t.height),o=r-s,a=i-n;if(s<r&&n<i){const l=e.width*e.height,c=t.width*t.height,d=o*a,f=d/(l+c-d);return Number(f.toFixed(4))}return 0}const HN=t=>{let{collisionRect:e,droppableRects:n,droppableContainers:s}=t;const r=[];for(const i of s){const{id:o}=i,a=n.get(o);if(a){const l=WN(a,e);l>0&&r.push({id:o,data:{droppableContainer:i,value:l}})}}return r.sort(BN)};function VN(t,e,n){return{...t,scaleX:e&&n?e.width/n.width:1,scaleY:e&&n?e.height/n.height:1}}function lv(t,e){return t&&e?{x:t.left-e.left,y:t.top-e.top}:Zt}function QN(t){return function(n){for(var s=arguments.length,r=new Array(s>1?s-1:0),i=1;i<s;i++)r[i-1]=arguments[i];return r.reduce((o,a)=>({...o,top:o.top+t*a.y,bottom:o.bottom+t*a.y,left:o.left+t*a.x,right:o.right+t*a.x}),{...n})}}const KN=QN(1);function cv(t){if(t.startsWith("matrix3d(")){const e=t.slice(9,-1).split(/, /);return{x:+e[12],y:+e[13],scaleX:+e[0],scaleY:+e[5]}}else if(t.startsWith("matrix(")){const e=t.slice(7,-1).split(/, /);return{x:+e[4],y:+e[5],scaleX:+e[0],scaleY:+e[3]}}return null}function YN(t,e,n){const s=cv(e);if(!s)return t;const{scaleX:r,scaleY:i,x:o,y:a}=s,l=t.left-o-(1-r)*parseFloat(n),c=t.top-a-(1-i)*parseFloat(n.slice(n.indexOf(" ")+1)),d=r?t.width/r:t.width,f=i?t.height/i:t.height;return{width:d,height:f,top:c,right:l+d,bottom:c+f,left:l}}const XN={ignoreTransform:!1};function Ci(t,e){e===void 0&&(e=XN);let n=t.getBoundingClientRect();if(e.ignoreTransform){const{transform:c,transformOrigin:d}=st(t).getComputedStyle(t);c&&(n=YN(n,c,d))}const{top:s,left:r,width:i,height:o,bottom:a,right:l}=n;return{top:s,left:r,width:i,height:o,bottom:a,right:l}}function lm(t){return Ci(t,{ignoreTransform:!0})}function qN(t){const e=t.innerWidth,n=t.innerHeight;return{top:0,left:0,right:e,bottom:n,width:e,height:n}}function GN(t,e){return e===void 0&&(e=st(t).getComputedStyle(t)),e.position==="fixed"}function JN(t,e){e===void 0&&(e=st(t).getComputedStyle(t));const n=/(auto|scroll|overlay)/;return["overflow","overflowX","overflowY"].some(r=>{const i=e[r];return typeof i=="string"?n.test(i):!1})}function lh(t,e){const n=[];function s(r){if(e!=null&&n.length>=e||!r)return n;if(ah(r)&&r.scrollingElement!=null&&!n.includes(r.scrollingElement))return n.push(r.scrollingElement),n;if(!ia(r)||iv(r)||n.includes(r))return n;const i=st(t).getComputedStyle(r);return r!==t&&JN(r,i)&&n.push(r),GN(r,i)?n:s(r.parentNode)}return t?s(t):n}function uv(t){const[e]=lh(t,1);return e??null}function bu(t){return!kc||!t?null:_i(t)?t:oh(t)?ah(t)||t===ki(t).scrollingElement?window:ia(t)?t:null:null}function dv(t){return _i(t)?t.scrollX:t.scrollLeft}function fv(t){return _i(t)?t.scrollY:t.scrollTop}function $d(t){return{x:dv(t),y:fv(t)}}var Ie;(function(t){t[t.Forward=1]="Forward",t[t.Backward=-1]="Backward"})(Ie||(Ie={}));function hv(t){return!kc||!t?!1:t===document.scrollingElement}function pv(t){const e={x:0,y:0},n=hv(t)?{height:window.innerHeight,width:window.innerWidth}:{height:t.clientHeight,width:t.clientWidth},s={x:t.scrollWidth-n.width,y:t.scrollHeight-n.height},r=t.scrollTop<=e.y,i=t.scrollLeft<=e.x,o=t.scrollTop>=s.y,a=t.scrollLeft>=s.x;return{isTop:r,isLeft:i,isBottom:o,isRight:a,maxScroll:s,minScroll:e}}const ZN={x:.2,y:.2};function e2(t,e,n,s,r){let{top:i,left:o,right:a,bottom:l}=n;s===void 0&&(s=10),r===void 0&&(r=ZN);const{isTop:c,isBottom:d,isLeft:f,isRight:h}=pv(t),p={x:0,y:0},m={x:0,y:0},g={height:e.height*r.y,width:e.width*r.x};return!c&&i<=e.top+g.height?(p.y=Ie.Backward,m.y=s*Math.abs((e.top+g.height-i)/g.height)):!d&&l>=e.bottom-g.height&&(p.y=Ie.Forward,m.y=s*Math.abs((e.bottom-g.height-l)/g.height)),!h&&a>=e.right-g.width?(p.x=Ie.Forward,m.x=s*Math.abs((e.right-g.width-a)/g.width)):!f&&o<=e.left+g.width&&(p.x=Ie.Backward,m.x=s*Math.abs((e.left+g.width-o)/g.width)),{direction:p,speed:m}}function t2(t){if(t===document.scrollingElement){const{innerWidth:i,innerHeight:o}=window;return{top:0,left:0,right:i,bottom:o,width:i,height:o}}const{top:e,left:n,right:s,bottom:r}=t.getBoundingClientRect();return{top:e,left:n,right:s,bottom:r,width:t.clientWidth,height:t.clientHeight}}function gv(t){return t.reduce((e,n)=>Qr(e,$d(n)),Zt)}function n2(t){return t.reduce((e,n)=>e+dv(n),0)}function s2(t){return t.reduce((e,n)=>e+fv(n),0)}function mv(t,e){if(e===void 0&&(e=Ci),!t)return;const{top:n,left:s,bottom:r,right:i}=e(t);uv(t)&&(r<=0||i<=0||n>=window.innerHeight||s>=window.innerWidth)&&t.scrollIntoView({block:"center",inline:"center"})}const r2=[["x",["left","right"],n2],["y",["top","bottom"],s2]];class ch{constructor(e,n){this.rect=void 0,this.width=void 0,this.height=void 0,this.top=void 0,this.bottom=void 0,this.right=void 0,this.left=void 0;const s=lh(n),r=gv(s);this.rect={...e},this.width=e.width,this.height=e.height;for(const[i,o,a]of r2)for(const l of o)Object.defineProperty(this,l,{get:()=>{const c=a(s),d=r[i]-c;return this.rect[l]+d},enumerable:!0});Object.defineProperty(this,"rect",{enumerable:!1})}}class go{constructor(e){this.target=void 0,this.listeners=[],this.removeAll=()=>{this.listeners.forEach(n=>{var s;return(s=this.target)==null?void 0:s.removeEventListener(...n)})},this.target=e}add(e,n,s){var r;(r=this.target)==null||r.addEventListener(e,n,s),this.listeners.push([e,n,s])}}function i2(t){const{EventTarget:e}=st(t);return t instanceof e?t:ki(t)}function wu(t,e){const n=Math.abs(t.x),s=Math.abs(t.y);return typeof e=="number"?Math.sqrt(n**2+s**2)>e:"x"in e&&"y"in e?n>e.x&&s>e.y:"x"in e?n>e.x:"y"in e?s>e.y:!1}var Pt;(function(t){t.Click="click",t.DragStart="dragstart",t.Keydown="keydown",t.ContextMenu="contextmenu",t.Resize="resize",t.SelectionChange="selectionchange",t.VisibilityChange="visibilitychange"})(Pt||(Pt={}));function cm(t){t.preventDefault()}function o2(t){t.stopPropagation()}var se;(function(t){t.Space="Space",t.Down="ArrowDown",t.Right="ArrowRight",t.Left="ArrowLeft",t.Up="ArrowUp",t.Esc="Escape",t.Enter="Enter",t.Tab="Tab"})(se||(se={}));const xv={start:[se.Space,se.Enter],cancel:[se.Esc],end:[se.Space,se.Enter,se.Tab]},a2=(t,e)=>{let{currentCoordinates:n}=e;switch(t.code){case se.Right:return{...n,x:n.x+25};case se.Left:return{...n,x:n.x-25};case se.Down:return{...n,y:n.y+25};case se.Up:return{...n,y:n.y-25}}};class yv{constructor(e){this.props=void 0,this.autoScrollEnabled=!1,this.referenceCoordinates=void 0,this.listeners=void 0,this.windowListeners=void 0,this.props=e;const{event:{target:n}}=e;this.props=e,this.listeners=new go(ki(n)),this.windowListeners=new go(st(n)),this.handleKeyDown=this.handleKeyDown.bind(this),this.handleCancel=this.handleCancel.bind(this),this.attach()}attach(){this.handleStart(),this.windowListeners.add(Pt.Resize,this.handleCancel),this.windowListeners.add(Pt.VisibilityChange,this.handleCancel),setTimeout(()=>this.listeners.add(Pt.Keydown,this.handleKeyDown))}handleStart(){const{activeNode:e,onStart:n}=this.props,s=e.node.current;s&&mv(s),n(Zt)}handleKeyDown(e){if(jc(e)){const{active:n,context:s,options:r}=this.props,{keyboardCodes:i=xv,coordinateGetter:o=a2,scrollBehavior:a="smooth"}=r,{code:l}=e;if(i.end.includes(l)){this.handleEnd(e);return}if(i.cancel.includes(l)){this.handleCancel(e);return}const{collisionRect:c}=s.current,d=c?{x:c.left,y:c.top}:Zt;this.referenceCoordinates||(this.referenceCoordinates=d);const f=o(e,{active:n,context:s.current,currentCoordinates:d});if(f){const h=Gl(f,d),p={x:0,y:0},{scrollableAncestors:m}=s.current;for(const g of m){const b=e.code,{isTop:y,isRight:x,isLeft:v,isBottom:_,maxScroll:w,minScroll:k}=pv(g),C=t2(g),j={x:Math.min(b===se.Right?C.right-C.width/2:C.right,Math.max(b===se.Right?C.left:C.left+C.width/2,f.x)),y:Math.min(b===se.Down?C.bottom-C.height/2:C.bottom,Math.max(b===se.Down?C.top:C.top+C.height/2,f.y))},M=b===se.Right&&!x||b===se.Left&&!v,E=b===se.Down&&!_||b===se.Up&&!y;if(M&&j.x!==f.x){const P=g.scrollLeft+h.x,A=b===se.Right&&P<=w.x||b===se.Left&&P>=k.x;if(A&&!h.y){g.scrollTo({left:P,behavior:a});return}A?p.x=g.scrollLeft-P:p.x=b===se.Right?g.scrollLeft-w.x:g.scrollLeft-k.x,p.x&&g.scrollBy({left:-p.x,behavior:a});break}else if(E&&j.y!==f.y){const P=g.scrollTop+h.y,A=b===se.Down&&P<=w.y||b===se.Up&&P>=k.y;if(A&&!h.x){g.scrollTo({top:P,behavior:a});return}A?p.y=g.scrollTop-P:p.y=b===se.Down?g.scrollTop-w.y:g.scrollTop-k.y,p.y&&g.scrollBy({top:-p.y,behavior:a});break}}this.handleMove(e,Qr(Gl(f,this.referenceCoordinates),p))}}}handleMove(e,n){const{onMove:s}=this.props;e.preventDefault(),s(n)}handleEnd(e){const{onEnd:n}=this.props;e.preventDefault(),this.detach(),n()}handleCancel(e){const{onCancel:n}=this.props;e.preventDefault(),this.detach(),n()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll()}}yv.activators=[{eventName:"onKeyDown",handler:(t,e,n)=>{let{keyboardCodes:s=xv,onActivation:r}=e,{active:i}=n;const{code:o}=t.nativeEvent;if(s.start.includes(o)){const a=i.activatorNode.current;return a&&t.target!==a?!1:(t.preventDefault(),r==null||r({event:t.nativeEvent}),!0)}return!1}}];function um(t){return!!(t&&"distance"in t)}function dm(t){return!!(t&&"delay"in t)}class uh{constructor(e,n,s){var r;s===void 0&&(s=i2(e.event.target)),this.props=void 0,this.events=void 0,this.autoScrollEnabled=!0,this.document=void 0,this.activated=!1,this.initialCoordinates=void 0,this.timeoutId=null,this.listeners=void 0,this.documentListeners=void 0,this.windowListeners=void 0,this.props=e,this.events=n;const{event:i}=e,{target:o}=i;this.props=e,this.events=n,this.document=ki(o),this.documentListeners=new go(this.document),this.listeners=new go(s),this.windowListeners=new go(st(o)),this.initialCoordinates=(r=Jl(i))!=null?r:Zt,this.handleStart=this.handleStart.bind(this),this.handleMove=this.handleMove.bind(this),this.handleEnd=this.handleEnd.bind(this),this.handleCancel=this.handleCancel.bind(this),this.handleKeydown=this.handleKeydown.bind(this),this.removeTextSelection=this.removeTextSelection.bind(this),this.attach()}attach(){const{events:e,props:{options:{activationConstraint:n,bypassActivationConstraint:s}}}=this;if(this.listeners.add(e.move.name,this.handleMove,{passive:!1}),this.listeners.add(e.end.name,this.handleEnd),e.cancel&&this.listeners.add(e.cancel.name,this.handleCancel),this.windowListeners.add(Pt.Resize,this.handleCancel),this.windowListeners.add(Pt.DragStart,cm),this.windowListeners.add(Pt.VisibilityChange,this.handleCancel),this.windowListeners.add(Pt.ContextMenu,cm),this.documentListeners.add(Pt.Keydown,this.handleKeydown),n){if(s!=null&&s({event:this.props.event,activeNode:this.props.activeNode,options:this.props.options}))return this.handleStart();if(dm(n)){this.timeoutId=setTimeout(this.handleStart,n.delay),this.handlePending(n);return}if(um(n)){this.handlePending(n);return}}this.handleStart()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll(),setTimeout(this.documentListeners.removeAll,50),this.timeoutId!==null&&(clearTimeout(this.timeoutId),this.timeoutId=null)}handlePending(e,n){const{active:s,onPending:r}=this.props;r(s,e,this.initialCoordinates,n)}handleStart(){const{initialCoordinates:e}=this,{onStart:n}=this.props;e&&(this.activated=!0,this.documentListeners.add(Pt.Click,o2,{capture:!0}),this.removeTextSelection(),this.documentListeners.add(Pt.SelectionChange,this.removeTextSelection),n(e))}handleMove(e){var n;const{activated:s,initialCoordinates:r,props:i}=this,{onMove:o,options:{activationConstraint:a}}=i;if(!r)return;const l=(n=Jl(e))!=null?n:Zt,c=Gl(r,l);if(!s&&a){if(um(a)){if(a.tolerance!=null&&wu(c,a.tolerance))return this.handleCancel();if(wu(c,a.distance))return this.handleStart()}if(dm(a)&&wu(c,a.tolerance))return this.handleCancel();this.handlePending(a,c);return}e.cancelable&&e.preventDefault(),o(l)}handleEnd(){const{onAbort:e,onEnd:n}=this.props;this.detach(),this.activated||e(this.props.active),n()}handleCancel(){const{onAbort:e,onCancel:n}=this.props;this.detach(),this.activated||e(this.props.active),n()}handleKeydown(e){e.code===se.Esc&&this.handleCancel()}removeTextSelection(){var e;(e=this.document.getSelection())==null||e.removeAllRanges()}}const l2={cancel:{name:"pointercancel"},move:{name:"pointermove"},end:{name:"pointerup"}};class dh extends uh{constructor(e){const{event:n}=e,s=ki(n.target);super(e,l2,s)}}dh.activators=[{eventName:"onPointerDown",handler:(t,e)=>{let{nativeEvent:n}=t,{onActivation:s}=e;return!n.isPrimary||n.button!==0?!1:(s==null||s({event:n}),!0)}}];const c2={move:{name:"mousemove"},end:{name:"mouseup"}};var Ud;(function(t){t[t.RightClick=2]="RightClick"})(Ud||(Ud={}));class u2 extends uh{constructor(e){super(e,c2,ki(e.event.target))}}u2.activators=[{eventName:"onMouseDown",handler:(t,e)=>{let{nativeEvent:n}=t,{onActivation:s}=e;return n.button===Ud.RightClick?!1:(s==null||s({event:n}),!0)}}];const Su={cancel:{name:"touchcancel"},move:{name:"touchmove"},end:{name:"touchend"}};class d2 extends uh{constructor(e){super(e,Su)}static setup(){return window.addEventListener(Su.move.name,e,{capture:!1,passive:!1}),function(){window.removeEventListener(Su.move.name,e)};function e(){}}}d2.activators=[{eventName:"onTouchStart",handler:(t,e)=>{let{nativeEvent:n}=t,{onActivation:s}=e;const{touches:r}=n;return r.length>1?!1:(s==null||s({event:n}),!0)}}];var mo;(function(t){t[t.Pointer=0]="Pointer",t[t.DraggableRect=1]="DraggableRect"})(mo||(mo={}));var ec;(function(t){t[t.TreeOrder=0]="TreeOrder",t[t.ReversedTreeOrder=1]="ReversedTreeOrder"})(ec||(ec={}));function f2(t){let{acceleration:e,activator:n=mo.Pointer,canScroll:s,draggingRect:r,enabled:i,interval:o=5,order:a=ec.TreeOrder,pointerCoordinates:l,scrollableAncestors:c,scrollableAncestorRects:d,delta:f,threshold:h}=t;const p=p2({delta:f,disabled:!i}),[m,g]=SN(),b=S.useRef({x:0,y:0}),y=S.useRef({x:0,y:0}),x=S.useMemo(()=>{switch(n){case mo.Pointer:return l?{top:l.y,bottom:l.y,left:l.x,right:l.x}:null;case mo.DraggableRect:return r}},[n,r,l]),v=S.useRef(null),_=S.useCallback(()=>{const k=v.current;if(!k)return;const C=b.current.x*y.current.x,j=b.current.y*y.current.y;k.scrollBy(C,j)},[]),w=S.useMemo(()=>a===ec.TreeOrder?[...c].reverse():c,[a,c]);S.useEffect(()=>{if(!i||!c.length||!x){g();return}for(const k of w){if((s==null?void 0:s(k))===!1)continue;const C=c.indexOf(k),j=d[C];if(!j)continue;const{direction:M,speed:E}=e2(k,j,x,e,h);for(const P of["x","y"])p[P][M[P]]||(E[P]=0,M[P]=0);if(E.x>0||E.y>0){g(),v.current=k,m(_,o),b.current=E,y.current=M;return}}b.current={x:0,y:0},y.current={x:0,y:0},g()},[e,_,s,g,i,o,JSON.stringify(x),JSON.stringify(p),m,c,w,d,JSON.stringify(h)])}const h2={x:{[Ie.Backward]:!1,[Ie.Forward]:!1},y:{[Ie.Backward]:!1,[Ie.Forward]:!1}};function p2(t){let{delta:e,disabled:n}=t;const s=ql(e);return oa(r=>{if(n||!s||!r)return h2;const i={x:Math.sign(e.x-s.x),y:Math.sign(e.y-s.y)};return{x:{[Ie.Backward]:r.x[Ie.Backward]||i.x===-1,[Ie.Forward]:r.x[Ie.Forward]||i.x===1},y:{[Ie.Backward]:r.y[Ie.Backward]||i.y===-1,[Ie.Forward]:r.y[Ie.Forward]||i.y===1}}},[n,e,s])}function g2(t,e){const n=e!=null?t.get(e):void 0,s=n?n.node.current:null;return oa(r=>{var i;return e==null?null:(i=s??r)!=null?i:null},[s,e])}function m2(t,e){return S.useMemo(()=>t.reduce((n,s)=>{const{sensor:r}=s,i=r.activators.map(o=>({eventName:o.eventName,handler:e(o.handler,s)}));return[...n,...i]},[]),[t,e])}var Wo;(function(t){t[t.Always=0]="Always",t[t.BeforeDragging=1]="BeforeDragging",t[t.WhileDragging=2]="WhileDragging"})(Wo||(Wo={}));var Wd;(function(t){t.Optimized="optimized"})(Wd||(Wd={}));const fm=new Map;function x2(t,e){let{dragging:n,dependencies:s,config:r}=e;const[i,o]=S.useState(null),{frequency:a,measure:l,strategy:c}=r,d=S.useRef(t),f=b(),h=Uo(f),p=S.useCallback(function(y){y===void 0&&(y=[]),!h.current&&o(x=>x===null?y:x.concat(y.filter(v=>!x.includes(v))))},[h]),m=S.useRef(null),g=oa(y=>{if(f&&!n)return fm;if(!y||y===fm||d.current!==t||i!=null){const x=new Map;for(let v of t){if(!v)continue;if(i&&i.length>0&&!i.includes(v.id)&&v.rect.current){x.set(v.id,v.rect.current);continue}const _=v.node.current,w=_?new ch(l(_),_):null;v.rect.current=w,w&&x.set(v.id,w)}return x}return y},[t,i,n,f,l]);return S.useEffect(()=>{d.current=t},[t]),S.useEffect(()=>{f||p()},[n,f]),S.useEffect(()=>{i&&i.length>0&&o(null)},[JSON.stringify(i)]),S.useEffect(()=>{f||typeof a!="number"||m.current!==null||(m.current=setTimeout(()=>{p(),m.current=null},a))},[a,f,p,...s]),{droppableRects:g,measureDroppableContainers:p,measuringScheduled:i!=null};function b(){switch(c){case Wo.Always:return!1;case Wo.BeforeDragging:return n;default:return!n}}}function fh(t,e){return oa(n=>t?n||(typeof e=="function"?e(t):t):null,[e,t])}function y2(t,e){return fh(t,e)}function v2(t){let{callback:e,disabled:n}=t;const s=Cc(e),r=S.useMemo(()=>{if(n||typeof window>"u"||typeof window.MutationObserver>"u")return;const{MutationObserver:i}=window;return new i(s)},[s,n]);return S.useEffect(()=>()=>r==null?void 0:r.disconnect(),[r]),r}function Nc(t){let{callback:e,disabled:n}=t;const s=Cc(e),r=S.useMemo(()=>{if(n||typeof window>"u"||typeof window.ResizeObserver>"u")return;const{ResizeObserver:i}=window;return new i(s)},[n]);return S.useEffect(()=>()=>r==null?void 0:r.disconnect(),[r]),r}function b2(t){return new ch(Ci(t),t)}function hm(t,e,n){e===void 0&&(e=b2);const[s,r]=S.useState(null);function i(){r(l=>{if(!t)return null;if(t.isConnected===!1){var c;return(c=l??n)!=null?c:null}const d=e(t);return JSON.stringify(l)===JSON.stringify(d)?l:d})}const o=v2({callback(l){if(t)for(const c of l){const{type:d,target:f}=c;if(d==="childList"&&f instanceof HTMLElement&&f.contains(t)){i();break}}}}),a=Nc({callback:i});return Jt(()=>{i(),t?(a==null||a.observe(t),o==null||o.observe(document.body,{childList:!0,subtree:!0})):(a==null||a.disconnect(),o==null||o.disconnect())},[t]),s}function w2(t){const e=fh(t);return lv(t,e)}const pm=[];function S2(t){const e=S.useRef(t),n=oa(s=>t?s&&s!==pm&&t&&e.current&&t.parentNode===e.current.parentNode?s:lh(t):pm,[t]);return S.useEffect(()=>{e.current=t},[t]),n}function _2(t){const[e,n]=S.useState(null),s=S.useRef(t),r=S.useCallback(i=>{const o=bu(i.target);o&&n(a=>a?(a.set(o,$d(o)),new Map(a)):null)},[]);return S.useEffect(()=>{const i=s.current;if(t!==i){o(i);const a=t.map(l=>{const c=bu(l);return c?(c.addEventListener("scroll",r,{passive:!0}),[c,$d(c)]):null}).filter(l=>l!=null);n(a.length?new Map(a):null),s.current=t}return()=>{o(t),o(i)};function o(a){a.forEach(l=>{const c=bu(l);c==null||c.removeEventListener("scroll",r)})}},[r,t]),S.useMemo(()=>t.length?e?Array.from(e.values()).reduce((i,o)=>Qr(i,o),Zt):gv(t):Zt,[t,e])}function gm(t,e){e===void 0&&(e=[]);const n=S.useRef(null);return S.useEffect(()=>{n.current=null},e),S.useEffect(()=>{const s=t!==Zt;s&&!n.current&&(n.current=t),!s&&n.current&&(n.current=null)},[t]),n.current?Gl(t,n.current):Zt}function k2(t){S.useEffect(()=>{if(!kc)return;const e=t.map(n=>{let{sensor:s}=n;return s.setup==null?void 0:s.setup()});return()=>{for(const n of e)n==null||n()}},t.map(e=>{let{sensor:n}=e;return n}))}function C2(t,e){return S.useMemo(()=>t.reduce((n,s)=>{let{eventName:r,handler:i}=s;return n[r]=o=>{i(o,e)},n},{}),[t,e])}function vv(t){return S.useMemo(()=>t?qN(t):null,[t])}const mm=[];function j2(t,e){e===void 0&&(e=Ci);const[n]=t,s=vv(n?st(n):null),[r,i]=S.useState(mm);function o(){i(()=>t.length?t.map(l=>hv(l)?s:new ch(e(l),l)):mm)}const a=Nc({callback:o});return Jt(()=>{a==null||a.disconnect(),o(),t.forEach(l=>a==null?void 0:a.observe(l))},[t]),r}function bv(t){if(!t)return null;if(t.children.length>1)return t;const e=t.children[0];return ia(e)?e:t}function N2(t){let{measure:e}=t;const[n,s]=S.useState(null),r=S.useCallback(c=>{for(const{target:d}of c)if(ia(d)){s(f=>{const h=e(d);return f?{...f,width:h.width,height:h.height}:h});break}},[e]),i=Nc({callback:r}),o=S.useCallback(c=>{const d=bv(c);i==null||i.disconnect(),d&&(i==null||i.observe(d)),s(d?e(d):null)},[e,i]),[a,l]=Xl(o);return S.useMemo(()=>({nodeRef:a,rect:n,setRef:l}),[n,a,l])}const E2=[{sensor:dh,options:{}},{sensor:yv,options:{}}],M2={current:{}},cl={draggable:{measure:lm},droppable:{measure:lm,strategy:Wo.WhileDragging,frequency:Wd.Optimized},dragOverlay:{measure:Ci}};class xo extends Map{get(e){var n;return e!=null&&(n=super.get(e))!=null?n:void 0}toArray(){return Array.from(this.values())}getEnabled(){return this.toArray().filter(e=>{let{disabled:n}=e;return!n})}getNodeFor(e){var n,s;return(n=(s=this.get(e))==null?void 0:s.node.current)!=null?n:void 0}}const P2={activatorEvent:null,active:null,activeNode:null,activeNodeRect:null,collisions:null,containerNodeRect:null,draggableNodes:new Map,droppableRects:new Map,droppableContainers:new xo,over:null,dragOverlay:{nodeRef:{current:null},rect:null,setRef:Zl},scrollableAncestors:[],scrollableAncestorRects:[],measuringConfiguration:cl,measureDroppableContainers:Zl,windowRect:null,measuringScheduled:!1},wv={activatorEvent:null,activators:[],active:null,activeNodeRect:null,ariaDescribedById:{draggable:""},dispatch:Zl,draggableNodes:new Map,over:null,measureDroppableContainers:Zl},la=S.createContext(wv),Sv=S.createContext(P2);function R2(){return{draggable:{active:null,initialCoordinates:{x:0,y:0},nodes:new Map,translate:{x:0,y:0}},droppable:{containers:new xo}}}function O2(t,e){switch(e.type){case Te.DragStart:return{...t,draggable:{...t.draggable,initialCoordinates:e.initialCoordinates,active:e.active}};case Te.DragMove:return t.draggable.active==null?t:{...t,draggable:{...t.draggable,translate:{x:e.coordinates.x-t.draggable.initialCoordinates.x,y:e.coordinates.y-t.draggable.initialCoordinates.y}}};case Te.DragEnd:case Te.DragCancel:return{...t,draggable:{...t.draggable,active:null,initialCoordinates:{x:0,y:0},translate:{x:0,y:0}}};case Te.RegisterDroppable:{const{element:n}=e,{id:s}=n,r=new xo(t.droppable.containers);return r.set(s,n),{...t,droppable:{...t.droppable,containers:r}}}case Te.SetDroppableDisabled:{const{id:n,key:s,disabled:r}=e,i=t.droppable.containers.get(n);if(!i||s!==i.key)return t;const o=new xo(t.droppable.containers);return o.set(n,{...i,disabled:r}),{...t,droppable:{...t.droppable,containers:o}}}case Te.UnregisterDroppable:{const{id:n,key:s}=e,r=t.droppable.containers.get(n);if(!r||s!==r.key)return t;const i=new xo(t.droppable.containers);return i.delete(n),{...t,droppable:{...t.droppable,containers:i}}}default:return t}}function T2(t){let{disabled:e}=t;const{active:n,activatorEvent:s,draggableNodes:r}=S.useContext(la),i=ql(s),o=ql(n==null?void 0:n.id);return S.useEffect(()=>{if(!e&&!s&&i&&o!=null){if(!jc(i)||document.activeElement===i.target)return;const a=r.get(o);if(!a)return;const{activatorNode:l,node:c}=a;if(!l.current&&!c.current)return;requestAnimationFrame(()=>{for(const d of[l.current,c.current]){if(!d)continue;const f=CN(d);if(f){f.focus();break}}})}},[s,e,r,o,i]),null}function _v(t,e){let{transform:n,...s}=e;return t!=null&&t.length?t.reduce((r,i)=>i({transform:r,...s}),n):n}function D2(t){return S.useMemo(()=>({draggable:{...cl.draggable,...t==null?void 0:t.draggable},droppable:{...cl.droppable,...t==null?void 0:t.droppable},dragOverlay:{...cl.dragOverlay,...t==null?void 0:t.dragOverlay}}),[t==null?void 0:t.draggable,t==null?void 0:t.droppable,t==null?void 0:t.dragOverlay])}function L2(t){let{activeNode:e,measure:n,initialRect:s,config:r=!0}=t;const i=S.useRef(!1),{x:o,y:a}=typeof r=="boolean"?{x:r,y:r}:r;Jt(()=>{if(!o&&!a||!e){i.current=!1;return}if(i.current||!s)return;const c=e==null?void 0:e.node.current;if(!c||c.isConnected===!1)return;const d=n(c),f=lv(d,s);if(o||(f.x=0),a||(f.y=0),i.current=!0,Math.abs(f.x)>0||Math.abs(f.y)>0){const h=uv(c);h&&h.scrollBy({top:f.y,left:f.x})}},[e,o,a,s,n])}const Ec=S.createContext({...Zt,scaleX:1,scaleY:1});var Yn;(function(t){t[t.Uninitialized=0]="Uninitialized",t[t.Initializing=1]="Initializing",t[t.Initialized=2]="Initialized"})(Yn||(Yn={}));const A2=S.memo(function(e){var n,s,r,i;let{id:o,accessibility:a,autoScroll:l=!0,children:c,sensors:d=E2,collisionDetection:f=HN,measuring:h,modifiers:p,...m}=e;const g=S.useReducer(O2,void 0,R2),[b,y]=g,[x,v]=RN(),[_,w]=S.useState(Yn.Uninitialized),k=_===Yn.Initialized,{draggable:{active:C,nodes:j,translate:M},droppable:{containers:E}}=b,P=C!=null?j.get(C):null,A=S.useRef({initial:null,translated:null}),Q=S.useMemo(()=>{var Ve;return C!=null?{id:C,data:(Ve=P==null?void 0:P.data)!=null?Ve:M2,rect:A}:null},[C,P]),ne=S.useRef(null),[Y,oe]=S.useState(null),[G,O]=S.useState(null),L=Uo(m,Object.values(m)),I=aa("DndDescribedBy",o),V=S.useMemo(()=>E.getEnabled(),[E]),F=D2(h),{droppableRects:ce,measureDroppableContainers:$,measuringScheduled:ke}=x2(V,{dragging:k,dependencies:[M.x,M.y],config:F.droppable}),J=g2(j,C),gt=S.useMemo(()=>G?Jl(G):null,[G]),Ft=zv(),zt=y2(J,F.draggable.measure);L2({activeNode:C!=null?j.get(C):null,config:Ft.layoutShiftCompensation,initialRect:zt,measure:F.draggable.measure});const ie=hm(J,F.draggable.measure,zt),ji=hm(J?J.parentElement:null),tn=S.useRef({activatorEvent:null,active:null,activeNode:J,collisionRect:null,collisions:null,droppableRects:ce,draggableNodes:j,draggingNode:null,draggingNodeRect:null,droppableContainers:E,over:null,scrollableAncestors:[],scrollAdjustedTranslate:null}),pr=E.getNodeFor((n=tn.current.over)==null?void 0:n.id),vn=N2({measure:F.dragOverlay.measure}),gr=(s=vn.nodeRef.current)!=null?s:J,mr=k?(r=vn.rect)!=null?r:ie:null,hh=!!(vn.nodeRef.current&&vn.rect),ph=w2(hh?null:ie),Mc=vv(gr?st(gr):null),Fn=S2(k?pr??J:null),ca=j2(Fn),ua=_v(p,{transform:{x:M.x-ph.x,y:M.y-ph.y,scaleX:1,scaleY:1},activatorEvent:G,active:Q,activeNodeRect:ie,containerNodeRect:ji,draggingNodeRect:mr,over:tn.current.over,overlayNodeRect:vn.rect,scrollableAncestors:Fn,scrollableAncestorRects:ca,windowRect:Mc}),gh=gt?Qr(gt,M):null,mh=_2(Fn),Ov=gm(mh),Tv=gm(mh,[ie]),xr=Qr(ua,Ov),yr=mr?KN(mr,ua):null,Ni=Q&&yr?f({active:Q,collisionRect:yr,droppableRects:ce,droppableContainers:V,pointerCoordinates:gh}):null,xh=$N(Ni,"id"),[zn,yh]=S.useState(null),Dv=hh?ua:Qr(ua,Tv),Lv=VN(Dv,(i=zn==null?void 0:zn.rect)!=null?i:null,ie),Pc=S.useRef(null),vh=S.useCallback((Ve,mt)=>{let{sensor:xt,options:Bn}=mt;if(ne.current==null)return;const Nt=j.get(ne.current);if(!Nt)return;const yt=Ve.nativeEvent,nn=new xt({active:ne.current,activeNode:Nt,event:yt,options:Bn,context:tn,onAbort(Be){if(!j.get(Be))return;const{onDragAbort:sn}=L.current,bn={id:Be};sn==null||sn(bn),x({type:"onDragAbort",event:bn})},onPending(Be,$n,sn,bn){if(!j.get(Be))return;const{onDragPending:Mi}=L.current,Un={id:Be,constraint:$n,initialCoordinates:sn,offset:bn};Mi==null||Mi(Un),x({type:"onDragPending",event:Un})},onStart(Be){const $n=ne.current;if($n==null)return;const sn=j.get($n);if(!sn)return;const{onDragStart:bn}=L.current,Ei={activatorEvent:yt,active:{id:$n,data:sn.data,rect:A}};Ar.unstable_batchedUpdates(()=>{bn==null||bn(Ei),w(Yn.Initializing),y({type:Te.DragStart,initialCoordinates:Be,active:$n}),x({type:"onDragStart",event:Ei}),oe(Pc.current),O(yt)})},onMove(Be){y({type:Te.DragMove,coordinates:Be})},onEnd:vr(Te.DragEnd),onCancel:vr(Te.DragCancel)});Pc.current=nn;function vr(Be){return async function(){const{active:sn,collisions:bn,over:Ei,scrollAdjustedTranslate:Mi}=tn.current;let Un=null;if(sn&&Mi){const{cancelDrop:Pi}=L.current;Un={activatorEvent:yt,active:sn,collisions:bn,delta:Mi,over:Ei},Be===Te.DragEnd&&typeof Pi=="function"&&await Promise.resolve(Pi(Un))&&(Be=Te.DragCancel)}ne.current=null,Ar.unstable_batchedUpdates(()=>{y({type:Be}),w(Yn.Uninitialized),yh(null),oe(null),O(null),Pc.current=null;const Pi=Be===Te.DragEnd?"onDragEnd":"onDragCancel";if(Un){const Rc=L.current[Pi];Rc==null||Rc(Un),x({type:Pi,event:Un})}})}}},[j]),Av=S.useCallback((Ve,mt)=>(xt,Bn)=>{const Nt=xt.nativeEvent,yt=j.get(Bn);if(ne.current!==null||!yt||Nt.dndKit||Nt.defaultPrevented)return;const nn={active:yt};Ve(xt,mt.options,nn)===!0&&(Nt.dndKit={capturedBy:mt.sensor},ne.current=Bn,vh(xt,mt))},[j,vh]),bh=m2(d,Av);k2(d),Jt(()=>{ie&&_===Yn.Initializing&&w(Yn.Initialized)},[ie,_]),S.useEffect(()=>{const{onDragMove:Ve}=L.current,{active:mt,activatorEvent:xt,collisions:Bn,over:Nt}=tn.current;if(!mt||!xt)return;const yt={active:mt,activatorEvent:xt,collisions:Bn,delta:{x:xr.x,y:xr.y},over:Nt};Ar.unstable_batchedUpdates(()=>{Ve==null||Ve(yt),x({type:"onDragMove",event:yt})})},[xr.x,xr.y]),S.useEffect(()=>{const{active:Ve,activatorEvent:mt,collisions:xt,droppableContainers:Bn,scrollAdjustedTranslate:Nt}=tn.current;if(!Ve||ne.current==null||!mt||!Nt)return;const{onDragOver:yt}=L.current,nn=Bn.get(xh),vr=nn&&nn.rect.current?{id:nn.id,rect:nn.rect.current,data:nn.data,disabled:nn.disabled}:null,Be={active:Ve,activatorEvent:mt,collisions:xt,delta:{x:Nt.x,y:Nt.y},over:vr};Ar.unstable_batchedUpdates(()=>{yh(vr),yt==null||yt(Be),x({type:"onDragOver",event:Be})})},[xh]),Jt(()=>{tn.current={activatorEvent:G,active:Q,activeNode:J,collisionRect:yr,collisions:Ni,droppableRects:ce,draggableNodes:j,draggingNode:gr,draggingNodeRect:mr,droppableContainers:E,over:zn,scrollableAncestors:Fn,scrollAdjustedTranslate:xr},A.current={initial:mr,translated:yr}},[Q,J,Ni,yr,j,gr,mr,ce,E,zn,Fn,xr]),f2({...Ft,delta:M,draggingRect:yr,pointerCoordinates:gh,scrollableAncestors:Fn,scrollableAncestorRects:ca});const Iv=S.useMemo(()=>({active:Q,activeNode:J,activeNodeRect:ie,activatorEvent:G,collisions:Ni,containerNodeRect:ji,dragOverlay:vn,draggableNodes:j,droppableContainers:E,droppableRects:ce,over:zn,measureDroppableContainers:$,scrollableAncestors:Fn,scrollableAncestorRects:ca,measuringConfiguration:F,measuringScheduled:ke,windowRect:Mc}),[Q,J,ie,G,Ni,ji,vn,j,E,ce,zn,$,Fn,ca,F,ke,Mc]),Fv=S.useMemo(()=>({activatorEvent:G,activators:bh,active:Q,activeNodeRect:ie,ariaDescribedById:{draggable:I},dispatch:y,draggableNodes:j,over:zn,measureDroppableContainers:$}),[G,bh,Q,ie,y,I,j,zn,$]);return pe.createElement(av.Provider,{value:v},pe.createElement(la.Provider,{value:Fv},pe.createElement(Sv.Provider,{value:Iv},pe.createElement(Ec.Provider,{value:Lv},c)),pe.createElement(T2,{disabled:(a==null?void 0:a.restoreFocus)===!1})),pe.createElement(DN,{...a,hiddenTextDescribedById:I}));function zv(){const Ve=(Y==null?void 0:Y.autoScrollEnabled)===!1,mt=typeof l=="object"?l.enabled===!1:l===!1,xt=k&&!Ve&&!mt;return typeof l=="object"?{...l,enabled:xt}:{enabled:xt}}}),I2=S.createContext(null),xm="button",F2="Draggable";function z2(t){let{id:e,data:n,disabled:s=!1,attributes:r}=t;const i=aa(F2),{activators:o,activatorEvent:a,active:l,activeNodeRect:c,ariaDescribedById:d,draggableNodes:f,over:h}=S.useContext(la),{role:p=xm,roleDescription:m="draggable",tabIndex:g=0}=r??{},b=(l==null?void 0:l.id)===e,y=S.useContext(b?Ec:I2),[x,v]=Xl(),[_,w]=Xl(),k=C2(o,e),C=Uo(n);Jt(()=>(f.set(e,{id:e,key:i,node:x,activatorNode:_,data:C}),()=>{const M=f.get(e);M&&M.key===i&&f.delete(e)}),[f,e]);const j=S.useMemo(()=>({role:p,tabIndex:g,"aria-disabled":s,"aria-pressed":b&&p===xm?!0:void 0,"aria-roledescription":m,"aria-describedby":d.draggable}),[s,p,g,b,m,d.draggable]);return{active:l,activatorEvent:a,activeNodeRect:c,attributes:j,isDragging:b,listeners:s?void 0:k,node:x,over:h,setNodeRef:v,setActivatorNodeRef:w,transform:y}}function kv(){return S.useContext(Sv)}const B2="Droppable",$2={timeout:25};function Cv(t){let{data:e,disabled:n=!1,id:s,resizeObserverConfig:r}=t;const i=aa(B2),{active:o,dispatch:a,over:l,measureDroppableContainers:c}=S.useContext(la),d=S.useRef({disabled:n}),f=S.useRef(!1),h=S.useRef(null),p=S.useRef(null),{disabled:m,updateMeasurementsFor:g,timeout:b}={...$2,...r},y=Uo(g??s),x=S.useCallback(()=>{if(!f.current){f.current=!0;return}p.current!=null&&clearTimeout(p.current),p.current=setTimeout(()=>{c(Array.isArray(y.current)?y.current:[y.current]),p.current=null},b)},[b]),v=Nc({callback:x,disabled:m||!o}),_=S.useCallback((j,M)=>{v&&(M&&(v.unobserve(M),f.current=!1),j&&v.observe(j))},[v]),[w,k]=Xl(_),C=Uo(e);return S.useEffect(()=>{!v||!w.current||(v.disconnect(),f.current=!1,v.observe(w.current))},[w,v]),S.useEffect(()=>(a({type:Te.RegisterDroppable,element:{id:s,key:i,disabled:n,node:w,rect:h,data:C}}),()=>a({type:Te.UnregisterDroppable,key:i,id:s})),[s]),S.useEffect(()=>{n!==d.current.disabled&&(a({type:Te.SetDroppableDisabled,id:s,key:i,disabled:n}),d.current.disabled=n)},[s,i,n,a]),{active:o,rect:h,isOver:(l==null?void 0:l.id)===s,node:w,over:l,setNodeRef:k}}function U2(t){let{animation:e,children:n}=t;const[s,r]=S.useState(null),[i,o]=S.useState(null),a=ql(n);return!n&&!s&&a&&r(a),Jt(()=>{if(!i)return;const l=s==null?void 0:s.key,c=s==null?void 0:s.props.id;if(l==null||c==null){r(null);return}Promise.resolve(e(c,i)).then(()=>{r(null)})},[e,s,i]),pe.createElement(pe.Fragment,null,n,s?S.cloneElement(s,{ref:o}):null)}const W2={x:0,y:0,scaleX:1,scaleY:1};function H2(t){let{children:e}=t;return pe.createElement(la.Provider,{value:wv},pe.createElement(Ec.Provider,{value:W2},e))}const V2={position:"fixed",touchAction:"none"},Q2=t=>jc(t)?"transform 250ms ease":void 0,K2=S.forwardRef((t,e)=>{let{as:n,activatorEvent:s,adjustScale:r,children:i,className:o,rect:a,style:l,transform:c,transition:d=Q2}=t;if(!a)return null;const f=r?c:{...c,scaleX:1,scaleY:1},h={...V2,width:a.width,height:a.height,top:a.top,left:a.left,transform:Ns.Transform.toString(f),transformOrigin:r&&s?FN(s,a):void 0,transition:typeof d=="function"?d(s):d,...l};return pe.createElement(n,{className:o,style:h,ref:e},i)}),Y2=t=>e=>{let{active:n,dragOverlay:s}=e;const r={},{styles:i,className:o}=t;if(i!=null&&i.active)for(const[a,l]of Object.entries(i.active))l!==void 0&&(r[a]=n.node.style.getPropertyValue(a),n.node.style.setProperty(a,l));if(i!=null&&i.dragOverlay)for(const[a,l]of Object.entries(i.dragOverlay))l!==void 0&&s.node.style.setProperty(a,l);return o!=null&&o.active&&n.node.classList.add(o.active),o!=null&&o.dragOverlay&&s.node.classList.add(o.dragOverlay),function(){for(const[l,c]of Object.entries(r))n.node.style.setProperty(l,c);o!=null&&o.active&&n.node.classList.remove(o.active)}},X2=t=>{let{transform:{initial:e,final:n}}=t;return[{transform:Ns.Transform.toString(e)},{transform:Ns.Transform.toString(n)}]},q2={duration:250,easing:"ease",keyframes:X2,sideEffects:Y2({styles:{active:{opacity:"0"}}})};function G2(t){let{config:e,draggableNodes:n,droppableContainers:s,measuringConfiguration:r}=t;return Cc((i,o)=>{if(e===null)return;const a=n.get(i);if(!a)return;const l=a.node.current;if(!l)return;const c=bv(o);if(!c)return;const{transform:d}=st(o).getComputedStyle(o),f=cv(d);if(!f)return;const h=typeof e=="function"?e:J2(e);return mv(l,r.draggable.measure),h({active:{id:i,data:a.data,node:l,rect:r.draggable.measure(l)},draggableNodes:n,dragOverlay:{node:o,rect:r.dragOverlay.measure(c)},droppableContainers:s,measuringConfiguration:r,transform:f})})}function J2(t){const{duration:e,easing:n,sideEffects:s,keyframes:r}={...q2,...t};return i=>{let{active:o,dragOverlay:a,transform:l,...c}=i;if(!e)return;const d={x:a.rect.left-o.rect.left,y:a.rect.top-o.rect.top},f={scaleX:l.scaleX!==1?o.rect.width*l.scaleX/a.rect.width:1,scaleY:l.scaleY!==1?o.rect.height*l.scaleY/a.rect.height:1},h={x:l.x-d.x,y:l.y-d.y,...f},p=r({...c,active:o,dragOverlay:a,transform:{initial:l,final:h}}),[m]=p,g=p[p.length-1];if(JSON.stringify(m)===JSON.stringify(g))return;const b=s==null?void 0:s({active:o,dragOverlay:a,...c}),y=a.node.animate(p,{duration:e,easing:n,fill:"forwards"});return new Promise(x=>{y.onfinish=()=>{b==null||b(),x()}})}}let ym=0;function Z2(t){return S.useMemo(()=>{if(t!=null)return ym++,ym},[t])}const eE=pe.memo(t=>{let{adjustScale:e=!1,children:n,dropAnimation:s,style:r,transition:i,modifiers:o,wrapperElement:a="div",className:l,zIndex:c=999}=t;const{activatorEvent:d,active:f,activeNodeRect:h,containerNodeRect:p,draggableNodes:m,droppableContainers:g,dragOverlay:b,over:y,measuringConfiguration:x,scrollableAncestors:v,scrollableAncestorRects:_,windowRect:w}=kv(),k=S.useContext(Ec),C=Z2(f==null?void 0:f.id),j=_v(o,{activatorEvent:d,active:f,activeNodeRect:h,containerNodeRect:p,draggingNodeRect:b.rect,over:y,overlayNodeRect:b.rect,scrollableAncestors:v,scrollableAncestorRects:_,transform:k,windowRect:w}),M=fh(h),E=G2({config:s,draggableNodes:m,droppableContainers:g,measuringConfiguration:x}),P=M?b.setRef:void 0;return pe.createElement(H2,null,pe.createElement(U2,{animation:E},f&&C?pe.createElement(K2,{key:C,id:f.id,ref:P,as:a,activatorEvent:d,adjustScale:e,className:l,transition:i,rect:M,style:{zIndex:c,...r},transform:j},n):null))});function jv(t,e,n){const s=t.slice();return s.splice(n<0?s.length+n:n,0,s.splice(e,1)[0]),s}function tE(t,e){return t.reduce((n,s,r)=>{const i=e.get(s);return i&&(n[r]=i),n},Array(t.length))}function Wa(t){return t!==null&&t>=0}function nE(t,e){if(t===e)return!0;if(t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(t[n]!==e[n])return!1;return!0}function sE(t){return typeof t=="boolean"?{draggable:t,droppable:t}:t}const Nv=t=>{let{rects:e,activeIndex:n,overIndex:s,index:r}=t;const i=jv(e,s,n),o=e[r],a=i[r];return!a||!o?null:{x:a.left-o.left,y:a.top-o.top,scaleX:a.width/o.width,scaleY:a.height/o.height}},Ha={scaleX:1,scaleY:1},rE=t=>{var e;let{activeIndex:n,activeNodeRect:s,index:r,rects:i,overIndex:o}=t;const a=(e=i[n])!=null?e:s;if(!a)return null;if(r===n){const c=i[o];return c?{x:0,y:n<o?c.top+c.height-(a.top+a.height):c.top-a.top,...Ha}:null}const l=iE(i,r,n);return r>n&&r<=o?{x:0,y:-a.height-l,...Ha}:r<n&&r>=o?{x:0,y:a.height+l,...Ha}:{x:0,y:0,...Ha}};function iE(t,e,n){const s=t[e],r=t[e-1],i=t[e+1];return s?n<e?r?s.top-(r.top+r.height):i?i.top-(s.top+s.height):0:i?i.top-(s.top+s.height):r?s.top-(r.top+r.height):0:0}const Ev="Sortable",Mv=pe.createContext({activeIndex:-1,containerId:Ev,disableTransforms:!1,items:[],overIndex:-1,useDragOverlay:!1,sortedRects:[],strategy:Nv,disabled:{draggable:!1,droppable:!1}});function oE(t){let{children:e,id:n,items:s,strategy:r=Nv,disabled:i=!1}=t;const{active:o,dragOverlay:a,droppableRects:l,over:c,measureDroppableContainers:d}=kv(),f=aa(Ev,n),h=a.rect!==null,p=S.useMemo(()=>s.map(k=>typeof k=="object"&&"id"in k?k.id:k),[s]),m=o!=null,g=o?p.indexOf(o.id):-1,b=c?p.indexOf(c.id):-1,y=S.useRef(p),x=!nE(p,y.current),v=b!==-1&&g===-1||x,_=sE(i);Jt(()=>{x&&m&&d(p)},[x,p,m,d]),S.useEffect(()=>{y.current=p},[p]);const w=S.useMemo(()=>({activeIndex:g,containerId:f,disabled:_,disableTransforms:v,items:p,overIndex:b,useDragOverlay:h,sortedRects:tE(p,l),strategy:r}),[g,f,_.draggable,_.droppable,v,p,b,l,h,r]);return pe.createElement(Mv.Provider,{value:w},e)}const aE=t=>{let{id:e,items:n,activeIndex:s,overIndex:r}=t;return jv(n,s,r).indexOf(e)},lE=t=>{let{containerId:e,isSorting:n,wasDragging:s,index:r,items:i,newIndex:o,previousItems:a,previousContainerId:l,transition:c}=t;return!c||!s||a!==i&&r===o?!1:n?!0:o!==r&&e===l},cE={duration:200,easing:"ease"},Pv="transform",uE=Ns.Transition.toString({property:Pv,duration:0,easing:"linear"}),dE={roleDescription:"sortable"};function fE(t){let{disabled:e,index:n,node:s,rect:r}=t;const[i,o]=S.useState(null),a=S.useRef(n);return Jt(()=>{if(!e&&n!==a.current&&s.current){const l=r.current;if(l){const c=Ci(s.current,{ignoreTransform:!0}),d={x:l.left-c.left,y:l.top-c.top,scaleX:l.width/c.width,scaleY:l.height/c.height};(d.x||d.y)&&o(d)}}n!==a.current&&(a.current=n)},[e,n,s,r]),S.useEffect(()=>{i&&o(null)},[i]),i}function hE(t){let{animateLayoutChanges:e=lE,attributes:n,disabled:s,data:r,getNewIndex:i=aE,id:o,strategy:a,resizeObserverConfig:l,transition:c=cE}=t;const{items:d,containerId:f,activeIndex:h,disabled:p,disableTransforms:m,sortedRects:g,overIndex:b,useDragOverlay:y,strategy:x}=S.useContext(Mv),v=pE(s,p),_=d.indexOf(o),w=S.useMemo(()=>({sortable:{containerId:f,index:_,items:d},...r}),[f,r,_,d]),k=S.useMemo(()=>d.slice(d.indexOf(o)),[d,o]),{rect:C,node:j,isOver:M,setNodeRef:E}=Cv({id:o,data:w,disabled:v.droppable,resizeObserverConfig:{updateMeasurementsFor:k,...l}}),{active:P,activatorEvent:A,activeNodeRect:Q,attributes:ne,setNodeRef:Y,listeners:oe,isDragging:G,over:O,setActivatorNodeRef:L,transform:I}=z2({id:o,data:w,attributes:{...dE,...n},disabled:v.draggable}),V=wN(E,Y),F=!!P,ce=F&&!m&&Wa(h)&&Wa(b),$=!y&&G,ke=$&&ce?I:null,gt=ce?ke??(a??x)({rects:g,activeNodeRect:Q,activeIndex:h,overIndex:b,index:_}):null,Ft=Wa(h)&&Wa(b)?i({id:o,items:d,activeIndex:h,overIndex:b}):_,zt=P==null?void 0:P.id,ie=S.useRef({activeId:zt,items:d,newIndex:Ft,containerId:f}),ji=d!==ie.current.items,tn=e({active:P,containerId:f,isDragging:G,isSorting:F,id:o,index:_,items:d,newIndex:ie.current.newIndex,previousItems:ie.current.items,previousContainerId:ie.current.containerId,transition:c,wasDragging:ie.current.activeId!=null}),pr=fE({disabled:!tn,index:_,node:j,rect:C});return S.useEffect(()=>{F&&ie.current.newIndex!==Ft&&(ie.current.newIndex=Ft),f!==ie.current.containerId&&(ie.current.containerId=f),d!==ie.current.items&&(ie.current.items=d)},[F,Ft,f,d]),S.useEffect(()=>{if(zt===ie.current.activeId)return;if(zt!=null&&ie.current.activeId==null){ie.current.activeId=zt;return}const gr=setTimeout(()=>{ie.current.activeId=zt},50);return()=>clearTimeout(gr)},[zt]),{active:P,activeIndex:h,attributes:ne,data:w,rect:C,index:_,newIndex:Ft,items:d,isOver:M,isSorting:F,isDragging:G,listeners:oe,node:j,overIndex:b,over:O,setNodeRef:V,setActivatorNodeRef:L,setDroppableNodeRef:E,setDraggableNodeRef:Y,transform:pr??gt,transition:vn()};function vn(){if(pr||ji&&ie.current.newIndex===_)return uE;if(!($&&!jc(A)||!c)&&(F||tn))return Ns.Transition.toString({...c,property:Pv})}}function pE(t,e){var n,s;return typeof t=="boolean"?{draggable:t,droppable:!1}:{draggable:(n=t==null?void 0:t.draggable)!=null?n:e.draggable,droppable:(s=t==null?void 0:t.droppable)!=null?s:e.droppable}}se.Down,se.Right,se.Up,se.Left;function Rv({lead:t,onAbrir:e,emOverlay:n=!1}){const{attributes:s,listeners:r,setNodeRef:i,transform:o,transition:a,isDragging:l}=hE({id:t.id});return u.jsxs("div",{ref:i,...r,...s,style:{transform:Ns.Transform.toString(o),transition:a,opacity:l?.5:1},className:H("bg-white rounded-lg shadow-sm border border-gray-100 p-3 cursor-grab active:cursor-grabbing select-none touch-none",n&&"shadow-xl rotate-2 cursor-grabbing"),onDoubleClick:()=>e==null?void 0:e(t),title:"Arraste para mudar de coluna · duplo clique para editar",children:[u.jsx("p",{className:"text-sm font-semibold text-gray-800 truncate",children:t.nome}),u.jsx("p",{className:"text-xs text-gray-500 mt-0.5",children:na(t.telefone)}),u.jsxs("div",{className:"flex items-center justify-between mt-2",children:[u.jsx("span",{className:"text-[10px] uppercase tracking-wide bg-indigo-50 text-indigo-700 px-1.5 py-0.5 rounded font-medium",children:t.fonte}),u.jsx("span",{className:"text-[10px] text-gray-400",title:"Data de criação",children:new Date(t.criado_em).toLocaleDateString("pt-BR")})]})]})}function gE({etapa:t,leads:e,cor:n,onAbrirLead:s}){const{setNodeRef:r,isOver:i}=Cv({id:t});return u.jsxs("div",{className:"w-72 shrink-0",children:[u.jsxs("div",{className:"flex items-center justify-between px-1 pb-2",children:[u.jsxs("span",{className:"flex items-center gap-2 text-sm font-semibold text-gray-700",children:[u.jsx("span",{className:H("w-2.5 h-2.5 rounded-full",n)}),mn[t]]}),u.jsx("span",{className:"text-xs font-medium text-gray-500 bg-white border border-gray-200 rounded-full px-2 py-0.5 shadow-sm",children:e.length})]}),u.jsx("div",{ref:r,className:H("bg-white rounded-xl p-3 min-h-[420px] transition-colors","shadow-sm border",i?"border-2 border-dashed border-indigo-400 bg-indigo-50":"border-gray-100"),children:u.jsx(oE,{items:e.map(o=>o.id),strategy:rE,children:u.jsxs("div",{className:"space-y-2 max-h-[calc(100vh-320px)] overflow-y-auto pr-0.5",children:[e.length===0&&u.jsxs("div",{className:"text-center text-xs text-gray-400 border-2 border-dashed border-gray-200 rounded-lg py-10 mt-8",children:[u.jsx("i",{className:"fas fa-inbox text-2xl text-gray-300 mb-2 block"}),"Arraste leads para cá"]}),e.map(o=>u.jsx(Rv,{lead:o,onAbrir:s},o.id))]})})})]})}const mE={leads:"bg-blue-500",em_contato:"bg-amber-500",proposta:"bg-violet-500",fechado:"bg-green-500"};function Hi(t,e){if(pt.includes(e))return e;for(const n of pt)if((t[n]||[]).includes(e))return n;return null}function xE({leads:t,onMover:e,onAbrirLead:n}){const[s,r]=S.useState(()=>yE(t)),[i,o]=S.useState(null),a=S.useRef(s),l=AN(LN(dh,{activationConstraint:{distance:6}}));S.useEffect(()=>{r(m=>{const g=new Set(t.map(v=>v.id)),b={};for(const v of pt)b[v]=(m[v]||[]).filter(_=>g.has(_));let y=!1;for(const v of t){const _=Hi(b,v.id);_===null?(b[v.etapa]=[...b[v.etapa]||[],v.id],y=!0):_!==v.etapa&&(b[_]=b[_].filter(w=>w!==v.id),b[v.etapa]=[...b[v.etapa]||[],v.id],y=!0)}const x=pt.every(v=>(b[v]||[]).length===(m[v]||[]).length);return y||!x?b:m})},[t]);const c=S.useCallback(m=>m&&t.find(g=>g.id===m)||null,[t]),d=S.useMemo(()=>c(i),[c,i]),f=m=>{a.current=s,o(String(m.active.id))},h=S.useCallback(m=>{const{active:g,over:b}=m;if(!b)return;const y=String(g.id),x=String(b.id);r(v=>{const _=Hi(v,y),w=Hi(v,x);return!_||!w||_===w?v:{...v,[_]:v[_].filter(k=>k!==y),[w]:[...v[w],y]}})},[]),p=async m=>{o(null);const g=String(m.active.id);if(!m.over){r(a.current);return}const b=Hi(s,String(m.over.id)),y=Hi(a.current,g);!b||!y||b===y||await e(g,b)};return u.jsxs(A2,{sensors:l,collisionDetection:UN,onDragStart:f,onDragOver:h,onDragEnd:p,children:[u.jsx("div",{className:"flex gap-4 overflow-x-auto pb-2",children:pt.map(m=>u.jsx(gE,{etapa:m,cor:mE[m],leads:t.filter(g=>{var b;return(b=s[m])==null?void 0:b.includes(g.id)}),onAbrirLead:n},m))}),u.jsx(eE,{children:d?u.jsx(Rv,{lead:d,emOverlay:!0}):null})]})}function yE(t){const e={leads:[],em_contato:[],proposta:[],fechado:[]};for(const n of t)e[n.etapa]&&e[n.etapa].push(n.id);return e}const vm={nome:"",telefone:"",email:"",fonte:"Manual",etapa:"leads"};function vE(){const{toast:t}=en(),[e,n]=S.useState([]),[s,r]=S.useState(null),[i,o]=S.useState(!1),[a,l]=S.useState(!1),[c,d]=S.useState(null),[f,h]=S.useState({...vm}),[p,m]=S.useState(""),g=S.useCallback(async()=>{n(await W.crm.leadsListar())},[]);S.useEffect(()=>{g().catch(C=>t("erro",C.message))},[g,t]);const b=async(C,j)=>{const M=e;n(E=>E.map(P=>P.id===C?{...P,etapa:j}:P));try{await W.crm.moverLead(C,j),t("sucesso",`Lead movido para "${mn[j]}".`)}catch(E){n(M),t("erro",E instanceof Error?E.message:"Falha ao mover lead.")}},y=async()=>{var C;if(!((C=f.nome)!=null&&C.trim())){t("erro","O nome do lead é obrigatório.");return}try{await W.crm.criarLead({...f,etapa:f.etapa||"leads"}),t("sucesso","Lead criado com sucesso."),l(!1),h({...vm}),await g()}catch(j){t("erro",j instanceof Error?j.message:"Falha ao criar lead.")}},x=async()=>{o(!0);try{const C=await W.crm.sugestoes();r(C.sugestoes)}catch(C){t("erro",C instanceof Error?C.message:"Falha ao pedir sugestões.")}finally{o(!1)}},v=async C=>{try{await W.crm.aplicar(C.lead_id,C.para),r(j=>(j==null?void 0:j.filter(M=>M!==C))??null),await g(),t("sucesso",`Sugestão aplicada: ${C.lead_nome} → ${mn[C.para]}.`)}catch(j){t("erro",j instanceof Error?j.message:"Falha ao aplicar sugestão.")}},_=async C=>{try{(await W.leads.enriquecer(C.id)).notas.forEach(M=>t("info",M)),await g()}catch(j){t("erro",j instanceof Error?j.message:"Falha ao enriquecer.")}},w=async()=>{if(c)try{await W.leads.atualizar(c.id,{observacoes:p}),d(null),await g(),t("sucesso","Observações salvas.")}catch(C){t("erro",C instanceof Error?C.message:"Falha ao salvar.")}},k=S.useMemo(()=>Object.fromEntries(pt.map(C=>[C,e.filter(j=>j.etapa===C).length])),[e]);return u.jsxs("div",{className:"space-y-6",children:[u.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-3",children:[u.jsxs("div",{className:"flex items-center gap-4 text-sm text-gray-500 flex-wrap",children:[u.jsxs("span",{children:[u.jsx("strong",{className:"text-gray-800",children:e.length})," leads no funil"]}),pt.map(C=>u.jsxs("span",{className:"hidden md:inline",children:[mn[C],": ",u.jsx("strong",{className:"text-gray-700",children:k[C]})]},C))]}),u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsxs("button",{onClick:x,disabled:i,className:"px-5 py-2.5 text-sm font-medium text-indigo-600 bg-white border border-indigo-200 rounded-lg hover:bg-indigo-50 transition disabled:opacity-60 shadow-sm",children:[u.jsx("i",{className:H("fas fa-wand-magic-sparkles mr-2",i&&"fa-spin")}),"Sugestões da IA"]}),u.jsxs("button",{onClick:()=>l(!0),className:"px-6 py-2.5 text-sm font-medium text-white bg-gradient-to-r from-indigo-500 to-purple-500 rounded-lg hover:opacity-90 transition shadow-sm",children:[u.jsx("i",{className:"fas fa-plus mr-2"})," Adicionar Lead"]})]})]}),u.jsx(xE,{leads:e,onMover:b,onAbrirLead:C=>{d(C),m(C.observacoes||"")}}),u.jsxs(Xt,{aberto:s!==null,onFechar:()=>r(null),titulo:"Sugestões de movimentação (Agente de CRM)",icone:"fas fa-robot",largura:"lg",children:[s&&s.length===0&&u.jsxs("p",{className:"text-sm text-gray-500 text-center py-8",children:[u.jsx("i",{className:"fas fa-circle-check text-green-500 text-2xl block mb-3"}),"Nenhuma sugestão no momento — o funil está equilibrado. 🎯"]}),u.jsx("div",{className:"space-y-3",children:s==null?void 0:s.map((C,j)=>u.jsxs("div",{className:"border border-gray-100 rounded-xl p-4 flex items-start justify-between gap-4 hover:border-indigo-200 transition",children:[u.jsxs("div",{className:"min-w-0",children:[u.jsx("p",{className:"text-sm font-semibold text-gray-800 truncate",children:C.lead_nome}),u.jsxs("p",{className:"text-xs text-gray-500 mt-1 flex items-center gap-2",children:[u.jsx(sr,{status:C.de})," ",u.jsx("i",{className:"fas fa-arrow-right text-gray-300"})," ",u.jsx(sr,{status:C.para}),u.jsxs("span",{className:"text-gray-400",children:["confiança ",Math.round(C.confianca*100),"%"]})]}),u.jsx("p",{className:"text-xs text-gray-600 mt-2",children:C.motivo})]}),u.jsx("button",{onClick:()=>v(C),className:"shrink-0 px-4 py-2 text-xs font-medium text-white bg-gradient-to-r from-indigo-500 to-purple-500 rounded-lg hover:opacity-90",children:"Aplicar"})]},j))})]}),u.jsx(Xt,{aberto:a,onFechar:()=>l(!1),titulo:"Adicionar Lead",icone:"fas fa-user-plus",children:u.jsxs("div",{className:"space-y-4",children:[u.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[u.jsx(_r,{rotulo:"Nome *",valor:f.nome||"",onChange:C=>h({...f,nome:C})}),u.jsx(_r,{rotulo:"Telefone",valor:f.telefone||"",onChange:C=>h({...f,telefone:C}),placeholder:"(11) 99999-9999"}),u.jsx(_r,{rotulo:"E-mail",tipo:"email",valor:f.email||"",onChange:C=>h({...f,email:C}),placeholder:"contato@empresa.com.br"}),u.jsxs("div",{children:[u.jsx("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"Coluna inicial"}),u.jsx("select",{value:f.etapa||"leads",onChange:C=>h({...f,etapa:C.target.value}),className:"w-full px-3 py-2 text-sm border border-gray-200 rounded-lg focus:ring-2 focus:ring-indigo-400 outline-none",children:pt.map(C=>u.jsx("option",{value:C,children:mn[C]},C))})]})]}),u.jsx(_r,{rotulo:"Fonte",valor:f.fonte||"",onChange:C=>h({...f,fonte:C}),placeholder:"Manual, Google Maps, Instagram, CNPJ..."}),u.jsxs(Qt,{titulo:"Campos avançados",icone:"fas fa-sliders",children:[u.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[u.jsx(_r,{rotulo:"Empresa",valor:f.empresa||"",onChange:C=>h({...f,empresa:C})}),u.jsx(_r,{rotulo:"Cidade",valor:f.cidade||"",onChange:C=>h({...f,cidade:C}),placeholder:"São Paulo/SP"})]}),u.jsxs("div",{children:[u.jsx("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"Observações"}),u.jsx("textarea",{value:f.observacoes||"",onChange:C=>h({...f,observacoes:C.target.value}),rows:3,className:"w-full px-3 py-2 text-sm border border-gray-200 rounded-lg focus:ring-2 focus:ring-indigo-400 outline-none"})]})]}),u.jsxs("div",{className:"flex justify-end gap-3 pt-2",children:[u.jsx("button",{onClick:()=>l(!1),className:"px-4 py-2.5 text-sm font-medium text-gray-600 bg-white border border-gray-200 rounded-lg hover:bg-gray-50",children:"Cancelar"}),u.jsxs("button",{onClick:y,className:"px-6 py-2.5 text-sm font-medium text-white bg-gradient-to-r from-indigo-500 to-purple-500 rounded-lg hover:opacity-90",children:[u.jsx("i",{className:"fas fa-save mr-2"})," Salvar"]})]})]})}),u.jsx(Xt,{aberto:!!c,onFechar:()=>d(null),titulo:"Lead",icone:"fas fa-address-card",children:c&&u.jsxs("div",{className:"space-y-4",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx("p",{className:"text-base font-semibold text-gray-800",children:c.nome}),u.jsxs("p",{className:"text-xs text-gray-500 mt-0.5",children:[na(c.telefone)," · ",c.fonte," · criado em ",Il(c.criado_em)]})]}),u.jsx(sr,{status:c.etapa})]}),u.jsxs("div",{children:[u.jsx("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"Observações"}),u.jsx("textarea",{value:p,onChange:C=>m(C.target.value),rows:4,className:"w-full px-3 py-2 text-sm border border-gray-200 rounded-lg focus:ring-2 focus:ring-indigo-400 outline-none",placeholder:"Ex.: ligou pedindo proposta, retorna na sexta..."})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("button",{onClick:()=>_(c),className:"text-sm text-indigo-600 hover:text-indigo-800 font-medium",children:[u.jsx("i",{className:"fas fa-wand-magic-sparkles mr-1"})," Enriquecer com IA"]}),u.jsxs("div",{className:"flex gap-3",children:[u.jsx("button",{onClick:()=>d(null),className:"px-4 py-2.5 text-sm font-medium text-gray-600 bg-white border border-gray-200 rounded-lg hover:bg-gray-50",children:"Cancelar"}),u.jsxs("button",{onClick:w,className:"px-6 py-2.5 text-sm font-medium text-white bg-gradient-to-r from-indigo-500 to-purple-500 rounded-lg hover:opacity-90",children:[u.jsx("i",{className:"fas fa-save mr-2"})," Salvar"]})]})]})]})})]})}function _r({rotulo:t,valor:e,onChange:n,tipo:s="text",placeholder:r}){return u.jsxs("div",{children:[u.jsx("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:t}),u.jsx("input",{type:s,value:e,onChange:i=>n(i.target.value),placeholder:r,className:"w-full px-3 py-2 text-sm border border-gray-200 rounded-lg focus:ring-2 focus:ring-indigo-400 outline-none"})]})}function bE(){const{toast:t}=en(),[e,n]=S.useState([]),[s,r]=S.useState(!1),[i,o]=S.useState(null),[a,l]=S.useState(""),[c,d]=S.useState(""),[f,h]=S.useState("texto"),[p,m]=S.useState("leads"),g=S.useCallback(async()=>{n(await W.leads.listar())},[]);S.useEffect(()=>{g().catch(w=>t("erro",w.message))},[g,t]);const{data:b=[],refetch:y}=ey({queryKey:["campanhas"],queryFn:()=>W.campanhas.listar(),refetchInterval:w=>{var k;return(k=w.state.data)!=null&&k.some(C=>C.status==="em_andamento")?4e3:!1},refetchIntervalInBackground:!1}),x=S.useMemo(()=>Object.fromEntries(pt.map(w=>[w,e.filter(k=>k.etapa===w).length])),[e]),v=async()=>{if(!a.trim()){t("erro","Dê um nome para a campanha.");return}if(!c.trim()){t("erro","Escreva o template da mensagem.");return}try{await W.campanhas.criar({nome:a.trim(),canal:f,template:f,mensagem:c.trim(),lead_ids:[],filtro_etapa:p});const w=mn[p]??p;t("sucesso",`Campanha criada — ${x[p]??0} leads de "${w}" serão disparados.`),r(!1),l(""),d(""),await y(),await g()}catch(w){t("erro",w instanceof Error?w.message:"Falha ao criar campanha.")}},_=async(w,k)=>{try{await W.campanhas.status(w.id,k),t("sucesso",`Campanha "${w.nome}" → ${k==="ativa"?"Ativa":k==="pausada"?"Pausada":"Rascunho"}.`),await y()}catch(C){t("erro",C instanceof Error?C.message:"Falha ao alterar status.")}};return u.jsxs("div",{className:"space-y-6",children:[u.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-3",children:[u.jsxs("p",{className:"text-sm text-gray-500",children:[u.jsx("strong",{className:"text-gray-800",children:b.length})," campanhas · templates em Agentes"]}),u.jsxs("button",{onClick:()=>r(!0),className:"px-6 py-3 text-sm font-medium text-white bg-gradient-to-r from-indigo-500 to-purple-500 rounded-lg hover:opacity-90 transition shadow-sm",children:[u.jsx("i",{className:"fas fa-plus mr-2"})," Nova Campanha"]})]}),u.jsx("div",{className:"bg-white rounded-xl shadow-sm border border-gray-100 overflow-hidden",children:u.jsx("div",{className:"overflow-x-auto",children:u.jsxs("table",{className:"w-full text-sm",children:[u.jsx("thead",{children:u.jsxs("tr",{className:"text-left text-xs text-gray-500 uppercase border-b border-gray-100 bg-gray-50/50",children:[u.jsx("th",{className:"px-5 py-3 font-semibold",children:"Nome"}),u.jsx("th",{className:"px-5 py-3 font-semibold",children:"Status"}),u.jsx("th",{className:"px-5 py-3 font-semibold",children:"Total de Leads"}),u.jsx("th",{className:"px-5 py-3 font-semibold",children:"Data de Criação"}),u.jsx("th",{className:"px-5 py-3 font-semibold text-right",children:"Ações"})]})}),u.jsxs("tbody",{children:[b.map(w=>{const k=w.status==="em_andamento",C=Math.max(w.total,w.enviadas+w.erros);return u.jsxs("tr",{className:"border-b border-gray-50 hover:bg-indigo-50/40",children:[u.jsxs("td",{className:"px-5 py-3",children:[u.jsx("p",{className:"font-medium text-gray-800 truncate max-w-[220px]",children:w.nome}),u.jsxs("p",{className:"text-xs text-gray-400",children:[w.canal==="audio"?"Áudio":"Texto",' · template "',w.template,'"']})]}),u.jsx("td",{className:"px-5 py-3",children:u.jsx(sr,{status:w.status})}),u.jsx("td",{className:"px-5 py-3 text-gray-600",children:C}),u.jsx("td",{className:"px-5 py-3 text-xs text-gray-400",children:Il(w.criado_em)}),u.jsxs("td",{className:"px-5 py-3 text-right whitespace-nowrap",children:[u.jsxs("button",{onClick:()=>o(w),className:"text-xs text-indigo-600 hover:text-indigo-800 font-medium mr-3",children:[u.jsx("i",{className:"fas fa-list mr-1"})," Ver"]}),k?u.jsxs(u.Fragment,{children:[u.jsxs("button",{onClick:()=>_(w,"pausada"),className:"px-4 py-2 text-xs font-medium text-amber-700 bg-amber-50 border border-amber-200 rounded-lg hover:bg-amber-100 mr-2",children:[u.jsx("i",{className:"fas fa-pause mr-1"})," Pausar"]}),u.jsxs("button",{onClick:()=>_(w,"rascunho"),className:"px-4 py-2 text-xs font-medium text-red-700 bg-red-50 border border-red-200 rounded-lg hover:bg-red-100",children:[u.jsx("i",{className:"fas fa-stop mr-1"})," Parar"]})]}):u.jsxs("button",{onClick:()=>_(w,"ativa"),className:"px-5 py-2 text-xs font-medium text-white bg-gradient-to-r from-indigo-500 to-purple-500 rounded-lg hover:opacity-90",children:[u.jsx("i",{className:"fas fa-play mr-1"})," Iniciar"]})]})]},w.id)}),b.length===0&&u.jsx("tr",{children:u.jsxs("td",{colSpan:5,className:"px-5 py-16 text-center text-gray-400",children:[u.jsx("i",{className:"fas fa-bullhorn text-3xl text-gray-200 block mb-3"}),"Nenhuma campanha ainda. Clique em ",u.jsx("strong",{className:"text-indigo-500",children:"Nova Campanha"})," para começar."]})})]})]})})}),b.filter(w=>w.status==="em_andamento").length>0&&u.jsx("div",{className:"space-y-3",children:b.filter(w=>w.status==="em_andamento").map(w=>{const k=Math.max(w.total,w.enviadas+w.erros),C=k?Math.round((w.enviadas+w.erros)/k*100):0;return u.jsxs("div",{className:"bg-white rounded-xl shadow-sm border border-indigo-100 p-4 space-y-2",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("p",{className:"text-sm font-medium text-gray-700 flex items-center gap-2",children:[u.jsx("i",{className:"fas fa-spinner fa-spin text-indigo-500"})," ",w.nome]}),u.jsxs("span",{className:"text-xs text-gray-500",children:[w.enviadas," enviadas · ",w.erros," erros"]})]}),u.jsx(ra,{valor:C,mostrarLabel:!0})]},w.id)})}),u.jsx(Xt,{aberto:s,onFechar:()=>r(!1),titulo:"Nova Campanha",icone:"fas fa-bullhorn",largura:"lg",children:u.jsxs("div",{className:"space-y-4",children:[u.jsxs("div",{children:[u.jsx("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"Nome da Campanha *"}),u.jsx("input",{value:a,onChange:w=>l(w.target.value),placeholder:"Ex.: Reativação de novos leads",className:"w-full px-3 py-2 text-sm border border-gray-200 rounded-lg focus:ring-2 focus:ring-indigo-400 outline-none"})]}),u.jsxs("div",{children:[u.jsx("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"Template da Mensagem *"}),u.jsx("textarea",{value:c,onChange:w=>d(w.target.value),rows:4,placeholder:"Use variáveis: {{nome}}, {{primeiro_nome}}, {{empresa}}, {{cidade}}...",className:"w-full px-3 py-2 text-sm border border-gray-200 rounded-lg focus:ring-2 focus:ring-indigo-400 outline-none font-mono"}),u.jsxs("p",{className:"text-[11px] text-gray-400 mt-1",children:["Variáveis: ",u.jsx("code",{className:"bg-gray-100 px-1 rounded",children:"{{nome}}"}),","," ",u.jsx("code",{className:"bg-gray-100 px-1 rounded",children:"{{primeiro_nome}}"}),","," ",u.jsx("code",{className:"bg-gray-100 px-1 rounded",children:"{{empresa}}"}),","," ",u.jsx("code",{className:"bg-gray-100 px-1 rounded",children:"{{cidade}}"})]})]}),u.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[u.jsxs("div",{children:[u.jsx("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"Canal"}),u.jsxs("select",{value:f,onChange:w=>h(w.target.value),className:"w-full px-3 py-2 text-sm border border-gray-200 rounded-lg focus:ring-2 focus:ring-indigo-400 outline-none",children:[u.jsx("option",{value:"texto",children:"Texto"}),u.jsx("option",{value:"audio",children:"Áudio"})]})]}),u.jsxs("div",{children:[u.jsx("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"Filtrar Leads por Etapa do CRM"}),u.jsx("select",{value:p,onChange:w=>m(w.target.value),className:"w-full px-3 py-2 text-sm border border-gray-200 rounded-lg focus:ring-2 focus:ring-indigo-400 outline-none",children:pt.map(w=>u.jsxs("option",{value:w,children:[mn[w]," (",x[w]??0," leads)"]},w))})]})]}),u.jsxs("p",{className:"text-xs text-gray-400 bg-gray-50 border border-gray-100 rounded-lg px-3 py-2",children:[u.jsx("i",{className:"fas fa-circle-info mr-1"})," O envio simulado altera o status no JSON. A integração real (OpenOutreach) é validada na hora de iniciar — configure em Ferramentas."]}),u.jsxs("div",{className:"flex justify-end gap-3 pt-1",children:[u.jsx("button",{onClick:()=>r(!1),className:"px-4 py-2.5 text-sm font-medium text-gray-600 bg-white border border-gray-200 rounded-lg hover:bg-gray-50",children:"Cancelar"}),u.jsxs("button",{onClick:v,className:"px-6 py-2.5 text-sm font-medium text-white bg-gradient-to-r from-indigo-500 to-purple-500 rounded-lg hover:opacity-90",children:[u.jsx("i",{className:"fas fa-plus mr-2"})," Criar Campanha"]})]})]})}),u.jsx(Xt,{aberto:!!i,onFechar:()=>o(null),titulo:`Eventos — ${(i==null?void 0:i.nome)??""}`,icone:"fas fa-list",largura:"lg",children:i&&u.jsxs("div",{className:"space-y-2 max-h-96 overflow-y-auto",children:[i.eventos.length===0&&u.jsx("p",{className:"text-sm text-gray-400 text-center py-8",children:"Nenhum evento ainda — a execução do disparo é simulada nesta fase."}),i.eventos.slice().reverse().map((w,k)=>{var C;return u.jsxs("div",{className:"flex items-start gap-3 text-sm border-b border-gray-50 pb-2",children:[u.jsx("i",{className:H("mt-1 text-xs",w.status==="enviado"?"fas fa-circle-check text-green-500":"fas fa-circle-xmark text-red-500")}),u.jsxs("div",{className:"min-w-0 flex-1",children:[u.jsx("p",{className:"text-gray-700 truncate",children:((C=e.find(j=>j.id===w.lead_id))==null?void 0:C.nome)??w.lead_id}),w.mensagem&&u.jsx("p",{className:"text-xs text-gray-400 truncate",children:w.mensagem})]}),u.jsx("span",{className:"text-xs text-gray-300 shrink-0",children:Il(w.momento)})]},k)})]})})]})}const wE=[{para:"/extrator-maps",icone:"fas fa-map-marked-alt",titulo:"Google Maps",descricao:"Empresas por palavra-chave e localização. Sem scraper configurado, gera mock de 5–10 leads."},{para:"/extrator-instagram",icone:"fab fa-instagram",titulo:"Instagram",descricao:"Seguidores de um perfil público. Sem igmapper configurado, gera mock de 5–10 leads."},{para:"/extrator-cnpj",icone:"fas fa-building",titulo:"CNPJ (B2B)",descricao:"Empresas por CNAE + UF. Sem provedor configurado, gera mock de 5–10 empresas."}];function SE(){const t=bi();return u.jsxs("div",{className:"space-y-6",children:[u.jsxs("p",{className:"text-sm text-gray-500",children:["Selecione uma fonte de leads. Todas salvam diretamente em ",u.jsx("strong",{children:"leads.json"}),", na coluna"," ",u.jsx("strong",{children:'"Novos Leads"'})," do CRM — dados 100% locais."]}),u.jsx("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:wE.map(e=>u.jsxs("button",{onClick:()=>t(e.para),className:"bg-white rounded-xl shadow-sm border border-gray-100 p-6 text-left space-y-3 hover:border-indigo-200 hover:shadow-md transition group",children:[u.jsx("span",{className:"w-11 h-11 rounded-lg bg-indigo-50 text-indigo-600 flex items-center justify-center text-lg group-hover:bg-indigo-100",children:u.jsx("i",{className:e.icone})}),u.jsx("p",{className:"text-sm font-semibold text-gray-800",children:e.titulo}),u.jsx("p",{className:"text-xs text-gray-500 leading-relaxed",children:e.descricao}),u.jsxs("span",{className:"text-xs font-medium text-indigo-600 group-hover:text-indigo-800",children:["Abrir extrator ",u.jsx("i",{className:"fas fa-arrow-right ml-1"})]})]},e.para))})]})}function _E(){const{toast:t}=en(),e=bi(),[n,s]=S.useState(""),[r,i]=S.useState(""),[o,a]=S.useState(10),[l,c]=S.useState(5),[d,f]=S.useState(!1),[h,p]=S.useState(!1),[m,g]=S.useState(0),[b,y]=S.useState(null),[x,v]=S.useState(""),_=async()=>{if(n.trim().length<2||r.trim().length<2){t("erro",'Preencha a palavra-chave e a localização (ex.: "Dentista", "Rio de Janeiro").');return}p(!0),y(null),g(8);const w=setInterval(()=>{g(k=>k<85?k+Math.ceil((90-k)/6):85)},90);try{const k=await W.extrair.maps({keyword:n.trim(),location:r.trim(),limit:o});clearInterval(w),g(100),y(k.importados),v(k.origem==="cli"?"scraper real":"mock de teste");const C=k.duplicados>0?` · ${k.duplicados} duplicados ignorados`:"",j=k.aviso?` · ${k.aviso}`:"";t("sucesso",`${k.importados.length} leads extraídos (${k.origem==="cli"?"scraper real":"mock"})${C}${j}`)}catch(k){clearInterval(w),g(0),t("erro",k instanceof Error?k.message:"Falha na extração.")}finally{p(!1)}};return u.jsxs("div",{className:"space-y-6 max-w-4xl",children:[u.jsxs("div",{className:"bg-white rounded-xl shadow-sm border border-gray-100 p-6 space-y-5",children:[u.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-2",children:[u.jsxs("p",{className:"text-sm text-gray-500",children:["Busque empresas por palavra-chave e localização. Sem scraper configurado, o LeadMaster gera",u.jsx("strong",{children:" dados mockados (5–10 leads)"})," para teste — sem risco de bloqueio de IP."]}),u.jsxs("span",{className:"text-xs shrink-0 text-gray-400",children:[u.jsx("i",{className:"fas fa-shield-halved mr-1"})," dados públicos"]})]}),u.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[u.jsxs("div",{children:[u.jsx("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"Palavra-chave *"}),u.jsx("input",{value:n,onChange:w=>s(w.target.value),placeholder:"Ex.: Dentista, pizzaria, academia...",className:"w-full px-3 py-2.5 text-sm border border-gray-200 rounded-lg focus:ring-2 focus:ring-indigo-400 outline-none"})]}),u.jsxs("div",{children:[u.jsx("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"Localização *"}),u.jsx("input",{value:r,onChange:w=>i(w.target.value),placeholder:"Ex.: Rio de Janeiro, RJ",className:"w-full px-3 py-2.5 text-sm border border-gray-200 rounded-lg focus:ring-2 focus:ring-indigo-400 outline-none"})]}),u.jsxs("div",{children:[u.jsxs("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:["Quantidade: ",o]}),u.jsx("input",{type:"range",min:5,max:10,value:o,onChange:w=>a(Number(w.target.value)),className:"w-full accent-indigo-500 mt-2"})]})]}),u.jsxs("button",{onClick:_,disabled:h,className:"w-full md:w-auto px-8 py-3.5 text-sm font-medium text-white bg-gradient-to-r from-indigo-500 to-purple-500 rounded-lg hover:opacity-90 transition disabled:opacity-60 shadow-sm",children:[u.jsx("i",{className:H("fas fa-magnifying-glass mr-2",h&&"fa-spin")}),h?"Buscando leads...":"Iniciar Extração"]}),(h||m>0)&&u.jsxs("div",{className:"space-y-1",children:[u.jsx(ra,{valor:m}),u.jsx("p",{className:"text-xs text-indigo-600 font-medium",children:m<100?"Buscando leads no Google Maps...":"Extração concluída ✓"})]}),u.jsxs(Qt,{titulo:"Configurações avançadas",icone:"fas fa-sliders",children:[u.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[u.jsxs("div",{children:[u.jsxs("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:["Raio de busca: ",l," km"]}),u.jsx("input",{type:"range",min:1,max:50,value:l,onChange:w=>c(Number(w.target.value)),className:"w-full accent-indigo-500"})]}),u.jsxs("label",{className:"flex items-center gap-2 text-sm text-gray-600 bg-gray-50 border border-gray-100 rounded-lg px-3 py-2.5 cursor-pointer h-fit",children:[u.jsx("input",{type:"checkbox",checked:d,onChange:w=>f(w.target.checked),className:"w-4 h-4 accent-indigo-500"}),"Apenas com nota ≥ 4,5"]})]}),u.jsx("p",{className:"text-[11px] text-gray-400",children:"As opções avançadas aplicam-se ao scraper real (gosom/google-maps-scraper), quando configurado em Ferramentas → Extratores. No modo mock elas são ignoradas."})]})]}),b&&u.jsxs("div",{className:"bg-white rounded-xl shadow-sm border border-gray-100 overflow-hidden",children:[u.jsxs("div",{className:"flex items-center justify-between px-5 py-3 border-b border-gray-100 bg-gray-50/50",children:[u.jsxs("p",{className:"text-sm font-medium text-gray-700",children:[b.length," lead(s) extraído(s) · origem: ",u.jsx("span",{className:"text-indigo-600",children:x})]}),u.jsxs("button",{onClick:()=>e("/crm"),className:"px-5 py-2 text-xs font-medium text-indigo-600 bg-white border border-indigo-200 rounded-lg hover:bg-indigo-50",children:[u.jsx("i",{className:"fas fa-columns mr-1"})," Ir para o CRM"]})]}),u.jsx("div",{className:"overflow-x-auto",children:u.jsxs("table",{className:"w-full text-sm",children:[u.jsx("thead",{children:u.jsxs("tr",{className:"text-left text-xs text-gray-500 uppercase border-b border-gray-100",children:[u.jsx("th",{className:"px-5 py-2 font-semibold",children:"Nome"}),u.jsx("th",{className:"px-5 py-2 font-semibold",children:"Telefone"}),u.jsx("th",{className:"px-5 py-2 font-semibold",children:"Localização"}),u.jsx("th",{className:"px-5 py-2 font-semibold",children:"Avaliação"})]})}),u.jsx("tbody",{children:b.map((w,k)=>{var j;const C=(j=w.extras)==null?void 0:j.avaliacao;return u.jsxs("tr",{className:"border-b border-gray-50 hover:bg-indigo-50/40",children:[u.jsx("td",{className:"px-5 py-2.5 text-gray-800",children:w.nome}),u.jsx("td",{className:"px-5 py-2.5 text-gray-600",children:na(w.telefone)}),u.jsxs("td",{className:"px-5 py-2.5 text-gray-500 text-xs",children:[w.cidade||"—",w.endereco?` · ${w.endereco}`:""]}),u.jsx("td",{className:"px-5 py-2.5 text-xs text-gray-400",children:C!==void 0?u.jsxs(u.Fragment,{children:[u.jsx("i",{className:"fas fa-star text-amber-400 mr-1"}),C]}):"—"})]},w.id||k)})})]})}),u.jsx("div",{className:"px-5 py-3 border-t border-gray-100 bg-gray-50/50",children:u.jsxs("button",{onClick:()=>e("/crm"),className:"text-xs text-indigo-600 hover:text-indigo-800 font-medium",children:[u.jsx("i",{className:"fas fa-arrow-right mr-1"})," Ver todos os leads no CRM Kanban"]})})]})]})}function kE(){const{toast:t}=en(),e=bi(),[n,s]=S.useState(""),[r,i]=S.useState(10),[o,a]=S.useState(!1),[l,c]=S.useState(500),[d,f]=S.useState(!1),[h,p]=S.useState(0),[m,g]=S.useState(null),[b,y]=S.useState(""),x=async()=>{if(!n.includes("instagram.com")){t("erro","Informe a URL do perfil (ex.: https://instagram.com/perfil).");return}f(!0),g(null),p(8);const v=setInterval(()=>{p(_=>_<85?_+Math.ceil((90-_)/6):85)},90);try{const _=await W.extrair.instagram(n.trim(),r);clearInterval(v),p(100),g(_.importados),y(_.origem==="cli"?"igmapper real":"mock de teste");const w=_.duplicados>0?` · ${_.duplicados} duplicados ignorados`:"",k=_.aviso?` · ${_.aviso}`:"";t("sucesso",`${_.importados.length} leads extraídos (${_.origem==="cli"?"igmapper real":"mock"})${w}${k}`)}catch(_){clearInterval(v),p(0),t("erro",_ instanceof Error?_.message:"Falha na extração.")}finally{f(!1)}};return u.jsxs("div",{className:"space-y-6 max-w-4xl",children:[u.jsxs("div",{className:"bg-white rounded-xl shadow-sm border border-gray-100 p-6 space-y-5",children:[u.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-2",children:[u.jsxs("p",{className:"text-sm text-gray-500",children:["Extraia seguidores de um perfil público do Instagram. Sem igmapper configurado, o LeadMaster gera",u.jsx("strong",{children:" dados mockados (5–10 leads)"})," para teste — sem risco de bloqueio de conta."]}),u.jsxs("span",{className:"text-xs shrink-0 text-gray-400",children:[u.jsx("i",{className:"fas fa-shield-halved mr-1"})," perfis públicos"]})]}),u.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[u.jsxs("div",{className:"md:col-span-2",children:[u.jsx("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"URL do perfil *"}),u.jsx("input",{value:n,onChange:v=>s(v.target.value),placeholder:"https://instagram.com/perfil_do_concorrente/",className:"w-full px-3 py-2.5 text-sm border border-gray-200 rounded-lg focus:ring-2 focus:ring-indigo-400 outline-none"})]}),u.jsxs("div",{children:[u.jsxs("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:["Quantidade de seguidores: ",r]}),u.jsx("input",{type:"range",min:5,max:10,value:r,onChange:v=>i(Number(v.target.value)),className:"w-full accent-indigo-500 mt-2"})]})]}),u.jsxs("button",{onClick:x,disabled:d,className:"w-full md:w-auto px-8 py-3.5 text-sm font-medium text-white bg-gradient-to-r from-indigo-500 to-purple-500 rounded-lg hover:opacity-90 transition disabled:opacity-60 shadow-sm",children:[u.jsx("i",{className:H("fab fa-instagram mr-2",d&&"fa-spin")}),d?"Buscando seguidores...":"Iniciar Extração"]}),(d||h>0)&&u.jsxs("div",{className:"space-y-1",children:[u.jsx(ra,{valor:h}),u.jsx("p",{className:"text-xs text-indigo-600 font-medium",children:h<100?"Buscando seguidores no Instagram...":"Extração concluída ✓"})]}),u.jsxs(Qt,{titulo:"Configurações avançadas",icone:"fas fa-sliders",children:[u.jsxs("label",{className:"flex items-center gap-2 text-sm text-gray-600 bg-gray-50 border border-gray-100 rounded-lg px-3 py-2.5 cursor-pointer",children:[u.jsx("input",{type:"checkbox",checked:o,onChange:v=>a(v.target.checked),className:"w-4 h-4 accent-indigo-500"}),"Extrair apenas contas comerciais"]}),u.jsxs("div",{children:[u.jsxs("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:["Mínimo de seguidores: ",l]}),u.jsx("input",{type:"range",min:100,max:5e3,step:100,value:l,onChange:v=>c(Number(v.target.value)),className:"w-full accent-indigo-500"})]}),u.jsx("p",{className:"text-[11px] text-gray-400",children:"As opções avançadas aplicam-se ao igmapper real (lucasoal/igmapper), quando configurado em Ferramentas → Extratores. No modo mock elas são ignoradas."})]})]}),m&&u.jsxs("div",{className:"bg-white rounded-xl shadow-sm border border-gray-100 overflow-hidden",children:[u.jsxs("div",{className:"flex items-center justify-between px-5 py-3 border-b border-gray-100 bg-gray-50/50",children:[u.jsxs("p",{className:"text-sm font-medium text-gray-700",children:[m.length," lead(s) extraído(s) · origem: ",u.jsx("span",{className:"text-indigo-600",children:b})]}),u.jsxs("button",{onClick:()=>e("/crm"),className:"px-5 py-2 text-xs font-medium text-indigo-600 bg-white border border-indigo-200 rounded-lg hover:bg-indigo-50",children:[u.jsx("i",{className:"fas fa-columns mr-1"})," Ir para o CRM"]})]}),u.jsx("div",{className:"overflow-x-auto",children:u.jsxs("table",{className:"w-full text-sm",children:[u.jsx("thead",{children:u.jsxs("tr",{className:"text-left text-xs text-gray-500 uppercase border-b border-gray-100",children:[u.jsx("th",{className:"px-5 py-2 font-semibold",children:"Nome / Username"}),u.jsx("th",{className:"px-5 py-2 font-semibold",children:"Telefone"}),u.jsx("th",{className:"px-5 py-2 font-semibold",children:"Fonte"}),u.jsx("th",{className:"px-5 py-2 font-semibold",children:"Seguidores"})]})}),u.jsx("tbody",{children:m.map((v,_)=>{var C,j;const w=((C=v.extras)==null?void 0:C.username)||"",k=(j=v.extras)==null?void 0:j.seguidores;return u.jsxs("tr",{className:"border-b border-gray-50 hover:bg-indigo-50/40",children:[u.jsxs("td",{className:"px-5 py-2.5 text-gray-800",children:[v.nome,w&&u.jsxs("span",{className:"text-xs text-gray-400 ml-2",children:["@",w]})]}),u.jsx("td",{className:"px-5 py-2.5 text-gray-600",children:na(v.telefone)}),u.jsx("td",{className:"px-5 py-2.5",children:u.jsx("span",{className:"text-[10px] uppercase tracking-wide bg-pink-50 text-pink-700 px-1.5 py-0.5 rounded font-medium",children:v.fonte})}),u.jsx("td",{className:"px-5 py-2.5 text-xs text-gray-400",children:k!==void 0?k.toLocaleString("pt-BR"):"—"})]},v.id||_)})})]})}),u.jsx("div",{className:"px-5 py-3 border-t border-gray-100 bg-gray-50/50",children:u.jsxs("button",{onClick:()=>e("/crm"),className:"text-xs text-indigo-600 hover:text-indigo-800 font-medium",children:[u.jsx("i",{className:"fas fa-arrow-right mr-1"})," Ver todos os leads no CRM Kanban"]})})]})]})}const CE=["AC","AL","AP","AM","BA","CE","DF","ES","GO","MA","MT","MS","MG","PA","PB","PR","PE","PI","RJ","RN","RS","RO","RR","SC","SP","SE","TO"];function jE(){const{toast:t}=en(),e=bi(),[n,s]=S.useState(""),[r,i]=S.useState("SP"),[o,a]=S.useState(10),[l,c]=S.useState(""),[d,f]=S.useState(0),[h,p]=S.useState(!1),[m,g]=S.useState(0),[b,y]=S.useState(null),[x,v]=S.useState(""),[_,w]=S.useState(""),[k,C]=S.useState(!1),j=async()=>{if(n.trim().length<2){t("erro","Informe o CNAE (ex.: 6201-5/01 — desenvolvimento de software).");return}p(!0),y(null),g(8);const E=setInterval(()=>{g(P=>P<85?P+Math.ceil((90-P)/6):85)},90);try{const P=await W.extrair.cnpjExtract({cnae:n.trim(),uf:r,limit:o});clearInterval(E),g(100),y(P.importados),v(P.origem==="provedor"?"provedor real":"mock de teste");const A=P.duplicados>0?` · ${P.duplicados} duplicados ignorados`:"",Q=P.aviso?` · ${P.aviso}`:"";t("sucesso",`${P.importados.length} empresas extraídas (${P.origem==="provedor"?"provedor real":"mock"})${A}${Q}`)}catch(P){clearInterval(E),g(0),t("erro",P instanceof Error?P.message:"Falha na extração.")}finally{p(!1)}},M=async()=>{const E=_.trim();if(E.length<8){t("erro","Informe um CNPJ completo (14 dígitos, com ou sem pontuação).");return}C(!0);try{const P=await W.extrair.cnpj(E),A=await W.leads.importar([P]);t("sucesso",`${A.importados.length} lead(s) importado(s) para "Novos Leads"${A.duplicados.length?` · ${A.duplicados.length} duplicado(s)`:""}.`),w("")}catch(P){t("erro",P instanceof Error?P.message:"Falha ao consultar o CNPJ.")}finally{C(!1)}};return u.jsxs("div",{className:"space-y-6 max-w-4xl",children:[u.jsxs("div",{className:"bg-white rounded-xl shadow-sm border border-gray-100 p-6 space-y-5",children:[u.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-2",children:[u.jsxs("p",{className:"text-sm text-gray-500",children:["Busque empresas por CNAE e estado. Sem provedor configurado, o LeadMaster gera",u.jsx("strong",{children:" dados mockados (5–10 empresas)"})," para teste — sem risco de bloqueio."]}),u.jsxs("span",{className:"text-xs shrink-0 text-gray-400",children:[u.jsx("i",{className:"fas fa-shield-halved mr-1"})," dados B2B"]})]}),u.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[u.jsxs("div",{children:[u.jsx("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"CNAE *"}),u.jsx("input",{value:n,onChange:E=>s(E.target.value),placeholder:"Ex.: 6201-5/01 (desenvolvimento de software)",className:"w-full px-3 py-2.5 text-sm border border-gray-200 rounded-lg focus:ring-2 focus:ring-indigo-400 outline-none"})]}),u.jsxs("div",{children:[u.jsx("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"UF *"}),u.jsx("select",{value:r,onChange:E=>i(E.target.value),className:"w-full px-3 py-2.5 text-sm border border-gray-200 rounded-lg focus:ring-2 focus:ring-indigo-400 outline-none bg-white",children:CE.map(E=>u.jsx("option",{value:E,children:E},E))})]}),u.jsxs("div",{children:[u.jsxs("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:["Quantidade: ",o]}),u.jsx("input",{type:"range",min:5,max:10,value:o,onChange:E=>a(Number(E.target.value)),className:"w-full accent-indigo-500 mt-2"})]})]}),u.jsxs("button",{onClick:j,disabled:h,className:"w-full md:w-auto px-8 py-3.5 text-sm font-medium text-white bg-gradient-to-r from-indigo-500 to-purple-500 rounded-lg hover:opacity-90 transition disabled:opacity-60 shadow-sm",children:[u.jsx("i",{className:H("fas fa-building mr-2",h&&"fa-spin")}),h?"Buscando empresas...":"Iniciar Extração"]}),(h||m>0)&&u.jsxs("div",{className:"space-y-1",children:[u.jsx(ra,{valor:m}),u.jsx("p",{className:"text-xs text-indigo-600 font-medium",children:m<100?"Buscando empresas por CNAE...":"Extração concluída ✓"})]}),u.jsxs(Qt,{titulo:"Configurações avançadas",icone:"fas fa-sliders",children:[u.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[u.jsxs("div",{children:[u.jsx("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"Porte da empresa"}),u.jsxs("select",{value:l,onChange:E=>c(E.target.value),className:"w-full px-3 py-2.5 text-sm border border-gray-200 rounded-lg focus:ring-2 focus:ring-indigo-400 outline-none bg-white",children:[u.jsx("option",{value:"",children:"Todos"}),u.jsx("option",{value:"ME",children:"ME (Microempresa)"}),u.jsx("option",{value:"EPP",children:"EPP (Pequeno porte)"}),u.jsx("option",{value:"medio",children:"Médio porte"}),u.jsx("option",{value:"grande",children:"Grande porte"})]})]}),u.jsxs("div",{children:[u.jsxs("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:["Capital social mínimo: ",d.toLocaleString("pt-BR",{style:"currency",currency:"BRL",maximumFractionDigits:0})]}),u.jsx("input",{type:"range",min:0,max:5e6,step:1e5,value:d,onChange:E=>f(Number(E.target.value)),className:"w-full accent-indigo-500"})]})]}),u.jsx("p",{className:"text-[11px] text-gray-400",children:"Os filtros de porte e capital social aplicam-se ao provedor real de busca, quando configurado em Ferramentas → Extratores. No modo mock eles são ignorados."})]}),u.jsxs("div",{className:"pt-1 border-t border-gray-100",children:[u.jsxs("p",{className:"text-xs font-medium text-gray-500 mb-2",children:[u.jsx("i",{className:"fas fa-magnifying-glass mr-1"})," Consulta avulsa por CNPJ (BrasilAPI) — importa uma empresa específica"]}),u.jsxs("div",{className:"flex flex-wrap gap-3",children:[u.jsx("input",{value:_,onChange:E=>w(E.target.value),placeholder:"00.000.000/0000-00",className:"flex-1 min-w-[220px] px-3 py-2.5 text-sm border border-gray-200 rounded-lg focus:ring-2 focus:ring-indigo-400 outline-none"}),u.jsxs("button",{onClick:M,disabled:k,className:"px-5 py-2.5 text-xs font-medium text-indigo-600 bg-white border border-indigo-200 rounded-lg hover:bg-indigo-50 disabled:opacity-60",children:[u.jsx("i",{className:H("fas fa-file-import mr-1",k&&"fa-spin")}),k?"Importando...":"Consultar e importar"]})]})]})]}),b&&u.jsxs("div",{className:"bg-white rounded-xl shadow-sm border border-gray-100 overflow-hidden",children:[u.jsxs("div",{className:"flex items-center justify-between px-5 py-3 border-b border-gray-100 bg-gray-50/50",children:[u.jsxs("p",{className:"text-sm font-medium text-gray-700",children:[b.length," lead(s) extraído(s) · origem: ",u.jsx("span",{className:"text-indigo-600",children:x})]}),u.jsxs("button",{onClick:()=>e("/crm"),className:"px-5 py-2 text-xs font-medium text-indigo-600 bg-white border border-indigo-200 rounded-lg hover:bg-indigo-50",children:[u.jsx("i",{className:"fas fa-columns mr-1"})," Ir para o CRM"]})]}),u.jsx("div",{className:"overflow-x-auto",children:u.jsxs("table",{className:"w-full text-sm",children:[u.jsx("thead",{children:u.jsxs("tr",{className:"text-left text-xs text-gray-500 uppercase border-b border-gray-100",children:[u.jsx("th",{className:"px-5 py-2 font-semibold",children:"Nome Fantasia"}),u.jsx("th",{className:"px-5 py-2 font-semibold",children:"CNPJ"}),u.jsx("th",{className:"px-5 py-2 font-semibold",children:"Cidade / UF"}),u.jsx("th",{className:"px-5 py-2 font-semibold",children:"Telefone"}),u.jsx("th",{className:"px-5 py-2 font-semibold",children:"Fonte"})]})}),u.jsx("tbody",{children:b.map((E,P)=>u.jsxs("tr",{className:"border-b border-gray-50 hover:bg-indigo-50/40",children:[u.jsx("td",{className:"px-5 py-2.5 text-gray-800",children:E.nome}),u.jsx("td",{className:"px-5 py-2.5 text-gray-600 font-mono text-xs",children:E.cnpj||"—"}),u.jsx("td",{className:"px-5 py-2.5 text-gray-500 text-xs",children:E.cidade||"—"}),u.jsx("td",{className:"px-5 py-2.5 text-gray-600",children:na(E.telefone)}),u.jsx("td",{className:"px-5 py-2.5",children:u.jsx("span",{className:"text-[10px] uppercase tracking-wide bg-indigo-50 text-indigo-700 px-1.5 py-0.5 rounded font-medium",children:E.fonte})})]},E.id||P))})]})}),u.jsx("div",{className:"px-5 py-3 border-t border-gray-100 bg-gray-50/50",children:u.jsxs("button",{onClick:()=>e("/crm"),className:"text-xs text-indigo-600 hover:text-indigo-800 font-medium",children:[u.jsx("i",{className:"fas fa-arrow-right mr-1"})," Ver todos os leads no CRM Kanban"]})})]})]})}function NE(){const[t,e]=s_(),n=t.get("tab")||"disparo";return u.jsxs("div",{className:"space-y-6",children:[u.jsx("div",{className:"flex gap-2",children:[{id:"disparo",rotulo:"Agente de Disparo",icone:"fas fa-paper-plane"},{id:"atendimento",rotulo:"Agente de Atendimento",icone:"fas fa-headset"}].map(s=>u.jsxs("button",{onClick:()=>e({tab:s.id}),className:H("px-5 py-2.5 text-sm font-medium rounded-lg transition",n===s.id?"bg-[#1e1b4b] text-white shadow-sm":"bg-white text-gray-600 border border-gray-200 hover:bg-gray-50"),children:[u.jsx("i",{className:H(s.icone,"mr-2")}),s.rotulo]},s.id))}),n==="disparo"?u.jsx(EE,{}):u.jsx(ME,{})]})}function EE(){const{toast:t}=en(),[e,n]=S.useState({texto:"",audio:""}),[s,r]=S.useState("LeadMaster"),[i,o]=S.useState(""),[a,l]=S.useState(!1),[c,d]=S.useState(!1),[f,h]=S.useState(null),p=S.useCallback(async()=>{const[b,y]=await Promise.all([W.agentes.templates(),W.config.obter()]);n({texto:b.texto??"",audio:b.audio??""}),r(y.agentes.disparo.minha_empresa??"LeadMaster"),h(y.integracoes.openoutreach)},[]);S.useEffect(()=>{p().catch(b=>t("erro",b.message))},[p,t]);const m=async()=>{d(!0);try{await W.agentes.salvarTemplates(e),await W.config.salvar({agentes:{disparo:{templates:e,minha_empresa:s}}}),t("sucesso","Templates do agente de disparo salvos."),await p()}catch(b){t("erro",b instanceof Error?b.message:"Falha ao salvar templates.")}finally{d(!1)}},g=async()=>{try{const b=await W.agentes.testarTemplate(e.texto);o(b.renderizado),l(!0)}catch(b){t("erro",b instanceof Error?b.message:"Falha ao renderizar template.")}};return u.jsxs("div",{className:"space-y-5 max-w-3xl",children:[u.jsxs("div",{className:"bg-white rounded-xl shadow-sm border border-gray-100 p-6 space-y-4",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx("h3",{className:"text-sm font-semibold text-gray-800",children:"Templates de mensagem"}),u.jsx(sr,{status:f!=null&&f.url&&f.enabled!==!1?"ativo":"inativo",rotulo:f!=null&&f.url&&f.enabled!==!1?"OpenOutreach configurado":"OpenOutreach não configurado"})]}),u.jsxs("p",{className:"text-xs text-gray-500",children:["Variáveis disponíveis: ",u.jsx("code",{className:"bg-gray-100 px-1 rounded",children:"{{nome}}"}),","," ",u.jsx("code",{className:"bg-gray-100 px-1 rounded",children:"{{primeiro_nome}}"}),","," ",u.jsx("code",{className:"bg-gray-100 px-1 rounded",children:"{{empresa}}"}),","," ",u.jsx("code",{className:"bg-gray-100 px-1 rounded",children:"{{cidade}}"}),","," ",u.jsx("code",{className:"bg-gray-100 px-1 rounded",children:"{{minha_empresa}}"}),"."]}),u.jsxs("div",{children:[u.jsx("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"Template — texto"}),u.jsx("textarea",{value:e.texto,onChange:b=>n({...e,texto:b.target.value}),rows:4,className:"w-full px-3 py-2 text-sm border border-gray-200 rounded-lg focus:ring-2 focus:ring-indigo-400 outline-none"})]}),u.jsxs("div",{children:[u.jsx("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"Template — áudio (texto para gravação)"}),u.jsx("textarea",{value:e.audio,onChange:b=>n({...e,audio:b.target.value}),rows:4,className:"w-full px-3 py-2 text-sm border border-gray-200 rounded-lg focus:ring-2 focus:ring-indigo-400 outline-none"})]}),u.jsxs("div",{children:[u.jsx("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"Nome da sua empresa"}),u.jsx("input",{value:s,onChange:b=>r(b.target.value),className:"w-full max-w-xs px-3 py-2 text-sm border border-gray-200 rounded-lg focus:ring-2 focus:ring-indigo-400 outline-none"})]}),u.jsxs("div",{className:"flex items-center gap-3",children:[u.jsxs("button",{onClick:m,disabled:c,className:"px-6 py-2.5 text-sm font-medium text-white bg-gradient-to-r from-indigo-500 to-purple-500 rounded-lg hover:opacity-90 disabled:opacity-60",children:[u.jsx("i",{className:"fas fa-save mr-2"})," Salvar templates"]}),u.jsxs("button",{onClick:g,className:"px-4 py-2.5 text-sm font-medium text-indigo-600 bg-indigo-50 border border-indigo-200 rounded-lg hover:bg-indigo-100",children:[u.jsx("i",{className:"fas fa-vial mr-2"})," Testar com lead de exemplo"]})]})]}),u.jsxs("div",{className:"bg-white rounded-xl shadow-sm border border-gray-100 p-6 text-sm text-gray-500 space-y-2",children:[u.jsx("p",{className:"font-medium text-gray-700 text-xs uppercase tracking-wide",children:"Como funciona"}),u.jsxs("p",{children:["O envio em massa é executado pelo ",u.jsx("strong",{children:"OpenOutreach"})," (eracle/OpenOutreach). As campanhas ficam na página ",u.jsx("strong",{children:"Disparos"}),"; a validação da integração acontece na hora de iniciar a campanha — sem travas de pré-registro."]})]}),u.jsx(Xt,{aberto:a,onFechar:()=>l(!1),titulo:"Pré-visualização do template",icone:"fas fa-comment-dots",children:u.jsx("div",{className:"bg-gray-50 border border-gray-100 rounded-lg p-4 text-sm text-gray-700 whitespace-pre-wrap",children:i})})]})}function ME(){const{toast:t}=en(),[e,n]=S.useState("texto"),[s,r]=S.useState(""),[i,o]=S.useState([{role:"assistant",content:"Olá! Sou o assistente de atendimento do LeadMaster. Como posso ajudar?"}]),[a,l]=S.useState(""),[c,d]=S.useState(!1),f=S.useCallback(async()=>{const m=await W.config.obter();n(m.agentes.atendimento.modo==="voz"?"voz":"texto"),r(m.integracoes.pipecat.url||"")},[]);S.useEffect(()=>{f().catch(m=>t("erro",m.message))},[f,t]);const h=async m=>{n(m);try{await W.config.salvar({agentes:{atendimento:{modo:m}},integracoes:{pipecat:{url:s}}}),t("sucesso",`Modo de atendimento: ${m==="voz"?"voz (pipecat)":"texto (LLM)"}.`)}catch(g){t("erro",g instanceof Error?g.message:"Falha ao salvar modo.")}},p=async()=>{const m=a.trim();if(!m)return;const g=[...i,{role:"user",content:m}];o(g),l(""),d(!0);try{const b=await W.agentes.chat(g.map(y=>({role:y.role==="assistant"?"assistant":"user",content:y.content})));b.ok&&b.resposta?o([...g,{role:"assistant",content:b.resposta}]):(o([...g,{role:"assistant",content:`⚠ ${b.mensagem??"Sem resposta."}`}]),t("erro",b.mensagem??"Sem resposta do agente."))}catch(b){t("erro",b instanceof Error?b.message:"Falha no chat.")}finally{d(!1)}};return u.jsxs("div",{className:"space-y-5 max-w-3xl",children:[u.jsxs("div",{className:"bg-white rounded-xl shadow-sm border border-gray-100 p-6 space-y-4",children:[u.jsx("h3",{className:"text-sm font-semibold text-gray-800",children:"Modo do agente de atendimento"}),u.jsx("div",{className:"flex gap-3",children:[{id:"texto",rotulo:"Texto (LLM)",icone:"fas fa-keyboard",descricao:"Chat via LLM configurado"},{id:"voz",rotulo:"Voz (pipecat)",icone:"fas fa-microphone",descricao:"Atendimento por voz"}].map(m=>u.jsxs("button",{onClick:()=>h(m.id),className:H("flex-1 px-4 py-3 rounded-lg border text-left transition",e===m.id?"bg-indigo-50 border-indigo-400":"bg-white border-gray-200 hover:bg-gray-50"),children:[u.jsxs("p",{className:H("text-sm font-medium flex items-center gap-2",e===m.id?"text-indigo-700":"text-gray-600"),children:[u.jsx("i",{className:m.icone})," ",m.rotulo]}),u.jsx("p",{className:"text-xs text-gray-400 mt-1",children:m.descricao})]},m.id))}),e==="voz"&&u.jsxs("div",{children:[u.jsx("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"URL do serviço pipecat"}),u.jsx("input",{value:s,onChange:m=>r(m.target.value),onBlur:()=>h("voz"),placeholder:"http://localhost:5000",className:"w-full max-w-md px-3 py-2 text-sm border border-gray-200 rounded-lg focus:ring-2 focus:ring-indigo-400 outline-none"})]})]}),u.jsxs("div",{className:"bg-white rounded-xl shadow-sm border border-gray-100 p-6",children:[u.jsx("h3",{className:"text-sm font-semibold text-gray-800 mb-3",children:"Testar conversa"}),u.jsxs("div",{className:"space-y-3 max-h-80 overflow-y-auto mb-4",children:[i.map((m,g)=>u.jsx("div",{className:H("flex",m.role==="user"?"justify-end":"justify-start"),children:u.jsx("div",{className:H("max-w-[80%] px-4 py-2.5 rounded-2xl text-sm",m.role==="user"?"bg-indigo-500 text-white rounded-br-sm":"bg-gray-100 text-gray-700 rounded-bl-sm"),children:m.content})},g)),c&&u.jsxs("div",{className:"text-xs text-gray-400 flex items-center gap-2",children:[u.jsx("i",{className:"fas fa-spinner fa-spin"})," pensando..."]})]}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx("input",{value:a,onChange:m=>l(m.target.value),onKeyDown:m=>m.key==="Enter"&&p(),placeholder:"Digite uma mensagem do cliente para testar...",className:"flex-1 px-3 py-2.5 text-sm border border-gray-200 rounded-lg focus:ring-2 focus:ring-indigo-400 outline-none"}),u.jsx("button",{onClick:p,disabled:c,className:"px-5 py-2.5 text-sm font-medium text-white bg-gradient-to-r from-indigo-500 to-purple-500 rounded-lg hover:opacity-90 disabled:opacity-60",children:u.jsx("i",{className:"fas fa-paper-plane"})})]})]})]})}function PE({onConfigSalva:t}){const{toast:e}=en(),[n,s]=S.useState(null),[r,i]=S.useState(!1),[o,a]=S.useState(""),l=S.useCallback(async()=>{const h=await W.config.obter();s(h)},[]);if(S.useEffect(()=>{l().catch(h=>e("erro",h.message))},[l,e]),!n)return u.jsx("div",{className:"text-center text-gray-400 py-16",children:u.jsx("i",{className:"fas fa-spinner fa-spin text-2xl"})});const c=h=>{s(p=>{if(!p)return p;const m=JSON.parse(JSON.stringify(p));return h(m),m})},d=async()=>{i(!0);try{const h=await W.config.salvar(n);s(h),t==null||t(h),e("sucesso","Configurações salvas localmente (config.json).")}catch(h){e("erro",h instanceof Error?h.message:"Falha ao salvar configurações.")}finally{i(!1)}},f=async()=>{a("llm");try{const h=await W.config.testarLlm();e(h.ok?"sucesso":"erro",h.ok?`LLM respondeu: ${h.resposta}`:h.mensagem??"Falha no teste.")}finally{a("")}};return u.jsxs("div",{className:"space-y-6 max-w-4xl",children:[u.jsxs(Va,{titulo:"LLM (agentes de IA)",icone:"fas fa-brain",children:[u.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[u.jsx(an,{rotulo:"Base URL",valor:n.llm.base_url,onChange:h=>c(p=>{p.llm.base_url=h}),placeholder:"https://api.openai.com/v1"}),u.jsx(an,{rotulo:"Modelo",valor:n.llm.modelo,onChange:h=>c(p=>{p.llm.modelo=h}),placeholder:"gpt-4o-mini"}),u.jsx(OE,{rotulo:"API Key",configurado:!!n.llm.api_key_configurado,onChange:h=>c(p=>{p.llm.api_key=h})})]}),u.jsx(TE,{rotulo:"Testar conexão LLM",carregando:o==="llm",onClick:f})]}),u.jsxs(Va,{titulo:"Extratores de leads",icone:"fas fa-magnifying-glass-location",children:[u.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[u.jsx(an,{rotulo:"Google Maps Scraper — binário",valor:n.extratores.google_maps_cli,onChange:h=>c(p=>{p.extratores.google_maps_cli=h}),placeholder:"C:\\ferramentas\\google-maps-scraper.exe"}),u.jsx(an,{rotulo:"igmapper — binário",valor:n.extratores.igmapper_cli,onChange:h=>c(p=>{p.extratores.igmapper_cli=h}),placeholder:"Caminho do CLI igmapper"})]}),u.jsxs(Qt,{titulo:"Argumentos dos scrapers (templates)",icone:"fas fa-terminal",children:[u.jsx(bm,{rotulo:"Google Maps — template de argumentos",valor:n.extratores.google_maps_args,onChange:h=>c(p=>{p.extratores.google_maps_args=h}),linhas:2}),u.jsx(bm,{rotulo:"igmapper — template de argumentos",valor:n.extratores.igmapper_args,onChange:h=>c(p=>{p.extratores.igmapper_args=h}),linhas:2})]}),u.jsxs(Qt,{titulo:"CNPJ e Scrapling",icone:"fas fa-building",children:[u.jsx(an,{rotulo:"Provedor de busca CNAE/UF — URL",valor:n.extratores.cnpj_provedor_busca,onChange:h=>c(p=>{p.extratores.cnpj_provedor_busca=h}),placeholder:"https://api.opencnpj.org"}),u.jsx(an,{rotulo:"Scrapling — binário (scraping profundo)",valor:n.extratores.scrapling_cli,onChange:h=>c(p=>{p.extratores.scrapling_cli=h}),placeholder:"Caminho do CLI Scrapling"})]})]}),u.jsxs(Va,{titulo:"Agentes — integrações",icone:"fas fa-robot",children:[u.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[u.jsx(an,{rotulo:"OpenOutreach — URL",valor:n.integracoes.openoutreach.url,onChange:h=>c(p=>{p.integracoes.openoutreach.url=h}),placeholder:"http://localhost:9090"}),u.jsxs("label",{className:"flex items-center gap-2 text-sm text-gray-600 bg-indigo-50 border border-indigo-100 rounded-lg px-3 py-2.5 cursor-pointer h-fit mt-5",children:[u.jsx("input",{type:"checkbox",checked:n.integracoes.openoutreach.enabled,onChange:h=>c(p=>{p.integracoes.openoutreach.enabled=h.target.checked}),className:"w-4 h-4 accent-indigo-500"}),"OpenOutreach ativo"]})]}),u.jsx(an,{rotulo:"pipecat — URL (atendimento por voz)",valor:n.integracoes.pipecat.url,onChange:h=>c(p=>{p.integracoes.pipecat.url=h}),placeholder:"http://localhost:5000"})]}),u.jsx(Va,{titulo:"Perfil e licença",icone:"fas fa-user",children:u.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[u.jsx(an,{rotulo:"Seu nome",valor:n.perfil.nome,onChange:h=>c(p=>{p.perfil.nome=h})}),u.jsx(an,{rotulo:"Expira em",valor:n.perfil.licenca.expira_em,onChange:h=>c(p=>{p.perfil.licenca.expira_em=h})}),u.jsx(RE,{rotulo:"Dias restantes (vazio = infinito)",valor:n.perfil.licenca.restam_dias??0,onChange:h=>c(p=>{p.perfil.licenca.restam_dias=h>0?h:null})})]})}),u.jsx("div",{className:"flex justify-end",children:u.jsxs("button",{onClick:d,disabled:r,className:"px-8 py-3 text-sm font-medium text-white bg-gradient-to-r from-indigo-500 to-purple-500 rounded-lg hover:opacity-90 transition disabled:opacity-60 shadow-sm",children:[u.jsx("i",{className:H("fas fa-save mr-2",r&&"fa-spin")}),r?"Salvando...":"Salvar configurações"]})})]})}function Va({titulo:t,icone:e,children:n}){return u.jsxs("div",{className:"bg-white rounded-xl shadow-sm border border-gray-100 p-6 space-y-4",children:[u.jsxs("h3",{className:"text-sm font-semibold text-gray-800 flex items-center gap-2",children:[u.jsx("i",{className:H(e,"text-indigo-400")})," ",t]}),n]})}function an({rotulo:t,valor:e,onChange:n,placeholder:s,tipo:r="text"}){return u.jsxs("div",{children:[u.jsx("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:t}),u.jsx("input",{type:r,value:e,onChange:i=>n(i.target.value),placeholder:s,className:"w-full px-3 py-2 text-sm border border-gray-200 rounded-lg focus:ring-2 focus:ring-indigo-400 outline-none"})]})}function RE({rotulo:t,valor:e,onChange:n}){return u.jsxs("div",{children:[u.jsx("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:t}),u.jsx("input",{type:"number",value:e??0,onChange:s=>n(Number(s.target.value)||0),className:"w-full px-3 py-2 text-sm border border-gray-200 rounded-lg focus:ring-2 focus:ring-indigo-400 outline-none"})]})}function OE({rotulo:t,configurado:e,onChange:n}){return u.jsxs("div",{children:[u.jsxs("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:[t," ",e&&u.jsx("span",{className:"text-green-600",children:"• configurado"})]}),u.jsx("input",{type:"password",onChange:s=>n(s.target.value),placeholder:e?"•••••••• (deixe vazio para manter)":"cole a chave aqui",className:"w-full px-3 py-2 text-sm border border-gray-200 rounded-lg focus:ring-2 focus:ring-indigo-400 outline-none"})]})}function bm({rotulo:t,valor:e,onChange:n,linhas:s=3}){return u.jsxs("div",{children:[u.jsx("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:t}),u.jsx("textarea",{value:e,onChange:r=>n(r.target.value),rows:s,className:"w-full px-3 py-2 text-xs font-mono border border-gray-200 rounded-lg focus:ring-2 focus:ring-indigo-400 outline-none"})]})}function TE({rotulo:t,onClick:e,carregando:n}){return u.jsxs("button",{onClick:e,disabled:n,className:"text-xs text-indigo-600 hover:text-indigo-800 font-medium disabled:opacity-50",children:[u.jsx("i",{className:H("fas fa-vial-circle-check mr-1",n&&"fa-spin")})," ",t]})}const DE=[{id:"lead.criado",rotulo:"Lead criado"},{id:"lead.etapa",rotulo:"Lead mudou de etapa"},{id:"campanha.concluida",rotulo:"Campanha concluída"}];function LE(){const{toast:t}=en(),[e,n]=S.useState(""),[s,r]=S.useState(new Set),[i,o]=S.useState(""),[a,l]=S.useState(!1),[c,d]=S.useState(!1),f=S.useCallback(async()=>{const g=await W.webhook.obter();n(g.url),r(new Set(g.eventos))},[]);S.useEffect(()=>{f().catch(g=>t("erro",g.message))},[f,t]);const h=g=>r(b=>{const y=new Set(b);return y.has(g)?y.delete(g):y.add(g),y}),p=async()=>{d(!0);try{await W.webhook.salvar({url:e.trim(),eventos:[...s]}),t("sucesso","Webhook salvo.")}catch(g){t("erro",g instanceof Error?g.message:"Falha ao salvar webhook.")}finally{d(!1)}},m=async()=>{if(!e.trim()){t("erro","Informe a URL do webhook antes de testar.");return}try{const g=await W.webhook.testar(e.trim());g.ok?o(`✅ HTTP ${g.status_http} — o endpoint recebeu o evento de teste.
|
|
88
|
+
`},TN={onDragStart(t){let{active:e}=t;return"Picked up draggable item "+e.id+"."},onDragOver(t){let{active:e,over:n}=t;return n?"Draggable item "+e.id+" was moved over droppable area "+n.id+".":"Draggable item "+e.id+" is no longer over a droppable area."},onDragEnd(t){let{active:e,over:n}=t;return n?"Draggable item "+e.id+" was dropped over droppable area "+n.id:"Draggable item "+e.id+" was dropped."},onDragCancel(t){let{active:e}=t;return"Dragging was cancelled. Draggable item "+e.id+" was dropped."}};function DN(t){let{announcements:e=TN,container:n,hiddenTextDescribedById:s,screenReaderInstructions:r=ON}=t;const{announce:i,announcement:o}=MN(),a=aa("DndLiveRegion"),[l,c]=S.useState(!1);if(S.useEffect(()=>{c(!0)},[]),PN(S.useMemo(()=>({onDragStart(f){let{active:h}=f;i(e.onDragStart({active:h}))},onDragMove(f){let{active:h,over:p}=f;e.onDragMove&&i(e.onDragMove({active:h,over:p}))},onDragOver(f){let{active:h,over:p}=f;i(e.onDragOver({active:h,over:p}))},onDragEnd(f){let{active:h,over:p}=f;i(e.onDragEnd({active:h,over:p}))},onDragCancel(f){let{active:h,over:p}=f;i(e.onDragCancel({active:h,over:p}))}}),[i,e])),!l)return null;const d=pe.createElement(pe.Fragment,null,pe.createElement(NN,{id:s,value:r.draggable}),pe.createElement(EN,{id:a,announcement:o}));return n?Ar.createPortal(d,n):d}var Te;(function(t){t.DragStart="dragStart",t.DragMove="dragMove",t.DragEnd="dragEnd",t.DragCancel="dragCancel",t.DragOver="dragOver",t.RegisterDroppable="registerDroppable",t.SetDroppableDisabled="setDroppableDisabled",t.UnregisterDroppable="unregisterDroppable"})(Te||(Te={}));function Zl(){}function LN(t,e){return S.useMemo(()=>({sensor:t,options:e??{}}),[t,e])}function AN(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];return S.useMemo(()=>[...e].filter(s=>s!=null),[...e])}const Zt=Object.freeze({x:0,y:0});function IN(t,e){return Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2))}function FN(t,e){const n=Jl(t);if(!n)return"0 0";const s={x:(n.x-e.left)/e.width*100,y:(n.y-e.top)/e.height*100};return s.x+"% "+s.y+"%"}function zN(t,e){let{data:{value:n}}=t,{data:{value:s}}=e;return n-s}function BN(t,e){let{data:{value:n}}=t,{data:{value:s}}=e;return s-n}function am(t){let{left:e,top:n,height:s,width:r}=t;return[{x:e,y:n},{x:e+r,y:n},{x:e,y:n+s},{x:e+r,y:n+s}]}function $N(t,e){if(!t||t.length===0)return null;const[n]=t;return n[e]}const UN=t=>{let{collisionRect:e,droppableRects:n,droppableContainers:s}=t;const r=am(e),i=[];for(const o of s){const{id:a}=o,l=n.get(a);if(l){const c=am(l),d=r.reduce((h,p,m)=>h+IN(c[m],p),0),f=Number((d/4).toFixed(4));i.push({id:a,data:{droppableContainer:o,value:f}})}}return i.sort(zN)};function WN(t,e){const n=Math.max(e.top,t.top),s=Math.max(e.left,t.left),r=Math.min(e.left+e.width,t.left+t.width),i=Math.min(e.top+e.height,t.top+t.height),o=r-s,a=i-n;if(s<r&&n<i){const l=e.width*e.height,c=t.width*t.height,d=o*a,f=d/(l+c-d);return Number(f.toFixed(4))}return 0}const HN=t=>{let{collisionRect:e,droppableRects:n,droppableContainers:s}=t;const r=[];for(const i of s){const{id:o}=i,a=n.get(o);if(a){const l=WN(a,e);l>0&&r.push({id:o,data:{droppableContainer:i,value:l}})}}return r.sort(BN)};function VN(t,e,n){return{...t,scaleX:e&&n?e.width/n.width:1,scaleY:e&&n?e.height/n.height:1}}function lv(t,e){return t&&e?{x:t.left-e.left,y:t.top-e.top}:Zt}function QN(t){return function(n){for(var s=arguments.length,r=new Array(s>1?s-1:0),i=1;i<s;i++)r[i-1]=arguments[i];return r.reduce((o,a)=>({...o,top:o.top+t*a.y,bottom:o.bottom+t*a.y,left:o.left+t*a.x,right:o.right+t*a.x}),{...n})}}const KN=QN(1);function cv(t){if(t.startsWith("matrix3d(")){const e=t.slice(9,-1).split(/, /);return{x:+e[12],y:+e[13],scaleX:+e[0],scaleY:+e[5]}}else if(t.startsWith("matrix(")){const e=t.slice(7,-1).split(/, /);return{x:+e[4],y:+e[5],scaleX:+e[0],scaleY:+e[3]}}return null}function YN(t,e,n){const s=cv(e);if(!s)return t;const{scaleX:r,scaleY:i,x:o,y:a}=s,l=t.left-o-(1-r)*parseFloat(n),c=t.top-a-(1-i)*parseFloat(n.slice(n.indexOf(" ")+1)),d=r?t.width/r:t.width,f=i?t.height/i:t.height;return{width:d,height:f,top:c,right:l+d,bottom:c+f,left:l}}const XN={ignoreTransform:!1};function Ci(t,e){e===void 0&&(e=XN);let n=t.getBoundingClientRect();if(e.ignoreTransform){const{transform:c,transformOrigin:d}=st(t).getComputedStyle(t);c&&(n=YN(n,c,d))}const{top:s,left:r,width:i,height:o,bottom:a,right:l}=n;return{top:s,left:r,width:i,height:o,bottom:a,right:l}}function lm(t){return Ci(t,{ignoreTransform:!0})}function qN(t){const e=t.innerWidth,n=t.innerHeight;return{top:0,left:0,right:e,bottom:n,width:e,height:n}}function GN(t,e){return e===void 0&&(e=st(t).getComputedStyle(t)),e.position==="fixed"}function JN(t,e){e===void 0&&(e=st(t).getComputedStyle(t));const n=/(auto|scroll|overlay)/;return["overflow","overflowX","overflowY"].some(r=>{const i=e[r];return typeof i=="string"?n.test(i):!1})}function lh(t,e){const n=[];function s(r){if(e!=null&&n.length>=e||!r)return n;if(ah(r)&&r.scrollingElement!=null&&!n.includes(r.scrollingElement))return n.push(r.scrollingElement),n;if(!ia(r)||iv(r)||n.includes(r))return n;const i=st(t).getComputedStyle(r);return r!==t&&JN(r,i)&&n.push(r),GN(r,i)?n:s(r.parentNode)}return t?s(t):n}function uv(t){const[e]=lh(t,1);return e??null}function bu(t){return!kc||!t?null:_i(t)?t:oh(t)?ah(t)||t===ki(t).scrollingElement?window:ia(t)?t:null:null}function dv(t){return _i(t)?t.scrollX:t.scrollLeft}function fv(t){return _i(t)?t.scrollY:t.scrollTop}function $d(t){return{x:dv(t),y:fv(t)}}var Ie;(function(t){t[t.Forward=1]="Forward",t[t.Backward=-1]="Backward"})(Ie||(Ie={}));function hv(t){return!kc||!t?!1:t===document.scrollingElement}function pv(t){const e={x:0,y:0},n=hv(t)?{height:window.innerHeight,width:window.innerWidth}:{height:t.clientHeight,width:t.clientWidth},s={x:t.scrollWidth-n.width,y:t.scrollHeight-n.height},r=t.scrollTop<=e.y,i=t.scrollLeft<=e.x,o=t.scrollTop>=s.y,a=t.scrollLeft>=s.x;return{isTop:r,isLeft:i,isBottom:o,isRight:a,maxScroll:s,minScroll:e}}const ZN={x:.2,y:.2};function e2(t,e,n,s,r){let{top:i,left:o,right:a,bottom:l}=n;s===void 0&&(s=10),r===void 0&&(r=ZN);const{isTop:c,isBottom:d,isLeft:f,isRight:h}=pv(t),p={x:0,y:0},m={x:0,y:0},g={height:e.height*r.y,width:e.width*r.x};return!c&&i<=e.top+g.height?(p.y=Ie.Backward,m.y=s*Math.abs((e.top+g.height-i)/g.height)):!d&&l>=e.bottom-g.height&&(p.y=Ie.Forward,m.y=s*Math.abs((e.bottom-g.height-l)/g.height)),!h&&a>=e.right-g.width?(p.x=Ie.Forward,m.x=s*Math.abs((e.right-g.width-a)/g.width)):!f&&o<=e.left+g.width&&(p.x=Ie.Backward,m.x=s*Math.abs((e.left+g.width-o)/g.width)),{direction:p,speed:m}}function t2(t){if(t===document.scrollingElement){const{innerWidth:i,innerHeight:o}=window;return{top:0,left:0,right:i,bottom:o,width:i,height:o}}const{top:e,left:n,right:s,bottom:r}=t.getBoundingClientRect();return{top:e,left:n,right:s,bottom:r,width:t.clientWidth,height:t.clientHeight}}function gv(t){return t.reduce((e,n)=>Qr(e,$d(n)),Zt)}function n2(t){return t.reduce((e,n)=>e+dv(n),0)}function s2(t){return t.reduce((e,n)=>e+fv(n),0)}function mv(t,e){if(e===void 0&&(e=Ci),!t)return;const{top:n,left:s,bottom:r,right:i}=e(t);uv(t)&&(r<=0||i<=0||n>=window.innerHeight||s>=window.innerWidth)&&t.scrollIntoView({block:"center",inline:"center"})}const r2=[["x",["left","right"],n2],["y",["top","bottom"],s2]];class ch{constructor(e,n){this.rect=void 0,this.width=void 0,this.height=void 0,this.top=void 0,this.bottom=void 0,this.right=void 0,this.left=void 0;const s=lh(n),r=gv(s);this.rect={...e},this.width=e.width,this.height=e.height;for(const[i,o,a]of r2)for(const l of o)Object.defineProperty(this,l,{get:()=>{const c=a(s),d=r[i]-c;return this.rect[l]+d},enumerable:!0});Object.defineProperty(this,"rect",{enumerable:!1})}}class go{constructor(e){this.target=void 0,this.listeners=[],this.removeAll=()=>{this.listeners.forEach(n=>{var s;return(s=this.target)==null?void 0:s.removeEventListener(...n)})},this.target=e}add(e,n,s){var r;(r=this.target)==null||r.addEventListener(e,n,s),this.listeners.push([e,n,s])}}function i2(t){const{EventTarget:e}=st(t);return t instanceof e?t:ki(t)}function wu(t,e){const n=Math.abs(t.x),s=Math.abs(t.y);return typeof e=="number"?Math.sqrt(n**2+s**2)>e:"x"in e&&"y"in e?n>e.x&&s>e.y:"x"in e?n>e.x:"y"in e?s>e.y:!1}var Pt;(function(t){t.Click="click",t.DragStart="dragstart",t.Keydown="keydown",t.ContextMenu="contextmenu",t.Resize="resize",t.SelectionChange="selectionchange",t.VisibilityChange="visibilitychange"})(Pt||(Pt={}));function cm(t){t.preventDefault()}function o2(t){t.stopPropagation()}var se;(function(t){t.Space="Space",t.Down="ArrowDown",t.Right="ArrowRight",t.Left="ArrowLeft",t.Up="ArrowUp",t.Esc="Escape",t.Enter="Enter",t.Tab="Tab"})(se||(se={}));const xv={start:[se.Space,se.Enter],cancel:[se.Esc],end:[se.Space,se.Enter,se.Tab]},a2=(t,e)=>{let{currentCoordinates:n}=e;switch(t.code){case se.Right:return{...n,x:n.x+25};case se.Left:return{...n,x:n.x-25};case se.Down:return{...n,y:n.y+25};case se.Up:return{...n,y:n.y-25}}};class yv{constructor(e){this.props=void 0,this.autoScrollEnabled=!1,this.referenceCoordinates=void 0,this.listeners=void 0,this.windowListeners=void 0,this.props=e;const{event:{target:n}}=e;this.props=e,this.listeners=new go(ki(n)),this.windowListeners=new go(st(n)),this.handleKeyDown=this.handleKeyDown.bind(this),this.handleCancel=this.handleCancel.bind(this),this.attach()}attach(){this.handleStart(),this.windowListeners.add(Pt.Resize,this.handleCancel),this.windowListeners.add(Pt.VisibilityChange,this.handleCancel),setTimeout(()=>this.listeners.add(Pt.Keydown,this.handleKeyDown))}handleStart(){const{activeNode:e,onStart:n}=this.props,s=e.node.current;s&&mv(s),n(Zt)}handleKeyDown(e){if(jc(e)){const{active:n,context:s,options:r}=this.props,{keyboardCodes:i=xv,coordinateGetter:o=a2,scrollBehavior:a="smooth"}=r,{code:l}=e;if(i.end.includes(l)){this.handleEnd(e);return}if(i.cancel.includes(l)){this.handleCancel(e);return}const{collisionRect:c}=s.current,d=c?{x:c.left,y:c.top}:Zt;this.referenceCoordinates||(this.referenceCoordinates=d);const f=o(e,{active:n,context:s.current,currentCoordinates:d});if(f){const h=Gl(f,d),p={x:0,y:0},{scrollableAncestors:m}=s.current;for(const g of m){const b=e.code,{isTop:y,isRight:x,isLeft:v,isBottom:_,maxScroll:w,minScroll:k}=pv(g),C=t2(g),j={x:Math.min(b===se.Right?C.right-C.width/2:C.right,Math.max(b===se.Right?C.left:C.left+C.width/2,f.x)),y:Math.min(b===se.Down?C.bottom-C.height/2:C.bottom,Math.max(b===se.Down?C.top:C.top+C.height/2,f.y))},M=b===se.Right&&!x||b===se.Left&&!v,E=b===se.Down&&!_||b===se.Up&&!y;if(M&&j.x!==f.x){const P=g.scrollLeft+h.x,A=b===se.Right&&P<=w.x||b===se.Left&&P>=k.x;if(A&&!h.y){g.scrollTo({left:P,behavior:a});return}A?p.x=g.scrollLeft-P:p.x=b===se.Right?g.scrollLeft-w.x:g.scrollLeft-k.x,p.x&&g.scrollBy({left:-p.x,behavior:a});break}else if(E&&j.y!==f.y){const P=g.scrollTop+h.y,A=b===se.Down&&P<=w.y||b===se.Up&&P>=k.y;if(A&&!h.x){g.scrollTo({top:P,behavior:a});return}A?p.y=g.scrollTop-P:p.y=b===se.Down?g.scrollTop-w.y:g.scrollTop-k.y,p.y&&g.scrollBy({top:-p.y,behavior:a});break}}this.handleMove(e,Qr(Gl(f,this.referenceCoordinates),p))}}}handleMove(e,n){const{onMove:s}=this.props;e.preventDefault(),s(n)}handleEnd(e){const{onEnd:n}=this.props;e.preventDefault(),this.detach(),n()}handleCancel(e){const{onCancel:n}=this.props;e.preventDefault(),this.detach(),n()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll()}}yv.activators=[{eventName:"onKeyDown",handler:(t,e,n)=>{let{keyboardCodes:s=xv,onActivation:r}=e,{active:i}=n;const{code:o}=t.nativeEvent;if(s.start.includes(o)){const a=i.activatorNode.current;return a&&t.target!==a?!1:(t.preventDefault(),r==null||r({event:t.nativeEvent}),!0)}return!1}}];function um(t){return!!(t&&"distance"in t)}function dm(t){return!!(t&&"delay"in t)}class uh{constructor(e,n,s){var r;s===void 0&&(s=i2(e.event.target)),this.props=void 0,this.events=void 0,this.autoScrollEnabled=!0,this.document=void 0,this.activated=!1,this.initialCoordinates=void 0,this.timeoutId=null,this.listeners=void 0,this.documentListeners=void 0,this.windowListeners=void 0,this.props=e,this.events=n;const{event:i}=e,{target:o}=i;this.props=e,this.events=n,this.document=ki(o),this.documentListeners=new go(this.document),this.listeners=new go(s),this.windowListeners=new go(st(o)),this.initialCoordinates=(r=Jl(i))!=null?r:Zt,this.handleStart=this.handleStart.bind(this),this.handleMove=this.handleMove.bind(this),this.handleEnd=this.handleEnd.bind(this),this.handleCancel=this.handleCancel.bind(this),this.handleKeydown=this.handleKeydown.bind(this),this.removeTextSelection=this.removeTextSelection.bind(this),this.attach()}attach(){const{events:e,props:{options:{activationConstraint:n,bypassActivationConstraint:s}}}=this;if(this.listeners.add(e.move.name,this.handleMove,{passive:!1}),this.listeners.add(e.end.name,this.handleEnd),e.cancel&&this.listeners.add(e.cancel.name,this.handleCancel),this.windowListeners.add(Pt.Resize,this.handleCancel),this.windowListeners.add(Pt.DragStart,cm),this.windowListeners.add(Pt.VisibilityChange,this.handleCancel),this.windowListeners.add(Pt.ContextMenu,cm),this.documentListeners.add(Pt.Keydown,this.handleKeydown),n){if(s!=null&&s({event:this.props.event,activeNode:this.props.activeNode,options:this.props.options}))return this.handleStart();if(dm(n)){this.timeoutId=setTimeout(this.handleStart,n.delay),this.handlePending(n);return}if(um(n)){this.handlePending(n);return}}this.handleStart()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll(),setTimeout(this.documentListeners.removeAll,50),this.timeoutId!==null&&(clearTimeout(this.timeoutId),this.timeoutId=null)}handlePending(e,n){const{active:s,onPending:r}=this.props;r(s,e,this.initialCoordinates,n)}handleStart(){const{initialCoordinates:e}=this,{onStart:n}=this.props;e&&(this.activated=!0,this.documentListeners.add(Pt.Click,o2,{capture:!0}),this.removeTextSelection(),this.documentListeners.add(Pt.SelectionChange,this.removeTextSelection),n(e))}handleMove(e){var n;const{activated:s,initialCoordinates:r,props:i}=this,{onMove:o,options:{activationConstraint:a}}=i;if(!r)return;const l=(n=Jl(e))!=null?n:Zt,c=Gl(r,l);if(!s&&a){if(um(a)){if(a.tolerance!=null&&wu(c,a.tolerance))return this.handleCancel();if(wu(c,a.distance))return this.handleStart()}if(dm(a)&&wu(c,a.tolerance))return this.handleCancel();this.handlePending(a,c);return}e.cancelable&&e.preventDefault(),o(l)}handleEnd(){const{onAbort:e,onEnd:n}=this.props;this.detach(),this.activated||e(this.props.active),n()}handleCancel(){const{onAbort:e,onCancel:n}=this.props;this.detach(),this.activated||e(this.props.active),n()}handleKeydown(e){e.code===se.Esc&&this.handleCancel()}removeTextSelection(){var e;(e=this.document.getSelection())==null||e.removeAllRanges()}}const l2={cancel:{name:"pointercancel"},move:{name:"pointermove"},end:{name:"pointerup"}};class dh extends uh{constructor(e){const{event:n}=e,s=ki(n.target);super(e,l2,s)}}dh.activators=[{eventName:"onPointerDown",handler:(t,e)=>{let{nativeEvent:n}=t,{onActivation:s}=e;return!n.isPrimary||n.button!==0?!1:(s==null||s({event:n}),!0)}}];const c2={move:{name:"mousemove"},end:{name:"mouseup"}};var Ud;(function(t){t[t.RightClick=2]="RightClick"})(Ud||(Ud={}));class u2 extends uh{constructor(e){super(e,c2,ki(e.event.target))}}u2.activators=[{eventName:"onMouseDown",handler:(t,e)=>{let{nativeEvent:n}=t,{onActivation:s}=e;return n.button===Ud.RightClick?!1:(s==null||s({event:n}),!0)}}];const Su={cancel:{name:"touchcancel"},move:{name:"touchmove"},end:{name:"touchend"}};class d2 extends uh{constructor(e){super(e,Su)}static setup(){return window.addEventListener(Su.move.name,e,{capture:!1,passive:!1}),function(){window.removeEventListener(Su.move.name,e)};function e(){}}}d2.activators=[{eventName:"onTouchStart",handler:(t,e)=>{let{nativeEvent:n}=t,{onActivation:s}=e;const{touches:r}=n;return r.length>1?!1:(s==null||s({event:n}),!0)}}];var mo;(function(t){t[t.Pointer=0]="Pointer",t[t.DraggableRect=1]="DraggableRect"})(mo||(mo={}));var ec;(function(t){t[t.TreeOrder=0]="TreeOrder",t[t.ReversedTreeOrder=1]="ReversedTreeOrder"})(ec||(ec={}));function f2(t){let{acceleration:e,activator:n=mo.Pointer,canScroll:s,draggingRect:r,enabled:i,interval:o=5,order:a=ec.TreeOrder,pointerCoordinates:l,scrollableAncestors:c,scrollableAncestorRects:d,delta:f,threshold:h}=t;const p=p2({delta:f,disabled:!i}),[m,g]=SN(),b=S.useRef({x:0,y:0}),y=S.useRef({x:0,y:0}),x=S.useMemo(()=>{switch(n){case mo.Pointer:return l?{top:l.y,bottom:l.y,left:l.x,right:l.x}:null;case mo.DraggableRect:return r}},[n,r,l]),v=S.useRef(null),_=S.useCallback(()=>{const k=v.current;if(!k)return;const C=b.current.x*y.current.x,j=b.current.y*y.current.y;k.scrollBy(C,j)},[]),w=S.useMemo(()=>a===ec.TreeOrder?[...c].reverse():c,[a,c]);S.useEffect(()=>{if(!i||!c.length||!x){g();return}for(const k of w){if((s==null?void 0:s(k))===!1)continue;const C=c.indexOf(k),j=d[C];if(!j)continue;const{direction:M,speed:E}=e2(k,j,x,e,h);for(const P of["x","y"])p[P][M[P]]||(E[P]=0,M[P]=0);if(E.x>0||E.y>0){g(),v.current=k,m(_,o),b.current=E,y.current=M;return}}b.current={x:0,y:0},y.current={x:0,y:0},g()},[e,_,s,g,i,o,JSON.stringify(x),JSON.stringify(p),m,c,w,d,JSON.stringify(h)])}const h2={x:{[Ie.Backward]:!1,[Ie.Forward]:!1},y:{[Ie.Backward]:!1,[Ie.Forward]:!1}};function p2(t){let{delta:e,disabled:n}=t;const s=ql(e);return oa(r=>{if(n||!s||!r)return h2;const i={x:Math.sign(e.x-s.x),y:Math.sign(e.y-s.y)};return{x:{[Ie.Backward]:r.x[Ie.Backward]||i.x===-1,[Ie.Forward]:r.x[Ie.Forward]||i.x===1},y:{[Ie.Backward]:r.y[Ie.Backward]||i.y===-1,[Ie.Forward]:r.y[Ie.Forward]||i.y===1}}},[n,e,s])}function g2(t,e){const n=e!=null?t.get(e):void 0,s=n?n.node.current:null;return oa(r=>{var i;return e==null?null:(i=s??r)!=null?i:null},[s,e])}function m2(t,e){return S.useMemo(()=>t.reduce((n,s)=>{const{sensor:r}=s,i=r.activators.map(o=>({eventName:o.eventName,handler:e(o.handler,s)}));return[...n,...i]},[]),[t,e])}var Wo;(function(t){t[t.Always=0]="Always",t[t.BeforeDragging=1]="BeforeDragging",t[t.WhileDragging=2]="WhileDragging"})(Wo||(Wo={}));var Wd;(function(t){t.Optimized="optimized"})(Wd||(Wd={}));const fm=new Map;function x2(t,e){let{dragging:n,dependencies:s,config:r}=e;const[i,o]=S.useState(null),{frequency:a,measure:l,strategy:c}=r,d=S.useRef(t),f=b(),h=Uo(f),p=S.useCallback(function(y){y===void 0&&(y=[]),!h.current&&o(x=>x===null?y:x.concat(y.filter(v=>!x.includes(v))))},[h]),m=S.useRef(null),g=oa(y=>{if(f&&!n)return fm;if(!y||y===fm||d.current!==t||i!=null){const x=new Map;for(let v of t){if(!v)continue;if(i&&i.length>0&&!i.includes(v.id)&&v.rect.current){x.set(v.id,v.rect.current);continue}const _=v.node.current,w=_?new ch(l(_),_):null;v.rect.current=w,w&&x.set(v.id,w)}return x}return y},[t,i,n,f,l]);return S.useEffect(()=>{d.current=t},[t]),S.useEffect(()=>{f||p()},[n,f]),S.useEffect(()=>{i&&i.length>0&&o(null)},[JSON.stringify(i)]),S.useEffect(()=>{f||typeof a!="number"||m.current!==null||(m.current=setTimeout(()=>{p(),m.current=null},a))},[a,f,p,...s]),{droppableRects:g,measureDroppableContainers:p,measuringScheduled:i!=null};function b(){switch(c){case Wo.Always:return!1;case Wo.BeforeDragging:return n;default:return!n}}}function fh(t,e){return oa(n=>t?n||(typeof e=="function"?e(t):t):null,[e,t])}function y2(t,e){return fh(t,e)}function v2(t){let{callback:e,disabled:n}=t;const s=Cc(e),r=S.useMemo(()=>{if(n||typeof window>"u"||typeof window.MutationObserver>"u")return;const{MutationObserver:i}=window;return new i(s)},[s,n]);return S.useEffect(()=>()=>r==null?void 0:r.disconnect(),[r]),r}function Nc(t){let{callback:e,disabled:n}=t;const s=Cc(e),r=S.useMemo(()=>{if(n||typeof window>"u"||typeof window.ResizeObserver>"u")return;const{ResizeObserver:i}=window;return new i(s)},[n]);return S.useEffect(()=>()=>r==null?void 0:r.disconnect(),[r]),r}function b2(t){return new ch(Ci(t),t)}function hm(t,e,n){e===void 0&&(e=b2);const[s,r]=S.useState(null);function i(){r(l=>{if(!t)return null;if(t.isConnected===!1){var c;return(c=l??n)!=null?c:null}const d=e(t);return JSON.stringify(l)===JSON.stringify(d)?l:d})}const o=v2({callback(l){if(t)for(const c of l){const{type:d,target:f}=c;if(d==="childList"&&f instanceof HTMLElement&&f.contains(t)){i();break}}}}),a=Nc({callback:i});return Jt(()=>{i(),t?(a==null||a.observe(t),o==null||o.observe(document.body,{childList:!0,subtree:!0})):(a==null||a.disconnect(),o==null||o.disconnect())},[t]),s}function w2(t){const e=fh(t);return lv(t,e)}const pm=[];function S2(t){const e=S.useRef(t),n=oa(s=>t?s&&s!==pm&&t&&e.current&&t.parentNode===e.current.parentNode?s:lh(t):pm,[t]);return S.useEffect(()=>{e.current=t},[t]),n}function _2(t){const[e,n]=S.useState(null),s=S.useRef(t),r=S.useCallback(i=>{const o=bu(i.target);o&&n(a=>a?(a.set(o,$d(o)),new Map(a)):null)},[]);return S.useEffect(()=>{const i=s.current;if(t!==i){o(i);const a=t.map(l=>{const c=bu(l);return c?(c.addEventListener("scroll",r,{passive:!0}),[c,$d(c)]):null}).filter(l=>l!=null);n(a.length?new Map(a):null),s.current=t}return()=>{o(t),o(i)};function o(a){a.forEach(l=>{const c=bu(l);c==null||c.removeEventListener("scroll",r)})}},[r,t]),S.useMemo(()=>t.length?e?Array.from(e.values()).reduce((i,o)=>Qr(i,o),Zt):gv(t):Zt,[t,e])}function gm(t,e){e===void 0&&(e=[]);const n=S.useRef(null);return S.useEffect(()=>{n.current=null},e),S.useEffect(()=>{const s=t!==Zt;s&&!n.current&&(n.current=t),!s&&n.current&&(n.current=null)},[t]),n.current?Gl(t,n.current):Zt}function k2(t){S.useEffect(()=>{if(!kc)return;const e=t.map(n=>{let{sensor:s}=n;return s.setup==null?void 0:s.setup()});return()=>{for(const n of e)n==null||n()}},t.map(e=>{let{sensor:n}=e;return n}))}function C2(t,e){return S.useMemo(()=>t.reduce((n,s)=>{let{eventName:r,handler:i}=s;return n[r]=o=>{i(o,e)},n},{}),[t,e])}function vv(t){return S.useMemo(()=>t?qN(t):null,[t])}const mm=[];function j2(t,e){e===void 0&&(e=Ci);const[n]=t,s=vv(n?st(n):null),[r,i]=S.useState(mm);function o(){i(()=>t.length?t.map(l=>hv(l)?s:new ch(e(l),l)):mm)}const a=Nc({callback:o});return Jt(()=>{a==null||a.disconnect(),o(),t.forEach(l=>a==null?void 0:a.observe(l))},[t]),r}function bv(t){if(!t)return null;if(t.children.length>1)return t;const e=t.children[0];return ia(e)?e:t}function N2(t){let{measure:e}=t;const[n,s]=S.useState(null),r=S.useCallback(c=>{for(const{target:d}of c)if(ia(d)){s(f=>{const h=e(d);return f?{...f,width:h.width,height:h.height}:h});break}},[e]),i=Nc({callback:r}),o=S.useCallback(c=>{const d=bv(c);i==null||i.disconnect(),d&&(i==null||i.observe(d)),s(d?e(d):null)},[e,i]),[a,l]=Xl(o);return S.useMemo(()=>({nodeRef:a,rect:n,setRef:l}),[n,a,l])}const E2=[{sensor:dh,options:{}},{sensor:yv,options:{}}],M2={current:{}},cl={draggable:{measure:lm},droppable:{measure:lm,strategy:Wo.WhileDragging,frequency:Wd.Optimized},dragOverlay:{measure:Ci}};class xo extends Map{get(e){var n;return e!=null&&(n=super.get(e))!=null?n:void 0}toArray(){return Array.from(this.values())}getEnabled(){return this.toArray().filter(e=>{let{disabled:n}=e;return!n})}getNodeFor(e){var n,s;return(n=(s=this.get(e))==null?void 0:s.node.current)!=null?n:void 0}}const P2={activatorEvent:null,active:null,activeNode:null,activeNodeRect:null,collisions:null,containerNodeRect:null,draggableNodes:new Map,droppableRects:new Map,droppableContainers:new xo,over:null,dragOverlay:{nodeRef:{current:null},rect:null,setRef:Zl},scrollableAncestors:[],scrollableAncestorRects:[],measuringConfiguration:cl,measureDroppableContainers:Zl,windowRect:null,measuringScheduled:!1},wv={activatorEvent:null,activators:[],active:null,activeNodeRect:null,ariaDescribedById:{draggable:""},dispatch:Zl,draggableNodes:new Map,over:null,measureDroppableContainers:Zl},la=S.createContext(wv),Sv=S.createContext(P2);function R2(){return{draggable:{active:null,initialCoordinates:{x:0,y:0},nodes:new Map,translate:{x:0,y:0}},droppable:{containers:new xo}}}function O2(t,e){switch(e.type){case Te.DragStart:return{...t,draggable:{...t.draggable,initialCoordinates:e.initialCoordinates,active:e.active}};case Te.DragMove:return t.draggable.active==null?t:{...t,draggable:{...t.draggable,translate:{x:e.coordinates.x-t.draggable.initialCoordinates.x,y:e.coordinates.y-t.draggable.initialCoordinates.y}}};case Te.DragEnd:case Te.DragCancel:return{...t,draggable:{...t.draggable,active:null,initialCoordinates:{x:0,y:0},translate:{x:0,y:0}}};case Te.RegisterDroppable:{const{element:n}=e,{id:s}=n,r=new xo(t.droppable.containers);return r.set(s,n),{...t,droppable:{...t.droppable,containers:r}}}case Te.SetDroppableDisabled:{const{id:n,key:s,disabled:r}=e,i=t.droppable.containers.get(n);if(!i||s!==i.key)return t;const o=new xo(t.droppable.containers);return o.set(n,{...i,disabled:r}),{...t,droppable:{...t.droppable,containers:o}}}case Te.UnregisterDroppable:{const{id:n,key:s}=e,r=t.droppable.containers.get(n);if(!r||s!==r.key)return t;const i=new xo(t.droppable.containers);return i.delete(n),{...t,droppable:{...t.droppable,containers:i}}}default:return t}}function T2(t){let{disabled:e}=t;const{active:n,activatorEvent:s,draggableNodes:r}=S.useContext(la),i=ql(s),o=ql(n==null?void 0:n.id);return S.useEffect(()=>{if(!e&&!s&&i&&o!=null){if(!jc(i)||document.activeElement===i.target)return;const a=r.get(o);if(!a)return;const{activatorNode:l,node:c}=a;if(!l.current&&!c.current)return;requestAnimationFrame(()=>{for(const d of[l.current,c.current]){if(!d)continue;const f=CN(d);if(f){f.focus();break}}})}},[s,e,r,o,i]),null}function _v(t,e){let{transform:n,...s}=e;return t!=null&&t.length?t.reduce((r,i)=>i({transform:r,...s}),n):n}function D2(t){return S.useMemo(()=>({draggable:{...cl.draggable,...t==null?void 0:t.draggable},droppable:{...cl.droppable,...t==null?void 0:t.droppable},dragOverlay:{...cl.dragOverlay,...t==null?void 0:t.dragOverlay}}),[t==null?void 0:t.draggable,t==null?void 0:t.droppable,t==null?void 0:t.dragOverlay])}function L2(t){let{activeNode:e,measure:n,initialRect:s,config:r=!0}=t;const i=S.useRef(!1),{x:o,y:a}=typeof r=="boolean"?{x:r,y:r}:r;Jt(()=>{if(!o&&!a||!e){i.current=!1;return}if(i.current||!s)return;const c=e==null?void 0:e.node.current;if(!c||c.isConnected===!1)return;const d=n(c),f=lv(d,s);if(o||(f.x=0),a||(f.y=0),i.current=!0,Math.abs(f.x)>0||Math.abs(f.y)>0){const h=uv(c);h&&h.scrollBy({top:f.y,left:f.x})}},[e,o,a,s,n])}const Ec=S.createContext({...Zt,scaleX:1,scaleY:1});var Yn;(function(t){t[t.Uninitialized=0]="Uninitialized",t[t.Initializing=1]="Initializing",t[t.Initialized=2]="Initialized"})(Yn||(Yn={}));const A2=S.memo(function(e){var n,s,r,i;let{id:o,accessibility:a,autoScroll:l=!0,children:c,sensors:d=E2,collisionDetection:f=HN,measuring:h,modifiers:p,...m}=e;const g=S.useReducer(O2,void 0,R2),[b,y]=g,[x,v]=RN(),[_,w]=S.useState(Yn.Uninitialized),k=_===Yn.Initialized,{draggable:{active:C,nodes:j,translate:M},droppable:{containers:E}}=b,P=C!=null?j.get(C):null,A=S.useRef({initial:null,translated:null}),Q=S.useMemo(()=>{var Ve;return C!=null?{id:C,data:(Ve=P==null?void 0:P.data)!=null?Ve:M2,rect:A}:null},[C,P]),ne=S.useRef(null),[Y,oe]=S.useState(null),[G,O]=S.useState(null),L=Uo(m,Object.values(m)),I=aa("DndDescribedBy",o),V=S.useMemo(()=>E.getEnabled(),[E]),F=D2(h),{droppableRects:ce,measureDroppableContainers:$,measuringScheduled:ke}=x2(V,{dragging:k,dependencies:[M.x,M.y],config:F.droppable}),J=g2(j,C),gt=S.useMemo(()=>G?Jl(G):null,[G]),Ft=zv(),zt=y2(J,F.draggable.measure);L2({activeNode:C!=null?j.get(C):null,config:Ft.layoutShiftCompensation,initialRect:zt,measure:F.draggable.measure});const ie=hm(J,F.draggable.measure,zt),ji=hm(J?J.parentElement:null),tn=S.useRef({activatorEvent:null,active:null,activeNode:J,collisionRect:null,collisions:null,droppableRects:ce,draggableNodes:j,draggingNode:null,draggingNodeRect:null,droppableContainers:E,over:null,scrollableAncestors:[],scrollAdjustedTranslate:null}),pr=E.getNodeFor((n=tn.current.over)==null?void 0:n.id),vn=N2({measure:F.dragOverlay.measure}),gr=(s=vn.nodeRef.current)!=null?s:J,mr=k?(r=vn.rect)!=null?r:ie:null,hh=!!(vn.nodeRef.current&&vn.rect),ph=w2(hh?null:ie),Mc=vv(gr?st(gr):null),Fn=S2(k?pr??J:null),ca=j2(Fn),ua=_v(p,{transform:{x:M.x-ph.x,y:M.y-ph.y,scaleX:1,scaleY:1},activatorEvent:G,active:Q,activeNodeRect:ie,containerNodeRect:ji,draggingNodeRect:mr,over:tn.current.over,overlayNodeRect:vn.rect,scrollableAncestors:Fn,scrollableAncestorRects:ca,windowRect:Mc}),gh=gt?Qr(gt,M):null,mh=_2(Fn),Ov=gm(mh),Tv=gm(mh,[ie]),xr=Qr(ua,Ov),yr=mr?KN(mr,ua):null,Ni=Q&&yr?f({active:Q,collisionRect:yr,droppableRects:ce,droppableContainers:V,pointerCoordinates:gh}):null,xh=$N(Ni,"id"),[zn,yh]=S.useState(null),Dv=hh?ua:Qr(ua,Tv),Lv=VN(Dv,(i=zn==null?void 0:zn.rect)!=null?i:null,ie),Pc=S.useRef(null),vh=S.useCallback((Ve,mt)=>{let{sensor:xt,options:Bn}=mt;if(ne.current==null)return;const Nt=j.get(ne.current);if(!Nt)return;const yt=Ve.nativeEvent,nn=new xt({active:ne.current,activeNode:Nt,event:yt,options:Bn,context:tn,onAbort(Be){if(!j.get(Be))return;const{onDragAbort:sn}=L.current,bn={id:Be};sn==null||sn(bn),x({type:"onDragAbort",event:bn})},onPending(Be,$n,sn,bn){if(!j.get(Be))return;const{onDragPending:Mi}=L.current,Un={id:Be,constraint:$n,initialCoordinates:sn,offset:bn};Mi==null||Mi(Un),x({type:"onDragPending",event:Un})},onStart(Be){const $n=ne.current;if($n==null)return;const sn=j.get($n);if(!sn)return;const{onDragStart:bn}=L.current,Ei={activatorEvent:yt,active:{id:$n,data:sn.data,rect:A}};Ar.unstable_batchedUpdates(()=>{bn==null||bn(Ei),w(Yn.Initializing),y({type:Te.DragStart,initialCoordinates:Be,active:$n}),x({type:"onDragStart",event:Ei}),oe(Pc.current),O(yt)})},onMove(Be){y({type:Te.DragMove,coordinates:Be})},onEnd:vr(Te.DragEnd),onCancel:vr(Te.DragCancel)});Pc.current=nn;function vr(Be){return async function(){const{active:sn,collisions:bn,over:Ei,scrollAdjustedTranslate:Mi}=tn.current;let Un=null;if(sn&&Mi){const{cancelDrop:Pi}=L.current;Un={activatorEvent:yt,active:sn,collisions:bn,delta:Mi,over:Ei},Be===Te.DragEnd&&typeof Pi=="function"&&await Promise.resolve(Pi(Un))&&(Be=Te.DragCancel)}ne.current=null,Ar.unstable_batchedUpdates(()=>{y({type:Be}),w(Yn.Uninitialized),yh(null),oe(null),O(null),Pc.current=null;const Pi=Be===Te.DragEnd?"onDragEnd":"onDragCancel";if(Un){const Rc=L.current[Pi];Rc==null||Rc(Un),x({type:Pi,event:Un})}})}}},[j]),Av=S.useCallback((Ve,mt)=>(xt,Bn)=>{const Nt=xt.nativeEvent,yt=j.get(Bn);if(ne.current!==null||!yt||Nt.dndKit||Nt.defaultPrevented)return;const nn={active:yt};Ve(xt,mt.options,nn)===!0&&(Nt.dndKit={capturedBy:mt.sensor},ne.current=Bn,vh(xt,mt))},[j,vh]),bh=m2(d,Av);k2(d),Jt(()=>{ie&&_===Yn.Initializing&&w(Yn.Initialized)},[ie,_]),S.useEffect(()=>{const{onDragMove:Ve}=L.current,{active:mt,activatorEvent:xt,collisions:Bn,over:Nt}=tn.current;if(!mt||!xt)return;const yt={active:mt,activatorEvent:xt,collisions:Bn,delta:{x:xr.x,y:xr.y},over:Nt};Ar.unstable_batchedUpdates(()=>{Ve==null||Ve(yt),x({type:"onDragMove",event:yt})})},[xr.x,xr.y]),S.useEffect(()=>{const{active:Ve,activatorEvent:mt,collisions:xt,droppableContainers:Bn,scrollAdjustedTranslate:Nt}=tn.current;if(!Ve||ne.current==null||!mt||!Nt)return;const{onDragOver:yt}=L.current,nn=Bn.get(xh),vr=nn&&nn.rect.current?{id:nn.id,rect:nn.rect.current,data:nn.data,disabled:nn.disabled}:null,Be={active:Ve,activatorEvent:mt,collisions:xt,delta:{x:Nt.x,y:Nt.y},over:vr};Ar.unstable_batchedUpdates(()=>{yh(vr),yt==null||yt(Be),x({type:"onDragOver",event:Be})})},[xh]),Jt(()=>{tn.current={activatorEvent:G,active:Q,activeNode:J,collisionRect:yr,collisions:Ni,droppableRects:ce,draggableNodes:j,draggingNode:gr,draggingNodeRect:mr,droppableContainers:E,over:zn,scrollableAncestors:Fn,scrollAdjustedTranslate:xr},A.current={initial:mr,translated:yr}},[Q,J,Ni,yr,j,gr,mr,ce,E,zn,Fn,xr]),f2({...Ft,delta:M,draggingRect:yr,pointerCoordinates:gh,scrollableAncestors:Fn,scrollableAncestorRects:ca});const Iv=S.useMemo(()=>({active:Q,activeNode:J,activeNodeRect:ie,activatorEvent:G,collisions:Ni,containerNodeRect:ji,dragOverlay:vn,draggableNodes:j,droppableContainers:E,droppableRects:ce,over:zn,measureDroppableContainers:$,scrollableAncestors:Fn,scrollableAncestorRects:ca,measuringConfiguration:F,measuringScheduled:ke,windowRect:Mc}),[Q,J,ie,G,Ni,ji,vn,j,E,ce,zn,$,Fn,ca,F,ke,Mc]),Fv=S.useMemo(()=>({activatorEvent:G,activators:bh,active:Q,activeNodeRect:ie,ariaDescribedById:{draggable:I},dispatch:y,draggableNodes:j,over:zn,measureDroppableContainers:$}),[G,bh,Q,ie,y,I,j,zn,$]);return pe.createElement(av.Provider,{value:v},pe.createElement(la.Provider,{value:Fv},pe.createElement(Sv.Provider,{value:Iv},pe.createElement(Ec.Provider,{value:Lv},c)),pe.createElement(T2,{disabled:(a==null?void 0:a.restoreFocus)===!1})),pe.createElement(DN,{...a,hiddenTextDescribedById:I}));function zv(){const Ve=(Y==null?void 0:Y.autoScrollEnabled)===!1,mt=typeof l=="object"?l.enabled===!1:l===!1,xt=k&&!Ve&&!mt;return typeof l=="object"?{...l,enabled:xt}:{enabled:xt}}}),I2=S.createContext(null),xm="button",F2="Draggable";function z2(t){let{id:e,data:n,disabled:s=!1,attributes:r}=t;const i=aa(F2),{activators:o,activatorEvent:a,active:l,activeNodeRect:c,ariaDescribedById:d,draggableNodes:f,over:h}=S.useContext(la),{role:p=xm,roleDescription:m="draggable",tabIndex:g=0}=r??{},b=(l==null?void 0:l.id)===e,y=S.useContext(b?Ec:I2),[x,v]=Xl(),[_,w]=Xl(),k=C2(o,e),C=Uo(n);Jt(()=>(f.set(e,{id:e,key:i,node:x,activatorNode:_,data:C}),()=>{const M=f.get(e);M&&M.key===i&&f.delete(e)}),[f,e]);const j=S.useMemo(()=>({role:p,tabIndex:g,"aria-disabled":s,"aria-pressed":b&&p===xm?!0:void 0,"aria-roledescription":m,"aria-describedby":d.draggable}),[s,p,g,b,m,d.draggable]);return{active:l,activatorEvent:a,activeNodeRect:c,attributes:j,isDragging:b,listeners:s?void 0:k,node:x,over:h,setNodeRef:v,setActivatorNodeRef:w,transform:y}}function kv(){return S.useContext(Sv)}const B2="Droppable",$2={timeout:25};function Cv(t){let{data:e,disabled:n=!1,id:s,resizeObserverConfig:r}=t;const i=aa(B2),{active:o,dispatch:a,over:l,measureDroppableContainers:c}=S.useContext(la),d=S.useRef({disabled:n}),f=S.useRef(!1),h=S.useRef(null),p=S.useRef(null),{disabled:m,updateMeasurementsFor:g,timeout:b}={...$2,...r},y=Uo(g??s),x=S.useCallback(()=>{if(!f.current){f.current=!0;return}p.current!=null&&clearTimeout(p.current),p.current=setTimeout(()=>{c(Array.isArray(y.current)?y.current:[y.current]),p.current=null},b)},[b]),v=Nc({callback:x,disabled:m||!o}),_=S.useCallback((j,M)=>{v&&(M&&(v.unobserve(M),f.current=!1),j&&v.observe(j))},[v]),[w,k]=Xl(_),C=Uo(e);return S.useEffect(()=>{!v||!w.current||(v.disconnect(),f.current=!1,v.observe(w.current))},[w,v]),S.useEffect(()=>(a({type:Te.RegisterDroppable,element:{id:s,key:i,disabled:n,node:w,rect:h,data:C}}),()=>a({type:Te.UnregisterDroppable,key:i,id:s})),[s]),S.useEffect(()=>{n!==d.current.disabled&&(a({type:Te.SetDroppableDisabled,id:s,key:i,disabled:n}),d.current.disabled=n)},[s,i,n,a]),{active:o,rect:h,isOver:(l==null?void 0:l.id)===s,node:w,over:l,setNodeRef:k}}function U2(t){let{animation:e,children:n}=t;const[s,r]=S.useState(null),[i,o]=S.useState(null),a=ql(n);return!n&&!s&&a&&r(a),Jt(()=>{if(!i)return;const l=s==null?void 0:s.key,c=s==null?void 0:s.props.id;if(l==null||c==null){r(null);return}Promise.resolve(e(c,i)).then(()=>{r(null)})},[e,s,i]),pe.createElement(pe.Fragment,null,n,s?S.cloneElement(s,{ref:o}):null)}const W2={x:0,y:0,scaleX:1,scaleY:1};function H2(t){let{children:e}=t;return pe.createElement(la.Provider,{value:wv},pe.createElement(Ec.Provider,{value:W2},e))}const V2={position:"fixed",touchAction:"none"},Q2=t=>jc(t)?"transform 250ms ease":void 0,K2=S.forwardRef((t,e)=>{let{as:n,activatorEvent:s,adjustScale:r,children:i,className:o,rect:a,style:l,transform:c,transition:d=Q2}=t;if(!a)return null;const f=r?c:{...c,scaleX:1,scaleY:1},h={...V2,width:a.width,height:a.height,top:a.top,left:a.left,transform:Ns.Transform.toString(f),transformOrigin:r&&s?FN(s,a):void 0,transition:typeof d=="function"?d(s):d,...l};return pe.createElement(n,{className:o,style:h,ref:e},i)}),Y2=t=>e=>{let{active:n,dragOverlay:s}=e;const r={},{styles:i,className:o}=t;if(i!=null&&i.active)for(const[a,l]of Object.entries(i.active))l!==void 0&&(r[a]=n.node.style.getPropertyValue(a),n.node.style.setProperty(a,l));if(i!=null&&i.dragOverlay)for(const[a,l]of Object.entries(i.dragOverlay))l!==void 0&&s.node.style.setProperty(a,l);return o!=null&&o.active&&n.node.classList.add(o.active),o!=null&&o.dragOverlay&&s.node.classList.add(o.dragOverlay),function(){for(const[l,c]of Object.entries(r))n.node.style.setProperty(l,c);o!=null&&o.active&&n.node.classList.remove(o.active)}},X2=t=>{let{transform:{initial:e,final:n}}=t;return[{transform:Ns.Transform.toString(e)},{transform:Ns.Transform.toString(n)}]},q2={duration:250,easing:"ease",keyframes:X2,sideEffects:Y2({styles:{active:{opacity:"0"}}})};function G2(t){let{config:e,draggableNodes:n,droppableContainers:s,measuringConfiguration:r}=t;return Cc((i,o)=>{if(e===null)return;const a=n.get(i);if(!a)return;const l=a.node.current;if(!l)return;const c=bv(o);if(!c)return;const{transform:d}=st(o).getComputedStyle(o),f=cv(d);if(!f)return;const h=typeof e=="function"?e:J2(e);return mv(l,r.draggable.measure),h({active:{id:i,data:a.data,node:l,rect:r.draggable.measure(l)},draggableNodes:n,dragOverlay:{node:o,rect:r.dragOverlay.measure(c)},droppableContainers:s,measuringConfiguration:r,transform:f})})}function J2(t){const{duration:e,easing:n,sideEffects:s,keyframes:r}={...q2,...t};return i=>{let{active:o,dragOverlay:a,transform:l,...c}=i;if(!e)return;const d={x:a.rect.left-o.rect.left,y:a.rect.top-o.rect.top},f={scaleX:l.scaleX!==1?o.rect.width*l.scaleX/a.rect.width:1,scaleY:l.scaleY!==1?o.rect.height*l.scaleY/a.rect.height:1},h={x:l.x-d.x,y:l.y-d.y,...f},p=r({...c,active:o,dragOverlay:a,transform:{initial:l,final:h}}),[m]=p,g=p[p.length-1];if(JSON.stringify(m)===JSON.stringify(g))return;const b=s==null?void 0:s({active:o,dragOverlay:a,...c}),y=a.node.animate(p,{duration:e,easing:n,fill:"forwards"});return new Promise(x=>{y.onfinish=()=>{b==null||b(),x()}})}}let ym=0;function Z2(t){return S.useMemo(()=>{if(t!=null)return ym++,ym},[t])}const eE=pe.memo(t=>{let{adjustScale:e=!1,children:n,dropAnimation:s,style:r,transition:i,modifiers:o,wrapperElement:a="div",className:l,zIndex:c=999}=t;const{activatorEvent:d,active:f,activeNodeRect:h,containerNodeRect:p,draggableNodes:m,droppableContainers:g,dragOverlay:b,over:y,measuringConfiguration:x,scrollableAncestors:v,scrollableAncestorRects:_,windowRect:w}=kv(),k=S.useContext(Ec),C=Z2(f==null?void 0:f.id),j=_v(o,{activatorEvent:d,active:f,activeNodeRect:h,containerNodeRect:p,draggingNodeRect:b.rect,over:y,overlayNodeRect:b.rect,scrollableAncestors:v,scrollableAncestorRects:_,transform:k,windowRect:w}),M=fh(h),E=G2({config:s,draggableNodes:m,droppableContainers:g,measuringConfiguration:x}),P=M?b.setRef:void 0;return pe.createElement(H2,null,pe.createElement(U2,{animation:E},f&&C?pe.createElement(K2,{key:C,id:f.id,ref:P,as:a,activatorEvent:d,adjustScale:e,className:l,transition:i,rect:M,style:{zIndex:c,...r},transform:j},n):null))});function jv(t,e,n){const s=t.slice();return s.splice(n<0?s.length+n:n,0,s.splice(e,1)[0]),s}function tE(t,e){return t.reduce((n,s,r)=>{const i=e.get(s);return i&&(n[r]=i),n},Array(t.length))}function Wa(t){return t!==null&&t>=0}function nE(t,e){if(t===e)return!0;if(t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(t[n]!==e[n])return!1;return!0}function sE(t){return typeof t=="boolean"?{draggable:t,droppable:t}:t}const Nv=t=>{let{rects:e,activeIndex:n,overIndex:s,index:r}=t;const i=jv(e,s,n),o=e[r],a=i[r];return!a||!o?null:{x:a.left-o.left,y:a.top-o.top,scaleX:a.width/o.width,scaleY:a.height/o.height}},Ha={scaleX:1,scaleY:1},rE=t=>{var e;let{activeIndex:n,activeNodeRect:s,index:r,rects:i,overIndex:o}=t;const a=(e=i[n])!=null?e:s;if(!a)return null;if(r===n){const c=i[o];return c?{x:0,y:n<o?c.top+c.height-(a.top+a.height):c.top-a.top,...Ha}:null}const l=iE(i,r,n);return r>n&&r<=o?{x:0,y:-a.height-l,...Ha}:r<n&&r>=o?{x:0,y:a.height+l,...Ha}:{x:0,y:0,...Ha}};function iE(t,e,n){const s=t[e],r=t[e-1],i=t[e+1];return s?n<e?r?s.top-(r.top+r.height):i?i.top-(s.top+s.height):0:i?i.top-(s.top+s.height):r?s.top-(r.top+r.height):0:0}const Ev="Sortable",Mv=pe.createContext({activeIndex:-1,containerId:Ev,disableTransforms:!1,items:[],overIndex:-1,useDragOverlay:!1,sortedRects:[],strategy:Nv,disabled:{draggable:!1,droppable:!1}});function oE(t){let{children:e,id:n,items:s,strategy:r=Nv,disabled:i=!1}=t;const{active:o,dragOverlay:a,droppableRects:l,over:c,measureDroppableContainers:d}=kv(),f=aa(Ev,n),h=a.rect!==null,p=S.useMemo(()=>s.map(k=>typeof k=="object"&&"id"in k?k.id:k),[s]),m=o!=null,g=o?p.indexOf(o.id):-1,b=c?p.indexOf(c.id):-1,y=S.useRef(p),x=!nE(p,y.current),v=b!==-1&&g===-1||x,_=sE(i);Jt(()=>{x&&m&&d(p)},[x,p,m,d]),S.useEffect(()=>{y.current=p},[p]);const w=S.useMemo(()=>({activeIndex:g,containerId:f,disabled:_,disableTransforms:v,items:p,overIndex:b,useDragOverlay:h,sortedRects:tE(p,l),strategy:r}),[g,f,_.draggable,_.droppable,v,p,b,l,h,r]);return pe.createElement(Mv.Provider,{value:w},e)}const aE=t=>{let{id:e,items:n,activeIndex:s,overIndex:r}=t;return jv(n,s,r).indexOf(e)},lE=t=>{let{containerId:e,isSorting:n,wasDragging:s,index:r,items:i,newIndex:o,previousItems:a,previousContainerId:l,transition:c}=t;return!c||!s||a!==i&&r===o?!1:n?!0:o!==r&&e===l},cE={duration:200,easing:"ease"},Pv="transform",uE=Ns.Transition.toString({property:Pv,duration:0,easing:"linear"}),dE={roleDescription:"sortable"};function fE(t){let{disabled:e,index:n,node:s,rect:r}=t;const[i,o]=S.useState(null),a=S.useRef(n);return Jt(()=>{if(!e&&n!==a.current&&s.current){const l=r.current;if(l){const c=Ci(s.current,{ignoreTransform:!0}),d={x:l.left-c.left,y:l.top-c.top,scaleX:l.width/c.width,scaleY:l.height/c.height};(d.x||d.y)&&o(d)}}n!==a.current&&(a.current=n)},[e,n,s,r]),S.useEffect(()=>{i&&o(null)},[i]),i}function hE(t){let{animateLayoutChanges:e=lE,attributes:n,disabled:s,data:r,getNewIndex:i=aE,id:o,strategy:a,resizeObserverConfig:l,transition:c=cE}=t;const{items:d,containerId:f,activeIndex:h,disabled:p,disableTransforms:m,sortedRects:g,overIndex:b,useDragOverlay:y,strategy:x}=S.useContext(Mv),v=pE(s,p),_=d.indexOf(o),w=S.useMemo(()=>({sortable:{containerId:f,index:_,items:d},...r}),[f,r,_,d]),k=S.useMemo(()=>d.slice(d.indexOf(o)),[d,o]),{rect:C,node:j,isOver:M,setNodeRef:E}=Cv({id:o,data:w,disabled:v.droppable,resizeObserverConfig:{updateMeasurementsFor:k,...l}}),{active:P,activatorEvent:A,activeNodeRect:Q,attributes:ne,setNodeRef:Y,listeners:oe,isDragging:G,over:O,setActivatorNodeRef:L,transform:I}=z2({id:o,data:w,attributes:{...dE,...n},disabled:v.draggable}),V=wN(E,Y),F=!!P,ce=F&&!m&&Wa(h)&&Wa(b),$=!y&&G,ke=$&&ce?I:null,gt=ce?ke??(a??x)({rects:g,activeNodeRect:Q,activeIndex:h,overIndex:b,index:_}):null,Ft=Wa(h)&&Wa(b)?i({id:o,items:d,activeIndex:h,overIndex:b}):_,zt=P==null?void 0:P.id,ie=S.useRef({activeId:zt,items:d,newIndex:Ft,containerId:f}),ji=d!==ie.current.items,tn=e({active:P,containerId:f,isDragging:G,isSorting:F,id:o,index:_,items:d,newIndex:ie.current.newIndex,previousItems:ie.current.items,previousContainerId:ie.current.containerId,transition:c,wasDragging:ie.current.activeId!=null}),pr=fE({disabled:!tn,index:_,node:j,rect:C});return S.useEffect(()=>{F&&ie.current.newIndex!==Ft&&(ie.current.newIndex=Ft),f!==ie.current.containerId&&(ie.current.containerId=f),d!==ie.current.items&&(ie.current.items=d)},[F,Ft,f,d]),S.useEffect(()=>{if(zt===ie.current.activeId)return;if(zt!=null&&ie.current.activeId==null){ie.current.activeId=zt;return}const gr=setTimeout(()=>{ie.current.activeId=zt},50);return()=>clearTimeout(gr)},[zt]),{active:P,activeIndex:h,attributes:ne,data:w,rect:C,index:_,newIndex:Ft,items:d,isOver:M,isSorting:F,isDragging:G,listeners:oe,node:j,overIndex:b,over:O,setNodeRef:V,setActivatorNodeRef:L,setDroppableNodeRef:E,setDraggableNodeRef:Y,transform:pr??gt,transition:vn()};function vn(){if(pr||ji&&ie.current.newIndex===_)return uE;if(!($&&!jc(A)||!c)&&(F||tn))return Ns.Transition.toString({...c,property:Pv})}}function pE(t,e){var n,s;return typeof t=="boolean"?{draggable:t,droppable:!1}:{draggable:(n=t==null?void 0:t.draggable)!=null?n:e.draggable,droppable:(s=t==null?void 0:t.droppable)!=null?s:e.droppable}}se.Down,se.Right,se.Up,se.Left;function Rv({lead:t,onAbrir:e,emOverlay:n=!1}){const{attributes:s,listeners:r,setNodeRef:i,transform:o,transition:a,isDragging:l}=hE({id:t.id});return u.jsxs("div",{ref:i,...r,...s,style:{transform:Ns.Transform.toString(o),transition:a,opacity:l?.5:1},className:H("bg-white rounded-lg shadow-sm border border-gray-100 p-3 cursor-grab active:cursor-grabbing select-none touch-none",n&&"shadow-xl rotate-2 cursor-grabbing"),onDoubleClick:()=>e==null?void 0:e(t),title:"Arraste para mudar de coluna · duplo clique para editar",children:[u.jsx("p",{className:"text-sm font-semibold text-gray-800 truncate",children:t.nome}),u.jsx("p",{className:"text-xs text-gray-500 mt-0.5",children:na(t.telefone)}),u.jsxs("div",{className:"flex items-center justify-between mt-2",children:[u.jsx("span",{className:"text-[10px] uppercase tracking-wide bg-indigo-50 text-indigo-700 px-1.5 py-0.5 rounded font-medium",children:t.fonte}),u.jsx("span",{className:"text-[10px] text-gray-400",title:"Data de criação",children:new Date(t.criado_em).toLocaleDateString("pt-BR")})]})]})}function gE({etapa:t,leads:e,cor:n,onAbrirLead:s}){const{setNodeRef:r,isOver:i}=Cv({id:t});return u.jsxs("div",{className:"w-72 shrink-0",children:[u.jsxs("div",{className:"flex items-center justify-between px-1 pb-2",children:[u.jsxs("span",{className:"flex items-center gap-2 text-sm font-semibold text-gray-700",children:[u.jsx("span",{className:H("w-2.5 h-2.5 rounded-full",n)}),mn[t]]}),u.jsx("span",{className:"text-xs font-medium text-gray-500 bg-white border border-gray-200 rounded-full px-2 py-0.5 shadow-sm",children:e.length})]}),u.jsx("div",{ref:r,className:H("bg-white rounded-xl p-3 min-h-[420px] transition-colors","shadow-sm border",i?"border-2 border-dashed border-indigo-400 bg-indigo-50":"border-gray-100"),children:u.jsx(oE,{items:e.map(o=>o.id),strategy:rE,children:u.jsxs("div",{className:"space-y-2 max-h-[calc(100vh-320px)] overflow-y-auto pr-0.5",children:[e.length===0&&u.jsxs("div",{className:"text-center text-xs text-gray-400 border-2 border-dashed border-gray-200 rounded-lg py-10 mt-8",children:[u.jsx("i",{className:"fas fa-inbox text-2xl text-gray-300 mb-2 block"}),"Arraste leads para cá"]}),e.map(o=>u.jsx(Rv,{lead:o,onAbrir:s},o.id))]})})})]})}const mE={leads:"bg-blue-500",em_contato:"bg-amber-500",proposta:"bg-violet-500",fechado:"bg-green-500"};function Hi(t,e){if(pt.includes(e))return e;for(const n of pt)if((t[n]||[]).includes(e))return n;return null}function xE({leads:t,onMover:e,onAbrirLead:n}){const[s,r]=S.useState(()=>yE(t)),[i,o]=S.useState(null),a=S.useRef(s),l=AN(LN(dh,{activationConstraint:{distance:6}}));S.useEffect(()=>{r(m=>{const g=new Set(t.map(v=>v.id)),b={};for(const v of pt)b[v]=(m[v]||[]).filter(_=>g.has(_));let y=!1;for(const v of t){const _=Hi(b,v.id);_===null?(b[v.etapa]=[...b[v.etapa]||[],v.id],y=!0):_!==v.etapa&&(b[_]=b[_].filter(w=>w!==v.id),b[v.etapa]=[...b[v.etapa]||[],v.id],y=!0)}const x=pt.every(v=>(b[v]||[]).length===(m[v]||[]).length);return y||!x?b:m})},[t]);const c=S.useCallback(m=>m&&t.find(g=>g.id===m)||null,[t]),d=S.useMemo(()=>c(i),[c,i]),f=m=>{a.current=s,o(String(m.active.id))},h=S.useCallback(m=>{const{active:g,over:b}=m;if(!b)return;const y=String(g.id),x=String(b.id);r(v=>{const _=Hi(v,y),w=Hi(v,x);return!_||!w||_===w?v:{...v,[_]:v[_].filter(k=>k!==y),[w]:[...v[w],y]}})},[]),p=async m=>{o(null);const g=String(m.active.id);if(!m.over){r(a.current);return}const b=Hi(s,String(m.over.id)),y=Hi(a.current,g);!b||!y||b===y||await e(g,b)};return u.jsxs(A2,{sensors:l,collisionDetection:UN,onDragStart:f,onDragOver:h,onDragEnd:p,children:[u.jsx("div",{className:"flex gap-4 overflow-x-auto pb-2",children:pt.map(m=>u.jsx(gE,{etapa:m,cor:mE[m],leads:t.filter(g=>{var b;return(b=s[m])==null?void 0:b.includes(g.id)}),onAbrirLead:n},m))}),u.jsx(eE,{children:d?u.jsx(Rv,{lead:d,emOverlay:!0}):null})]})}function yE(t){const e={leads:[],em_contato:[],proposta:[],fechado:[]};for(const n of t)e[n.etapa]&&e[n.etapa].push(n.id);return e}const vm={nome:"",telefone:"",email:"",fonte:"Manual",etapa:"leads"};function vE(){const{toast:t}=en(),[e,n]=S.useState([]),[s,r]=S.useState(null),[i,o]=S.useState(!1),[a,l]=S.useState(!1),[c,d]=S.useState(null),[f,h]=S.useState({...vm}),[p,m]=S.useState(""),g=S.useCallback(async()=>{n(await W.crm.leadsListar())},[]);S.useEffect(()=>{g().catch(C=>t("erro",C.message))},[g,t]);const b=async(C,j)=>{const M=e;n(E=>E.map(P=>P.id===C?{...P,etapa:j}:P));try{await W.crm.moverLead(C,j),t("sucesso",`Lead movido para "${mn[j]}".`)}catch(E){n(M),t("erro",E instanceof Error?E.message:"Falha ao mover lead.")}},y=async()=>{var C;if(!((C=f.nome)!=null&&C.trim())){t("erro","O nome do lead é obrigatório.");return}try{await W.crm.criarLead({...f,etapa:f.etapa||"leads"}),t("sucesso","Lead criado com sucesso."),l(!1),h({...vm}),await g()}catch(j){t("erro",j instanceof Error?j.message:"Falha ao criar lead.")}},x=async()=>{o(!0);try{const C=await W.crm.sugestoes();r(C.sugestoes)}catch(C){t("erro",C instanceof Error?C.message:"Falha ao pedir sugestões.")}finally{o(!1)}},v=async C=>{try{await W.crm.aplicar(C.lead_id,C.para),r(j=>(j==null?void 0:j.filter(M=>M!==C))??null),await g(),t("sucesso",`Sugestão aplicada: ${C.lead_nome} → ${mn[C.para]}.`)}catch(j){t("erro",j instanceof Error?j.message:"Falha ao aplicar sugestão.")}},_=async C=>{try{(await W.leads.enriquecer(C.id)).notas.forEach(M=>t("info",M)),await g()}catch(j){t("erro",j instanceof Error?j.message:"Falha ao enriquecer.")}},w=async()=>{if(c)try{await W.leads.atualizar(c.id,{observacoes:p}),d(null),await g(),t("sucesso","Observações salvas.")}catch(C){t("erro",C instanceof Error?C.message:"Falha ao salvar.")}},k=S.useMemo(()=>Object.fromEntries(pt.map(C=>[C,e.filter(j=>j.etapa===C).length])),[e]);return u.jsxs("div",{className:"space-y-6",children:[u.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-3",children:[u.jsxs("div",{className:"flex items-center gap-4 text-sm text-gray-500 flex-wrap",children:[u.jsxs("span",{children:[u.jsx("strong",{className:"text-gray-800",children:e.length})," leads no funil"]}),pt.map(C=>u.jsxs("span",{className:"hidden md:inline",children:[mn[C],": ",u.jsx("strong",{className:"text-gray-700",children:k[C]})]},C))]}),u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsxs("button",{onClick:x,disabled:i,className:"px-5 py-2.5 text-sm font-medium text-indigo-600 bg-white border border-indigo-200 rounded-lg hover:bg-indigo-50 transition disabled:opacity-60 shadow-sm",children:[u.jsx("i",{className:H("fas fa-wand-magic-sparkles mr-2",i&&"fa-spin")}),"Sugestões da IA"]}),u.jsxs("button",{onClick:()=>l(!0),className:"px-6 py-2.5 text-sm font-medium text-white bg-gradient-to-r from-indigo-500 to-purple-500 rounded-lg hover:opacity-90 transition shadow-sm",children:[u.jsx("i",{className:"fas fa-plus mr-2"})," Adicionar Lead"]})]})]}),u.jsx(xE,{leads:e,onMover:b,onAbrirLead:C=>{d(C),m(C.observacoes||"")}}),u.jsxs(Xt,{aberto:s!==null,onFechar:()=>r(null),titulo:"Sugestões de movimentação (Agente de CRM)",icone:"fas fa-robot",largura:"lg",children:[s&&s.length===0&&u.jsxs("p",{className:"text-sm text-gray-500 text-center py-8",children:[u.jsx("i",{className:"fas fa-circle-check text-green-500 text-2xl block mb-3"}),"Nenhuma sugestão no momento — o funil está equilibrado. 🎯"]}),u.jsx("div",{className:"space-y-3",children:s==null?void 0:s.map((C,j)=>u.jsxs("div",{className:"border border-gray-100 rounded-xl p-4 flex items-start justify-between gap-4 hover:border-indigo-200 transition",children:[u.jsxs("div",{className:"min-w-0",children:[u.jsx("p",{className:"text-sm font-semibold text-gray-800 truncate",children:C.lead_nome}),u.jsxs("p",{className:"text-xs text-gray-500 mt-1 flex items-center gap-2",children:[u.jsx(sr,{status:C.de})," ",u.jsx("i",{className:"fas fa-arrow-right text-gray-300"})," ",u.jsx(sr,{status:C.para}),u.jsxs("span",{className:"text-gray-400",children:["confiança ",Math.round(C.confianca*100),"%"]})]}),u.jsx("p",{className:"text-xs text-gray-600 mt-2",children:C.motivo})]}),u.jsx("button",{onClick:()=>v(C),className:"shrink-0 px-4 py-2 text-xs font-medium text-white bg-gradient-to-r from-indigo-500 to-purple-500 rounded-lg hover:opacity-90",children:"Aplicar"})]},j))})]}),u.jsx(Xt,{aberto:a,onFechar:()=>l(!1),titulo:"Adicionar Lead",icone:"fas fa-user-plus",children:u.jsxs("div",{className:"space-y-4",children:[u.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[u.jsx(_r,{rotulo:"Nome *",valor:f.nome||"",onChange:C=>h({...f,nome:C})}),u.jsx(_r,{rotulo:"Telefone",valor:f.telefone||"",onChange:C=>h({...f,telefone:C}),placeholder:"(11) 99999-9999"}),u.jsx(_r,{rotulo:"E-mail",tipo:"email",valor:f.email||"",onChange:C=>h({...f,email:C}),placeholder:"contato@empresa.com.br"}),u.jsxs("div",{children:[u.jsx("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"Coluna inicial"}),u.jsx("select",{value:f.etapa||"leads",onChange:C=>h({...f,etapa:C.target.value}),className:"w-full px-3 py-2 text-sm border border-gray-200 rounded-lg focus:ring-2 focus:ring-indigo-400 outline-none",children:pt.map(C=>u.jsx("option",{value:C,children:mn[C]},C))})]})]}),u.jsx(_r,{rotulo:"Fonte",valor:f.fonte||"",onChange:C=>h({...f,fonte:C}),placeholder:"Manual, Google Maps, Instagram, CNPJ..."}),u.jsxs(Qt,{titulo:"Campos avançados",icone:"fas fa-sliders",children:[u.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[u.jsx(_r,{rotulo:"Empresa",valor:f.empresa||"",onChange:C=>h({...f,empresa:C})}),u.jsx(_r,{rotulo:"Cidade",valor:f.cidade||"",onChange:C=>h({...f,cidade:C}),placeholder:"São Paulo/SP"})]}),u.jsxs("div",{children:[u.jsx("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"Observações"}),u.jsx("textarea",{value:f.observacoes||"",onChange:C=>h({...f,observacoes:C.target.value}),rows:3,className:"w-full px-3 py-2 text-sm border border-gray-200 rounded-lg focus:ring-2 focus:ring-indigo-400 outline-none"})]})]}),u.jsxs("div",{className:"flex justify-end gap-3 pt-2",children:[u.jsx("button",{onClick:()=>l(!1),className:"px-4 py-2.5 text-sm font-medium text-gray-600 bg-white border border-gray-200 rounded-lg hover:bg-gray-50",children:"Cancelar"}),u.jsxs("button",{onClick:y,className:"px-6 py-2.5 text-sm font-medium text-white bg-gradient-to-r from-indigo-500 to-purple-500 rounded-lg hover:opacity-90",children:[u.jsx("i",{className:"fas fa-save mr-2"})," Salvar"]})]})]})}),u.jsx(Xt,{aberto:!!c,onFechar:()=>d(null),titulo:"Lead",icone:"fas fa-address-card",children:c&&u.jsxs("div",{className:"space-y-4",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx("p",{className:"text-base font-semibold text-gray-800",children:c.nome}),u.jsxs("p",{className:"text-xs text-gray-500 mt-0.5",children:[na(c.telefone)," · ",c.fonte," · criado em ",Il(c.criado_em)]})]}),u.jsx(sr,{status:c.etapa})]}),u.jsxs("div",{children:[u.jsx("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"Observações"}),u.jsx("textarea",{value:p,onChange:C=>m(C.target.value),rows:4,className:"w-full px-3 py-2 text-sm border border-gray-200 rounded-lg focus:ring-2 focus:ring-indigo-400 outline-none",placeholder:"Ex.: ligou pedindo proposta, retorna na sexta..."})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("button",{onClick:()=>_(c),className:"text-sm text-indigo-600 hover:text-indigo-800 font-medium",children:[u.jsx("i",{className:"fas fa-wand-magic-sparkles mr-1"})," Enriquecer com IA"]}),u.jsxs("div",{className:"flex gap-3",children:[u.jsx("button",{onClick:()=>d(null),className:"px-4 py-2.5 text-sm font-medium text-gray-600 bg-white border border-gray-200 rounded-lg hover:bg-gray-50",children:"Cancelar"}),u.jsxs("button",{onClick:w,className:"px-6 py-2.5 text-sm font-medium text-white bg-gradient-to-r from-indigo-500 to-purple-500 rounded-lg hover:opacity-90",children:[u.jsx("i",{className:"fas fa-save mr-2"})," Salvar"]})]})]})]})})]})}function _r({rotulo:t,valor:e,onChange:n,tipo:s="text",placeholder:r}){return u.jsxs("div",{children:[u.jsx("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:t}),u.jsx("input",{type:s,value:e,onChange:i=>n(i.target.value),placeholder:r,className:"w-full px-3 py-2 text-sm border border-gray-200 rounded-lg focus:ring-2 focus:ring-indigo-400 outline-none"})]})}function bE(){const{toast:t}=en(),[e,n]=S.useState([]),[s,r]=S.useState(!1),[i,o]=S.useState(null),[a,l]=S.useState(""),[c,d]=S.useState(""),[f,h]=S.useState("texto"),[p,m]=S.useState("leads"),g=S.useCallback(async()=>{n(await W.leads.listar())},[]);S.useEffect(()=>{g().catch(w=>t("erro",w.message))},[g,t]);const{data:b=[],refetch:y}=ey({queryKey:["campanhas"],queryFn:()=>W.campanhas.listar(),refetchInterval:w=>{var k;return(k=w.state.data)!=null&&k.some(C=>C.status==="em_andamento")?4e3:!1},refetchIntervalInBackground:!1}),x=S.useMemo(()=>Object.fromEntries(pt.map(w=>[w,e.filter(k=>k.etapa===w).length])),[e]),v=async()=>{if(!a.trim()){t("erro","Dê um nome para a campanha.");return}if(!c.trim()){t("erro","Escreva o template da mensagem.");return}try{await W.campanhas.criar({nome:a.trim(),canal:f,template:f,mensagem:c.trim(),lead_ids:[],filtro_etapa:p});const w=mn[p]??p;t("sucesso",`Campanha criada — ${x[p]??0} leads de "${w}" serão disparados.`),r(!1),l(""),d(""),await y(),await g()}catch(w){t("erro",w instanceof Error?w.message:"Falha ao criar campanha.")}},_=async(w,k)=>{try{await W.campanhas.status(w.id,k),t("sucesso",`Campanha "${w.nome}" → ${k==="ativa"?"Ativa":k==="pausada"?"Pausada":"Rascunho"}.`),await y()}catch(C){t("erro",C instanceof Error?C.message:"Falha ao alterar status.")}};return u.jsxs("div",{className:"space-y-6",children:[u.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-3",children:[u.jsxs("p",{className:"text-sm text-gray-500",children:[u.jsx("strong",{className:"text-gray-800",children:b.length})," campanhas · templates em Agentes"]}),u.jsxs("button",{onClick:()=>r(!0),className:"px-6 py-3 text-sm font-medium text-white bg-gradient-to-r from-indigo-500 to-purple-500 rounded-lg hover:opacity-90 transition shadow-sm",children:[u.jsx("i",{className:"fas fa-plus mr-2"})," Nova Campanha"]})]}),u.jsx("div",{className:"bg-white rounded-xl shadow-sm border border-gray-100 overflow-hidden",children:u.jsx("div",{className:"overflow-x-auto",children:u.jsxs("table",{className:"w-full text-sm",children:[u.jsx("thead",{children:u.jsxs("tr",{className:"text-left text-xs text-gray-500 uppercase border-b border-gray-100 bg-gray-50/50",children:[u.jsx("th",{className:"px-5 py-3 font-semibold",children:"Nome"}),u.jsx("th",{className:"px-5 py-3 font-semibold",children:"Status"}),u.jsx("th",{className:"px-5 py-3 font-semibold",children:"Total de Leads"}),u.jsx("th",{className:"px-5 py-3 font-semibold",children:"Data de Criação"}),u.jsx("th",{className:"px-5 py-3 font-semibold text-right",children:"Ações"})]})}),u.jsxs("tbody",{children:[b.map(w=>{const k=w.status==="em_andamento",C=Math.max(w.total,w.enviadas+w.erros);return u.jsxs("tr",{className:"border-b border-gray-50 hover:bg-indigo-50/40",children:[u.jsxs("td",{className:"px-5 py-3",children:[u.jsx("p",{className:"font-medium text-gray-800 truncate max-w-[220px]",children:w.nome}),u.jsxs("p",{className:"text-xs text-gray-400",children:[w.canal==="audio"?"Áudio":"Texto",' · template "',w.template,'"']})]}),u.jsx("td",{className:"px-5 py-3",children:u.jsx(sr,{status:w.status})}),u.jsx("td",{className:"px-5 py-3 text-gray-600",children:C}),u.jsx("td",{className:"px-5 py-3 text-xs text-gray-400",children:Il(w.criado_em)}),u.jsxs("td",{className:"px-5 py-3 text-right whitespace-nowrap",children:[u.jsxs("button",{onClick:()=>o(w),className:"text-xs text-indigo-600 hover:text-indigo-800 font-medium mr-3",children:[u.jsx("i",{className:"fas fa-list mr-1"})," Ver"]}),k?u.jsxs(u.Fragment,{children:[u.jsxs("button",{onClick:()=>_(w,"pausada"),className:"px-4 py-2 text-xs font-medium text-amber-700 bg-amber-50 border border-amber-200 rounded-lg hover:bg-amber-100 mr-2",children:[u.jsx("i",{className:"fas fa-pause mr-1"})," Pausar"]}),u.jsxs("button",{onClick:()=>_(w,"rascunho"),className:"px-4 py-2 text-xs font-medium text-red-700 bg-red-50 border border-red-200 rounded-lg hover:bg-red-100",children:[u.jsx("i",{className:"fas fa-stop mr-1"})," Parar"]})]}):u.jsxs("button",{onClick:()=>_(w,"ativa"),className:"px-5 py-2 text-xs font-medium text-white bg-gradient-to-r from-indigo-500 to-purple-500 rounded-lg hover:opacity-90",children:[u.jsx("i",{className:"fas fa-play mr-1"})," Iniciar"]})]})]},w.id)}),b.length===0&&u.jsx("tr",{children:u.jsxs("td",{colSpan:5,className:"px-5 py-16 text-center text-gray-400",children:[u.jsx("i",{className:"fas fa-bullhorn text-3xl text-gray-200 block mb-3"}),"Nenhuma campanha ainda. Clique em ",u.jsx("strong",{className:"text-indigo-500",children:"Nova Campanha"})," para começar."]})})]})]})})}),b.filter(w=>w.status==="em_andamento").length>0&&u.jsx("div",{className:"space-y-3",children:b.filter(w=>w.status==="em_andamento").map(w=>{const k=Math.max(w.total,w.enviadas+w.erros),C=k?Math.round((w.enviadas+w.erros)/k*100):0;return u.jsxs("div",{className:"bg-white rounded-xl shadow-sm border border-indigo-100 p-4 space-y-2",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("p",{className:"text-sm font-medium text-gray-700 flex items-center gap-2",children:[u.jsx("i",{className:"fas fa-spinner fa-spin text-indigo-500"})," ",w.nome]}),u.jsxs("span",{className:"text-xs text-gray-500",children:[w.enviadas," enviadas · ",w.erros," erros"]})]}),u.jsx(ra,{valor:C,mostrarLabel:!0})]},w.id)})}),u.jsx(Xt,{aberto:s,onFechar:()=>r(!1),titulo:"Nova Campanha",icone:"fas fa-bullhorn",largura:"lg",children:u.jsxs("div",{className:"space-y-4",children:[u.jsxs("div",{children:[u.jsx("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"Nome da Campanha *"}),u.jsx("input",{value:a,onChange:w=>l(w.target.value),placeholder:"Ex.: Reativação de novos leads",className:"w-full px-3 py-2 text-sm border border-gray-200 rounded-lg focus:ring-2 focus:ring-indigo-400 outline-none"})]}),u.jsxs("div",{children:[u.jsx("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"Template da Mensagem *"}),u.jsx("textarea",{value:c,onChange:w=>d(w.target.value),rows:4,placeholder:"Use variáveis: {{nome}}, {{primeiro_nome}}, {{empresa}}, {{cidade}}...",className:"w-full px-3 py-2 text-sm border border-gray-200 rounded-lg focus:ring-2 focus:ring-indigo-400 outline-none font-mono"}),u.jsxs("p",{className:"text-[11px] text-gray-400 mt-1",children:["Variáveis: ",u.jsx("code",{className:"bg-gray-100 px-1 rounded",children:"{{nome}}"}),","," ",u.jsx("code",{className:"bg-gray-100 px-1 rounded",children:"{{primeiro_nome}}"}),","," ",u.jsx("code",{className:"bg-gray-100 px-1 rounded",children:"{{empresa}}"}),","," ",u.jsx("code",{className:"bg-gray-100 px-1 rounded",children:"{{cidade}}"})]})]}),u.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[u.jsxs("div",{children:[u.jsx("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"Canal"}),u.jsxs("select",{value:f,onChange:w=>h(w.target.value),className:"w-full px-3 py-2 text-sm border border-gray-200 rounded-lg focus:ring-2 focus:ring-indigo-400 outline-none",children:[u.jsx("option",{value:"texto",children:"Texto"}),u.jsx("option",{value:"audio",children:"Áudio"})]})]}),u.jsxs("div",{children:[u.jsx("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"Filtrar Leads por Etapa do CRM"}),u.jsx("select",{value:p,onChange:w=>m(w.target.value),className:"w-full px-3 py-2 text-sm border border-gray-200 rounded-lg focus:ring-2 focus:ring-indigo-400 outline-none",children:pt.map(w=>u.jsxs("option",{value:w,children:[mn[w]," (",x[w]??0," leads)"]},w))})]})]}),u.jsxs("p",{className:"text-xs text-gray-400 bg-gray-50 border border-gray-100 rounded-lg px-3 py-2",children:[u.jsx("i",{className:"fas fa-circle-info mr-1"})," O envio simulado altera o status no JSON. A integração real (OpenOutreach) é validada na hora de iniciar — configure em Ferramentas."]}),u.jsxs("div",{className:"flex justify-end gap-3 pt-1",children:[u.jsx("button",{onClick:()=>r(!1),className:"px-4 py-2.5 text-sm font-medium text-gray-600 bg-white border border-gray-200 rounded-lg hover:bg-gray-50",children:"Cancelar"}),u.jsxs("button",{onClick:v,className:"px-6 py-2.5 text-sm font-medium text-white bg-gradient-to-r from-indigo-500 to-purple-500 rounded-lg hover:opacity-90",children:[u.jsx("i",{className:"fas fa-plus mr-2"})," Criar Campanha"]})]})]})}),u.jsx(Xt,{aberto:!!i,onFechar:()=>o(null),titulo:`Eventos — ${(i==null?void 0:i.nome)??""}`,icone:"fas fa-list",largura:"lg",children:i&&u.jsxs("div",{className:"space-y-2 max-h-96 overflow-y-auto",children:[i.eventos.length===0&&u.jsx("p",{className:"text-sm text-gray-400 text-center py-8",children:"Nenhum evento ainda — a execução do disparo é simulada nesta fase."}),i.eventos.slice().reverse().map((w,k)=>{var C;return u.jsxs("div",{className:"flex items-start gap-3 text-sm border-b border-gray-50 pb-2",children:[u.jsx("i",{className:H("mt-1 text-xs",w.status==="enviado"?"fas fa-circle-check text-green-500":"fas fa-circle-xmark text-red-500")}),u.jsxs("div",{className:"min-w-0 flex-1",children:[u.jsx("p",{className:"text-gray-700 truncate",children:((C=e.find(j=>j.id===w.lead_id))==null?void 0:C.nome)??w.lead_id}),w.mensagem&&u.jsx("p",{className:"text-xs text-gray-400 truncate",children:w.mensagem})]}),u.jsx("span",{className:"text-xs text-gray-300 shrink-0",children:Il(w.momento)})]},k)})]})})]})}const wE=[{para:"/extrator-maps",icone:"fas fa-map-marked-alt",titulo:"Google Maps",descricao:"Empresas por palavra-chave e localização. Sem scraper configurado, gera mock de 5–10 leads."},{para:"/extrator-instagram",icone:"fab fa-instagram",titulo:"Instagram",descricao:"Seguidores de um perfil público. Sem igmapper configurado, gera mock de 5–10 leads."},{para:"/extrator-cnpj",icone:"fas fa-building",titulo:"CNPJ (B2B)",descricao:"Empresas por CNAE + UF. Sem provedor configurado, gera mock de 5–10 empresas."}];function SE(){const t=bi();return u.jsxs("div",{className:"space-y-6",children:[u.jsxs("p",{className:"text-sm text-gray-500",children:["Selecione uma fonte de leads. Todas salvam diretamente em ",u.jsx("strong",{children:"leads.json"}),", na coluna"," ",u.jsx("strong",{children:'"Novos Leads"'})," do CRM — dados 100% locais."]}),u.jsx("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:wE.map(e=>u.jsxs("button",{onClick:()=>t(e.para),className:"bg-white rounded-xl shadow-sm border border-gray-100 p-6 text-left space-y-3 hover:border-indigo-200 hover:shadow-md transition group",children:[u.jsx("span",{className:"w-11 h-11 rounded-lg bg-indigo-50 text-indigo-600 flex items-center justify-center text-lg group-hover:bg-indigo-100",children:u.jsx("i",{className:e.icone})}),u.jsx("p",{className:"text-sm font-semibold text-gray-800",children:e.titulo}),u.jsx("p",{className:"text-xs text-gray-500 leading-relaxed",children:e.descricao}),u.jsxs("span",{className:"text-xs font-medium text-indigo-600 group-hover:text-indigo-800",children:["Abrir extrator ",u.jsx("i",{className:"fas fa-arrow-right ml-1"})]})]},e.para))})]})}function _E(){const{toast:t}=en(),e=bi(),[n,s]=S.useState(""),[r,i]=S.useState(""),[o,a]=S.useState(10),[l,c]=S.useState(5),[d,f]=S.useState(!1),[h,p]=S.useState(!1),[m,g]=S.useState(0),[b,y]=S.useState(null),[x,v]=S.useState(""),_=async()=>{if(n.trim().length<2||r.trim().length<2){t("erro",'Preencha a palavra-chave e a localização (ex.: "Dentista", "Rio de Janeiro").');return}p(!0),y(null),g(8);const w=setInterval(()=>{g(k=>k<85?k+Math.ceil((90-k)/6):85)},90);try{const k=await W.extrair.maps({keyword:n.trim(),location:r.trim(),limit:o});clearInterval(w),g(100),y(k.importados),v(k.origem==="cli"?"scraper real":"mock de teste");const C=k.duplicados>0?` · ${k.duplicados} duplicados ignorados`:"",j=k.aviso?` · ${k.aviso}`:"";t("sucesso",`${k.importados.length} leads extraídos (${k.origem==="cli"?"scraper real":"mock"})${C}${j}`)}catch(k){clearInterval(w),g(0),t("erro",k instanceof Error?k.message:"Falha na extração.")}finally{p(!1)}};return u.jsxs("div",{className:"space-y-6 max-w-4xl",children:[u.jsxs("div",{className:"bg-white rounded-xl shadow-sm border border-gray-100 p-6 space-y-5",children:[u.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-2",children:[u.jsxs("p",{className:"text-sm text-gray-500",children:["Busque empresas por palavra-chave e localização. Sem scraper configurado, o LeadMaster gera",u.jsx("strong",{children:" dados mockados (5–10 leads)"})," para teste — sem risco de bloqueio de IP."]}),u.jsxs("span",{className:"text-xs shrink-0 text-gray-400",children:[u.jsx("i",{className:"fas fa-shield-halved mr-1"})," dados públicos"]})]}),u.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[u.jsxs("div",{children:[u.jsx("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"Palavra-chave *"}),u.jsx("input",{value:n,onChange:w=>s(w.target.value),placeholder:"Ex.: Dentista, pizzaria, academia...",className:"w-full px-3 py-2.5 text-sm border border-gray-200 rounded-lg focus:ring-2 focus:ring-indigo-400 outline-none"})]}),u.jsxs("div",{children:[u.jsx("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"Localização *"}),u.jsx("input",{value:r,onChange:w=>i(w.target.value),placeholder:"Ex.: Rio de Janeiro, RJ",className:"w-full px-3 py-2.5 text-sm border border-gray-200 rounded-lg focus:ring-2 focus:ring-indigo-400 outline-none"})]}),u.jsxs("div",{children:[u.jsxs("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:["Quantidade: ",o]}),u.jsx("input",{type:"range",min:5,max:10,value:o,onChange:w=>a(Number(w.target.value)),className:"w-full accent-indigo-500 mt-2"})]})]}),u.jsxs("button",{onClick:_,disabled:h,className:"w-full md:w-auto px-8 py-3.5 text-sm font-medium text-white bg-gradient-to-r from-indigo-500 to-purple-500 rounded-lg hover:opacity-90 transition disabled:opacity-60 shadow-sm",children:[u.jsx("i",{className:H("fas fa-magnifying-glass mr-2",h&&"fa-spin")}),h?"Buscando leads...":"Iniciar Extração"]}),(h||m>0)&&u.jsxs("div",{className:"space-y-1",children:[u.jsx(ra,{valor:m}),u.jsx("p",{className:"text-xs text-indigo-600 font-medium",children:m<100?"Buscando leads no Google Maps...":"Extração concluída ✓"})]}),u.jsxs(Qt,{titulo:"Configurações avançadas",icone:"fas fa-sliders",children:[u.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[u.jsxs("div",{children:[u.jsxs("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:["Raio de busca: ",l," km"]}),u.jsx("input",{type:"range",min:1,max:50,value:l,onChange:w=>c(Number(w.target.value)),className:"w-full accent-indigo-500"})]}),u.jsxs("label",{className:"flex items-center gap-2 text-sm text-gray-600 bg-gray-50 border border-gray-100 rounded-lg px-3 py-2.5 cursor-pointer h-fit",children:[u.jsx("input",{type:"checkbox",checked:d,onChange:w=>f(w.target.checked),className:"w-4 h-4 accent-indigo-500"}),"Apenas com nota ≥ 4,5"]})]}),u.jsx("p",{className:"text-[11px] text-gray-400",children:"As opções avançadas aplicam-se ao scraper real (gosom/google-maps-scraper), quando configurado em Ferramentas → Extratores. No modo mock elas são ignoradas."})]})]}),b&&u.jsxs("div",{className:"bg-white rounded-xl shadow-sm border border-gray-100 overflow-hidden",children:[u.jsxs("div",{className:"flex items-center justify-between px-5 py-3 border-b border-gray-100 bg-gray-50/50",children:[u.jsxs("p",{className:"text-sm font-medium text-gray-700",children:[b.length," lead(s) extraído(s) · origem: ",u.jsx("span",{className:"text-indigo-600",children:x})]}),u.jsxs("button",{onClick:()=>e("/crm"),className:"px-5 py-2 text-xs font-medium text-indigo-600 bg-white border border-indigo-200 rounded-lg hover:bg-indigo-50",children:[u.jsx("i",{className:"fas fa-columns mr-1"})," Ir para o CRM"]})]}),u.jsx("div",{className:"overflow-x-auto",children:u.jsxs("table",{className:"w-full text-sm",children:[u.jsx("thead",{children:u.jsxs("tr",{className:"text-left text-xs text-gray-500 uppercase border-b border-gray-100",children:[u.jsx("th",{className:"px-5 py-2 font-semibold",children:"Nome"}),u.jsx("th",{className:"px-5 py-2 font-semibold",children:"Telefone"}),u.jsx("th",{className:"px-5 py-2 font-semibold",children:"Localização"}),u.jsx("th",{className:"px-5 py-2 font-semibold",children:"Avaliação"})]})}),u.jsx("tbody",{children:b.map((w,k)=>{var j;const C=(j=w.extras)==null?void 0:j.avaliacao;return u.jsxs("tr",{className:"border-b border-gray-50 hover:bg-indigo-50/40",children:[u.jsx("td",{className:"px-5 py-2.5 text-gray-800",children:w.nome}),u.jsx("td",{className:"px-5 py-2.5 text-gray-600",children:na(w.telefone)}),u.jsxs("td",{className:"px-5 py-2.5 text-gray-500 text-xs",children:[w.cidade||"—",w.endereco?` · ${w.endereco}`:""]}),u.jsx("td",{className:"px-5 py-2.5 text-xs text-gray-400",children:C!==void 0?u.jsxs(u.Fragment,{children:[u.jsx("i",{className:"fas fa-star text-amber-400 mr-1"}),C]}):"—"})]},w.id||k)})})]})}),u.jsx("div",{className:"px-5 py-3 border-t border-gray-100 bg-gray-50/50",children:u.jsxs("button",{onClick:()=>e("/crm"),className:"text-xs text-indigo-600 hover:text-indigo-800 font-medium",children:[u.jsx("i",{className:"fas fa-arrow-right mr-1"})," Ver todos os leads no CRM Kanban"]})})]})]})}function kE(){const{toast:t}=en(),e=bi(),[n,s]=S.useState(""),[r,i]=S.useState(10),[o,a]=S.useState(!1),[l,c]=S.useState(500),[d,f]=S.useState(!1),[h,p]=S.useState(0),[m,g]=S.useState(null),[b,y]=S.useState(""),x=async()=>{if(!n.includes("instagram.com")){t("erro","Informe a URL do perfil (ex.: https://instagram.com/perfil).");return}f(!0),g(null),p(8);const v=setInterval(()=>{p(_=>_<85?_+Math.ceil((90-_)/6):85)},90);try{const _=await W.extrair.instagram(n.trim(),r);clearInterval(v),p(100),g(_.importados),y(_.origem==="cli"?"igmapper real":"mock de teste");const w=_.duplicados>0?` · ${_.duplicados} duplicados ignorados`:"",k=_.aviso?` · ${_.aviso}`:"";t("sucesso",`${_.importados.length} leads extraídos (${_.origem==="cli"?"igmapper real":"mock"})${w}${k}`)}catch(_){clearInterval(v),p(0),t("erro",_ instanceof Error?_.message:"Falha na extração.")}finally{f(!1)}};return u.jsxs("div",{className:"space-y-6 max-w-4xl",children:[u.jsxs("div",{className:"bg-white rounded-xl shadow-sm border border-gray-100 p-6 space-y-5",children:[u.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-2",children:[u.jsxs("p",{className:"text-sm text-gray-500",children:["Extraia seguidores de um perfil público do Instagram. Sem igmapper configurado, o LeadMaster gera",u.jsx("strong",{children:" dados mockados (5–10 leads)"})," para teste — sem risco de bloqueio de conta."]}),u.jsxs("span",{className:"text-xs shrink-0 text-gray-400",children:[u.jsx("i",{className:"fas fa-shield-halved mr-1"})," perfis públicos"]})]}),u.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[u.jsxs("div",{className:"md:col-span-2",children:[u.jsx("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"URL do perfil *"}),u.jsx("input",{value:n,onChange:v=>s(v.target.value),placeholder:"https://instagram.com/perfil_do_concorrente/",className:"w-full px-3 py-2.5 text-sm border border-gray-200 rounded-lg focus:ring-2 focus:ring-indigo-400 outline-none"})]}),u.jsxs("div",{children:[u.jsxs("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:["Quantidade de seguidores: ",r]}),u.jsx("input",{type:"range",min:5,max:10,value:r,onChange:v=>i(Number(v.target.value)),className:"w-full accent-indigo-500 mt-2"})]})]}),u.jsxs("button",{onClick:x,disabled:d,className:"w-full md:w-auto px-8 py-3.5 text-sm font-medium text-white bg-gradient-to-r from-indigo-500 to-purple-500 rounded-lg hover:opacity-90 transition disabled:opacity-60 shadow-sm",children:[u.jsx("i",{className:H("fab fa-instagram mr-2",d&&"fa-spin")}),d?"Buscando seguidores...":"Iniciar Extração"]}),(d||h>0)&&u.jsxs("div",{className:"space-y-1",children:[u.jsx(ra,{valor:h}),u.jsx("p",{className:"text-xs text-indigo-600 font-medium",children:h<100?"Buscando seguidores no Instagram...":"Extração concluída ✓"})]}),u.jsxs(Qt,{titulo:"Configurações avançadas",icone:"fas fa-sliders",children:[u.jsxs("label",{className:"flex items-center gap-2 text-sm text-gray-600 bg-gray-50 border border-gray-100 rounded-lg px-3 py-2.5 cursor-pointer",children:[u.jsx("input",{type:"checkbox",checked:o,onChange:v=>a(v.target.checked),className:"w-4 h-4 accent-indigo-500"}),"Extrair apenas contas comerciais"]}),u.jsxs("div",{children:[u.jsxs("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:["Mínimo de seguidores: ",l]}),u.jsx("input",{type:"range",min:100,max:5e3,step:100,value:l,onChange:v=>c(Number(v.target.value)),className:"w-full accent-indigo-500"})]}),u.jsx("p",{className:"text-[11px] text-gray-400",children:"As opções avançadas aplicam-se ao igmapper real (lucasoal/igmapper), quando configurado em Ferramentas → Extratores. No modo mock elas são ignoradas."})]})]}),m&&u.jsxs("div",{className:"bg-white rounded-xl shadow-sm border border-gray-100 overflow-hidden",children:[u.jsxs("div",{className:"flex items-center justify-between px-5 py-3 border-b border-gray-100 bg-gray-50/50",children:[u.jsxs("p",{className:"text-sm font-medium text-gray-700",children:[m.length," lead(s) extraído(s) · origem: ",u.jsx("span",{className:"text-indigo-600",children:b})]}),u.jsxs("button",{onClick:()=>e("/crm"),className:"px-5 py-2 text-xs font-medium text-indigo-600 bg-white border border-indigo-200 rounded-lg hover:bg-indigo-50",children:[u.jsx("i",{className:"fas fa-columns mr-1"})," Ir para o CRM"]})]}),u.jsx("div",{className:"overflow-x-auto",children:u.jsxs("table",{className:"w-full text-sm",children:[u.jsx("thead",{children:u.jsxs("tr",{className:"text-left text-xs text-gray-500 uppercase border-b border-gray-100",children:[u.jsx("th",{className:"px-5 py-2 font-semibold",children:"Nome / Username"}),u.jsx("th",{className:"px-5 py-2 font-semibold",children:"Telefone"}),u.jsx("th",{className:"px-5 py-2 font-semibold",children:"Fonte"}),u.jsx("th",{className:"px-5 py-2 font-semibold",children:"Seguidores"})]})}),u.jsx("tbody",{children:m.map((v,_)=>{var C,j;const w=((C=v.extras)==null?void 0:C.username)||"",k=(j=v.extras)==null?void 0:j.seguidores;return u.jsxs("tr",{className:"border-b border-gray-50 hover:bg-indigo-50/40",children:[u.jsxs("td",{className:"px-5 py-2.5 text-gray-800",children:[v.nome,w&&u.jsxs("span",{className:"text-xs text-gray-400 ml-2",children:["@",w]})]}),u.jsx("td",{className:"px-5 py-2.5 text-gray-600",children:na(v.telefone)}),u.jsx("td",{className:"px-5 py-2.5",children:u.jsx("span",{className:"text-[10px] uppercase tracking-wide bg-pink-50 text-pink-700 px-1.5 py-0.5 rounded font-medium",children:v.fonte})}),u.jsx("td",{className:"px-5 py-2.5 text-xs text-gray-400",children:k!==void 0?k.toLocaleString("pt-BR"):"—"})]},v.id||_)})})]})}),u.jsx("div",{className:"px-5 py-3 border-t border-gray-100 bg-gray-50/50",children:u.jsxs("button",{onClick:()=>e("/crm"),className:"text-xs text-indigo-600 hover:text-indigo-800 font-medium",children:[u.jsx("i",{className:"fas fa-arrow-right mr-1"})," Ver todos os leads no CRM Kanban"]})})]})]})}const CE=["AC","AL","AP","AM","BA","CE","DF","ES","GO","MA","MT","MS","MG","PA","PB","PR","PE","PI","RJ","RN","RS","RO","RR","SC","SP","SE","TO"];function jE(){const{toast:t}=en(),e=bi(),[n,s]=S.useState(""),[r,i]=S.useState("SP"),[o,a]=S.useState(10),[l,c]=S.useState(""),[d,f]=S.useState(0),[h,p]=S.useState(!1),[m,g]=S.useState(0),[b,y]=S.useState(null),[x,v]=S.useState(""),[_,w]=S.useState(""),[k,C]=S.useState(!1),j=async()=>{if(n.trim().length<2){t("erro","Informe o CNAE (ex.: 6201-5/01 — desenvolvimento de software).");return}p(!0),y(null),g(8);const E=setInterval(()=>{g(P=>P<85?P+Math.ceil((90-P)/6):85)},90);try{const P=await W.extrair.cnpjExtract({cnae:n.trim(),uf:r,limit:o});clearInterval(E),g(100),y(P.importados),v(P.origem==="provedor"?"provedor real":"mock de teste");const A=P.duplicados>0?` · ${P.duplicados} duplicados ignorados`:"",Q=P.aviso?` · ${P.aviso}`:"";t("sucesso",`${P.importados.length} empresas extraídas (${P.origem==="provedor"?"provedor real":"mock"})${A}${Q}`)}catch(P){clearInterval(E),g(0),t("erro",P instanceof Error?P.message:"Falha na extração.")}finally{p(!1)}},M=async()=>{const E=_.trim();if(E.length<8){t("erro","Informe um CNPJ completo (14 dígitos, com ou sem pontuação).");return}C(!0);try{const P=await W.extrair.cnpj(E),A=await W.leads.importar([P]);t("sucesso",`${A.importados.length} lead(s) importado(s) para "Novos Leads"${A.duplicados.length?` · ${A.duplicados.length} duplicado(s)`:""}.`),w("")}catch(P){t("erro",P instanceof Error?P.message:"Falha ao consultar o CNPJ.")}finally{C(!1)}};return u.jsxs("div",{className:"space-y-6 max-w-4xl",children:[u.jsxs("div",{className:"bg-white rounded-xl shadow-sm border border-gray-100 p-6 space-y-5",children:[u.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-2",children:[u.jsxs("p",{className:"text-sm text-gray-500",children:["Busque empresas por CNAE e estado. Sem provedor configurado, o LeadMaster gera",u.jsx("strong",{children:" dados mockados (5–10 empresas)"})," para teste — sem risco de bloqueio."]}),u.jsxs("span",{className:"text-xs shrink-0 text-gray-400",children:[u.jsx("i",{className:"fas fa-shield-halved mr-1"})," dados B2B"]})]}),u.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[u.jsxs("div",{children:[u.jsx("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"CNAE *"}),u.jsx("input",{value:n,onChange:E=>s(E.target.value),placeholder:"Ex.: 6201-5/01 (desenvolvimento de software)",className:"w-full px-3 py-2.5 text-sm border border-gray-200 rounded-lg focus:ring-2 focus:ring-indigo-400 outline-none"})]}),u.jsxs("div",{children:[u.jsx("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"UF *"}),u.jsx("select",{value:r,onChange:E=>i(E.target.value),className:"w-full px-3 py-2.5 text-sm border border-gray-200 rounded-lg focus:ring-2 focus:ring-indigo-400 outline-none bg-white",children:CE.map(E=>u.jsx("option",{value:E,children:E},E))})]}),u.jsxs("div",{children:[u.jsxs("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:["Quantidade: ",o]}),u.jsx("input",{type:"range",min:5,max:10,value:o,onChange:E=>a(Number(E.target.value)),className:"w-full accent-indigo-500 mt-2"})]})]}),u.jsxs("button",{onClick:j,disabled:h,className:"w-full md:w-auto px-8 py-3.5 text-sm font-medium text-white bg-gradient-to-r from-indigo-500 to-purple-500 rounded-lg hover:opacity-90 transition disabled:opacity-60 shadow-sm",children:[u.jsx("i",{className:H("fas fa-building mr-2",h&&"fa-spin")}),h?"Buscando empresas...":"Iniciar Extração"]}),(h||m>0)&&u.jsxs("div",{className:"space-y-1",children:[u.jsx(ra,{valor:m}),u.jsx("p",{className:"text-xs text-indigo-600 font-medium",children:m<100?"Buscando empresas por CNAE...":"Extração concluída ✓"})]}),u.jsxs(Qt,{titulo:"Configurações avançadas",icone:"fas fa-sliders",children:[u.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[u.jsxs("div",{children:[u.jsx("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"Porte da empresa"}),u.jsxs("select",{value:l,onChange:E=>c(E.target.value),className:"w-full px-3 py-2.5 text-sm border border-gray-200 rounded-lg focus:ring-2 focus:ring-indigo-400 outline-none bg-white",children:[u.jsx("option",{value:"",children:"Todos"}),u.jsx("option",{value:"ME",children:"ME (Microempresa)"}),u.jsx("option",{value:"EPP",children:"EPP (Pequeno porte)"}),u.jsx("option",{value:"medio",children:"Médio porte"}),u.jsx("option",{value:"grande",children:"Grande porte"})]})]}),u.jsxs("div",{children:[u.jsxs("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:["Capital social mínimo: ",d.toLocaleString("pt-BR",{style:"currency",currency:"BRL",maximumFractionDigits:0})]}),u.jsx("input",{type:"range",min:0,max:5e6,step:1e5,value:d,onChange:E=>f(Number(E.target.value)),className:"w-full accent-indigo-500"})]})]}),u.jsx("p",{className:"text-[11px] text-gray-400",children:"Os filtros de porte e capital social aplicam-se ao provedor real de busca, quando configurado em Ferramentas → Extratores. No modo mock eles são ignorados."})]}),u.jsxs("div",{className:"pt-1 border-t border-gray-100",children:[u.jsxs("p",{className:"text-xs font-medium text-gray-500 mb-2",children:[u.jsx("i",{className:"fas fa-magnifying-glass mr-1"})," Consulta avulsa por CNPJ (BrasilAPI) — importa uma empresa específica"]}),u.jsxs("div",{className:"flex flex-wrap gap-3",children:[u.jsx("input",{value:_,onChange:E=>w(E.target.value),placeholder:"00.000.000/0000-00",className:"flex-1 min-w-[220px] px-3 py-2.5 text-sm border border-gray-200 rounded-lg focus:ring-2 focus:ring-indigo-400 outline-none"}),u.jsxs("button",{onClick:M,disabled:k,className:"px-5 py-2.5 text-xs font-medium text-indigo-600 bg-white border border-indigo-200 rounded-lg hover:bg-indigo-50 disabled:opacity-60",children:[u.jsx("i",{className:H("fas fa-file-import mr-1",k&&"fa-spin")}),k?"Importando...":"Consultar e importar"]})]})]})]}),b&&u.jsxs("div",{className:"bg-white rounded-xl shadow-sm border border-gray-100 overflow-hidden",children:[u.jsxs("div",{className:"flex items-center justify-between px-5 py-3 border-b border-gray-100 bg-gray-50/50",children:[u.jsxs("p",{className:"text-sm font-medium text-gray-700",children:[b.length," lead(s) extraído(s) · origem: ",u.jsx("span",{className:"text-indigo-600",children:x})]}),u.jsxs("button",{onClick:()=>e("/crm"),className:"px-5 py-2 text-xs font-medium text-indigo-600 bg-white border border-indigo-200 rounded-lg hover:bg-indigo-50",children:[u.jsx("i",{className:"fas fa-columns mr-1"})," Ir para o CRM"]})]}),u.jsx("div",{className:"overflow-x-auto",children:u.jsxs("table",{className:"w-full text-sm",children:[u.jsx("thead",{children:u.jsxs("tr",{className:"text-left text-xs text-gray-500 uppercase border-b border-gray-100",children:[u.jsx("th",{className:"px-5 py-2 font-semibold",children:"Nome Fantasia"}),u.jsx("th",{className:"px-5 py-2 font-semibold",children:"CNPJ"}),u.jsx("th",{className:"px-5 py-2 font-semibold",children:"Cidade / UF"}),u.jsx("th",{className:"px-5 py-2 font-semibold",children:"Telefone"}),u.jsx("th",{className:"px-5 py-2 font-semibold",children:"Fonte"})]})}),u.jsx("tbody",{children:b.map((E,P)=>u.jsxs("tr",{className:"border-b border-gray-50 hover:bg-indigo-50/40",children:[u.jsx("td",{className:"px-5 py-2.5 text-gray-800",children:E.nome}),u.jsx("td",{className:"px-5 py-2.5 text-gray-600 font-mono text-xs",children:E.cnpj||"—"}),u.jsx("td",{className:"px-5 py-2.5 text-gray-500 text-xs",children:E.cidade||"—"}),u.jsx("td",{className:"px-5 py-2.5 text-gray-600",children:na(E.telefone)}),u.jsx("td",{className:"px-5 py-2.5",children:u.jsx("span",{className:"text-[10px] uppercase tracking-wide bg-indigo-50 text-indigo-700 px-1.5 py-0.5 rounded font-medium",children:E.fonte})})]},E.id||P))})]})}),u.jsx("div",{className:"px-5 py-3 border-t border-gray-100 bg-gray-50/50",children:u.jsxs("button",{onClick:()=>e("/crm"),className:"text-xs text-indigo-600 hover:text-indigo-800 font-medium",children:[u.jsx("i",{className:"fas fa-arrow-right mr-1"})," Ver todos os leads no CRM Kanban"]})})]})]})}function NE(){const[t,e]=s_(),n=t.get("tab")||"disparo";return u.jsxs("div",{className:"space-y-6",children:[u.jsx("div",{className:"flex gap-2",children:[{id:"disparo",rotulo:"Agente de Disparo",icone:"fas fa-paper-plane"},{id:"atendimento",rotulo:"Agente de Atendimento",icone:"fas fa-headset"}].map(s=>u.jsxs("button",{onClick:()=>e({tab:s.id}),className:H("px-5 py-2.5 text-sm font-medium rounded-lg transition",n===s.id?"bg-[#1e1b4b] text-white shadow-sm":"bg-white text-gray-600 border border-gray-200 hover:bg-gray-50"),children:[u.jsx("i",{className:H(s.icone,"mr-2")}),s.rotulo]},s.id))}),n==="disparo"?u.jsx(EE,{}):u.jsx(ME,{})]})}function EE(){const{toast:t}=en(),[e,n]=S.useState({texto:"",audio:""}),[s,r]=S.useState("LeadMaster"),[i,o]=S.useState(""),[a,l]=S.useState(!1),[c,d]=S.useState(!1),[f,h]=S.useState(null),p=S.useCallback(async()=>{const[b,y]=await Promise.all([W.agentes.templates(),W.config.obter()]);n({texto:b.texto??"",audio:b.audio??""}),r(y.agentes.disparo.minha_empresa??"LeadMaster"),h(y.integracoes.openoutreach)},[]);S.useEffect(()=>{p().catch(b=>t("erro",b.message))},[p,t]);const m=async()=>{d(!0);try{await W.agentes.salvarTemplates(e),await W.config.salvar({agentes:{disparo:{templates:e,minha_empresa:s}}}),t("sucesso","Templates do agente de disparo salvos."),await p()}catch(b){t("erro",b instanceof Error?b.message:"Falha ao salvar templates.")}finally{d(!1)}},g=async()=>{try{const b=await W.agentes.testarTemplate(e.texto);o(b.renderizado),l(!0)}catch(b){t("erro",b instanceof Error?b.message:"Falha ao renderizar template.")}};return u.jsxs("div",{className:"space-y-5 max-w-3xl",children:[u.jsxs("div",{className:"bg-white rounded-xl shadow-sm border border-gray-100 p-6 space-y-4",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx("h3",{className:"text-sm font-semibold text-gray-800",children:"Templates de mensagem"}),u.jsx(sr,{status:f!=null&&f.url&&f.enabled!==!1?"ativo":"inativo",rotulo:f!=null&&f.url&&f.enabled!==!1?"OpenOutreach configurado":"OpenOutreach não configurado"})]}),u.jsxs("p",{className:"text-xs text-gray-500",children:["Variáveis disponíveis: ",u.jsx("code",{className:"bg-gray-100 px-1 rounded",children:"{{nome}}"}),","," ",u.jsx("code",{className:"bg-gray-100 px-1 rounded",children:"{{primeiro_nome}}"}),","," ",u.jsx("code",{className:"bg-gray-100 px-1 rounded",children:"{{empresa}}"}),","," ",u.jsx("code",{className:"bg-gray-100 px-1 rounded",children:"{{cidade}}"}),","," ",u.jsx("code",{className:"bg-gray-100 px-1 rounded",children:"{{minha_empresa}}"}),"."]}),u.jsxs("div",{children:[u.jsx("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"Template — texto"}),u.jsx("textarea",{value:e.texto,onChange:b=>n({...e,texto:b.target.value}),rows:4,className:"w-full px-3 py-2 text-sm border border-gray-200 rounded-lg focus:ring-2 focus:ring-indigo-400 outline-none"})]}),u.jsxs("div",{children:[u.jsx("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"Template — áudio (texto para gravação)"}),u.jsx("textarea",{value:e.audio,onChange:b=>n({...e,audio:b.target.value}),rows:4,className:"w-full px-3 py-2 text-sm border border-gray-200 rounded-lg focus:ring-2 focus:ring-indigo-400 outline-none"})]}),u.jsxs("div",{children:[u.jsx("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"Nome da sua empresa"}),u.jsx("input",{value:s,onChange:b=>r(b.target.value),className:"w-full max-w-xs px-3 py-2 text-sm border border-gray-200 rounded-lg focus:ring-2 focus:ring-indigo-400 outline-none"})]}),u.jsxs("div",{className:"flex items-center gap-3",children:[u.jsxs("button",{onClick:m,disabled:c,className:"px-6 py-2.5 text-sm font-medium text-white bg-gradient-to-r from-indigo-500 to-purple-500 rounded-lg hover:opacity-90 disabled:opacity-60",children:[u.jsx("i",{className:"fas fa-save mr-2"})," Salvar templates"]}),u.jsxs("button",{onClick:g,className:"px-4 py-2.5 text-sm font-medium text-indigo-600 bg-indigo-50 border border-indigo-200 rounded-lg hover:bg-indigo-100",children:[u.jsx("i",{className:"fas fa-vial mr-2"})," Testar com lead de exemplo"]})]})]}),u.jsxs("div",{className:"bg-white rounded-xl shadow-sm border border-gray-100 p-6 text-sm text-gray-500 space-y-2",children:[u.jsx("p",{className:"font-medium text-gray-700 text-xs uppercase tracking-wide",children:"Como funciona"}),u.jsxs("p",{children:["O envio em massa é executado pelo ",u.jsx("strong",{children:"OpenOutreach"})," (eracle/OpenOutreach). As campanhas ficam na página ",u.jsx("strong",{children:"Disparos"}),"; a validação da integração acontece na hora de iniciar a campanha — sem travas de pré-registro."]})]}),u.jsx(Xt,{aberto:a,onFechar:()=>l(!1),titulo:"Pré-visualização do template",icone:"fas fa-comment-dots",children:u.jsx("div",{className:"bg-gray-50 border border-gray-100 rounded-lg p-4 text-sm text-gray-700 whitespace-pre-wrap",children:i})})]})}function ME(){const{toast:t}=en(),[e,n]=S.useState("texto"),[s,r]=S.useState(""),[i,o]=S.useState([{role:"assistant",content:"Olá! Sou o assistente de atendimento do LeadMaster. Como posso ajudar?"}]),[a,l]=S.useState(""),[c,d]=S.useState(!1),f=S.useCallback(async()=>{const m=await W.config.obter();n(m.agentes.atendimento.modo==="voz"?"voz":"texto"),r(m.integracoes.pipecat.url||"")},[]);S.useEffect(()=>{f().catch(m=>t("erro",m.message))},[f,t]);const h=async m=>{n(m);try{await W.config.salvar({agentes:{atendimento:{modo:m}},integracoes:{pipecat:{url:s}}}),t("sucesso",`Modo de atendimento: ${m==="voz"?"voz (pipecat)":"texto (LLM)"}.`)}catch(g){t("erro",g instanceof Error?g.message:"Falha ao salvar modo.")}},p=async()=>{const m=a.trim();if(!m)return;const g=[...i,{role:"user",content:m}];o(g),l(""),d(!0);try{const b=await W.agentes.chat(g.map(y=>({role:y.role==="assistant"?"assistant":"user",content:y.content})));b.ok&&b.resposta?o([...g,{role:"assistant",content:b.resposta}]):(o([...g,{role:"assistant",content:`⚠ ${b.mensagem??"Sem resposta."}`}]),t("erro",b.mensagem??"Sem resposta do agente."))}catch(b){t("erro",b instanceof Error?b.message:"Falha no chat.")}finally{d(!1)}};return u.jsxs("div",{className:"space-y-5 max-w-3xl",children:[u.jsxs("div",{className:"bg-white rounded-xl shadow-sm border border-gray-100 p-6 space-y-4",children:[u.jsx("h3",{className:"text-sm font-semibold text-gray-800",children:"Modo do agente de atendimento"}),u.jsx("div",{className:"flex gap-3",children:[{id:"texto",rotulo:"Texto (LLM)",icone:"fas fa-keyboard",descricao:"Chat via LLM configurado"},{id:"voz",rotulo:"Voz (pipecat)",icone:"fas fa-microphone",descricao:"Atendimento por voz"}].map(m=>u.jsxs("button",{onClick:()=>h(m.id),className:H("flex-1 px-4 py-3 rounded-lg border text-left transition",e===m.id?"bg-indigo-50 border-indigo-400":"bg-white border-gray-200 hover:bg-gray-50"),children:[u.jsxs("p",{className:H("text-sm font-medium flex items-center gap-2",e===m.id?"text-indigo-700":"text-gray-600"),children:[u.jsx("i",{className:m.icone})," ",m.rotulo]}),u.jsx("p",{className:"text-xs text-gray-400 mt-1",children:m.descricao})]},m.id))}),e==="voz"&&u.jsxs("div",{children:[u.jsx("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"URL do serviço pipecat"}),u.jsx("input",{value:s,onChange:m=>r(m.target.value),onBlur:()=>h("voz"),placeholder:"http://localhost:5000",className:"w-full max-w-md px-3 py-2 text-sm border border-gray-200 rounded-lg focus:ring-2 focus:ring-indigo-400 outline-none"})]})]}),u.jsxs("div",{className:"bg-white rounded-xl shadow-sm border border-gray-100 p-6",children:[u.jsx("h3",{className:"text-sm font-semibold text-gray-800 mb-3",children:"Testar conversa"}),u.jsxs("div",{className:"space-y-3 max-h-80 overflow-y-auto mb-4",children:[i.map((m,g)=>u.jsx("div",{className:H("flex",m.role==="user"?"justify-end":"justify-start"),children:u.jsx("div",{className:H("max-w-[80%] px-4 py-2.5 rounded-2xl text-sm",m.role==="user"?"bg-indigo-500 text-white rounded-br-sm":"bg-gray-100 text-gray-700 rounded-bl-sm"),children:m.content})},g)),c&&u.jsxs("div",{className:"text-xs text-gray-400 flex items-center gap-2",children:[u.jsx("i",{className:"fas fa-spinner fa-spin"})," pensando..."]})]}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx("input",{value:a,onChange:m=>l(m.target.value),onKeyDown:m=>m.key==="Enter"&&p(),placeholder:"Digite uma mensagem do cliente para testar...",className:"flex-1 px-3 py-2.5 text-sm border border-gray-200 rounded-lg focus:ring-2 focus:ring-indigo-400 outline-none"}),u.jsx("button",{onClick:p,disabled:c,className:"px-5 py-2.5 text-sm font-medium text-white bg-gradient-to-r from-indigo-500 to-purple-500 rounded-lg hover:opacity-90 disabled:opacity-60",children:u.jsx("i",{className:"fas fa-paper-plane"})})]})]})]})}function PE({onConfigSalva:t}){const{toast:e}=en(),[n,s]=S.useState(null),[r,i]=S.useState(!1),[o,a]=S.useState(""),l=S.useCallback(async()=>{const h=await W.config.obter();s(h)},[]);if(S.useEffect(()=>{l().catch(h=>e("erro",h.message))},[l,e]),!n)return u.jsx("div",{className:"text-center text-gray-400 py-16",children:u.jsx("i",{className:"fas fa-spinner fa-spin text-2xl"})});const c=h=>{s(p=>{if(!p)return p;const m=JSON.parse(JSON.stringify(p));return h(m),m})},d=async()=>{i(!0);try{const h=await W.config.salvar(n);s(h),t==null||t(h),e("sucesso","Configurações salvas localmente (config.json).")}catch(h){e("erro",h instanceof Error?h.message:"Falha ao salvar configurações.")}finally{i(!1)}},f=async()=>{a("llm");try{const h=await W.config.testarLlm();e(h.ok?"sucesso":"erro",h.ok?`LLM respondeu: ${h.resposta}`:h.mensagem??"Falha no teste.")}finally{a("")}};return u.jsxs("div",{className:"space-y-6 max-w-4xl",children:[u.jsxs(Va,{titulo:"LLM (agentes de IA)",icone:"fas fa-brain",children:[u.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[u.jsx(an,{rotulo:"Base URL",valor:n.llm.base_url,onChange:h=>c(p=>{p.llm.base_url=h}),placeholder:"https://api.openai.com/v1"}),u.jsx(an,{rotulo:"Modelo",valor:n.llm.modelo,onChange:h=>c(p=>{p.llm.modelo=h}),placeholder:"gpt-4o-mini"}),u.jsx(OE,{rotulo:"API Key",configurado:!!n.llm.api_key_configurado,onChange:h=>c(p=>{p.llm.api_key=h})})]}),u.jsx(TE,{rotulo:"Testar conexão LLM",carregando:o==="llm",onClick:f})]}),u.jsxs(Va,{titulo:"Extratores de leads",icone:"fas fa-magnifying-glass-location",children:[u.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[u.jsx(an,{rotulo:"Google Maps Scraper — binário",valor:n.extratores.google_maps_cli,onChange:h=>c(p=>{p.extratores.google_maps_cli=h}),placeholder:"C:\\ferramentas\\google-maps-scraper.exe"}),u.jsx(an,{rotulo:"igmapper — binário",valor:n.extratores.igmapper_cli,onChange:h=>c(p=>{p.extratores.igmapper_cli=h}),placeholder:"Caminho do CLI igmapper"})]}),u.jsxs(Qt,{titulo:"Argumentos dos scrapers (templates)",icone:"fas fa-terminal",children:[u.jsx(bm,{rotulo:"Google Maps — template de argumentos",valor:n.extratores.google_maps_args,onChange:h=>c(p=>{p.extratores.google_maps_args=h}),linhas:2}),u.jsx(bm,{rotulo:"igmapper — template de argumentos",valor:n.extratores.igmapper_args,onChange:h=>c(p=>{p.extratores.igmapper_args=h}),linhas:2})]}),u.jsxs(Qt,{titulo:"CNPJ e Scrapling",icone:"fas fa-building",children:[u.jsx(an,{rotulo:"Provedor de busca CNAE/UF — URL",valor:n.extratores.cnpj_provedor_busca,onChange:h=>c(p=>{p.extratores.cnpj_provedor_busca=h}),placeholder:"https://api.opencnpj.org"}),u.jsx(an,{rotulo:"Scrapling — binário (scraping profundo)",valor:n.extratores.scrapling_cli,onChange:h=>c(p=>{p.extratores.scrapling_cli=h}),placeholder:"Caminho do CLI Scrapling"})]})]}),u.jsxs(Va,{titulo:"Agentes — integrações",icone:"fas fa-robot",children:[u.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[u.jsx(an,{rotulo:"OpenOutreach — URL",valor:n.integracoes.openoutreach.url,onChange:h=>c(p=>{p.integracoes.openoutreach.url=h}),placeholder:"http://localhost:9090"}),u.jsxs("label",{className:"flex items-center gap-2 text-sm text-gray-600 bg-indigo-50 border border-indigo-100 rounded-lg px-3 py-2.5 cursor-pointer h-fit mt-5",children:[u.jsx("input",{type:"checkbox",checked:n.integracoes.openoutreach.enabled,onChange:h=>c(p=>{p.integracoes.openoutreach.enabled=h.target.checked}),className:"w-4 h-4 accent-indigo-500"}),"OpenOutreach ativo"]})]}),u.jsx(an,{rotulo:"pipecat — URL (atendimento por voz)",valor:n.integracoes.pipecat.url,onChange:h=>c(p=>{p.integracoes.pipecat.url=h}),placeholder:"http://localhost:5000"})]}),u.jsx(Va,{titulo:"Perfil e licença",icone:"fas fa-user",children:u.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[u.jsx(an,{rotulo:"Seu nome",valor:n.perfil.nome,onChange:h=>c(p=>{p.perfil.nome=h})}),u.jsx(an,{rotulo:"Expira em",valor:n.perfil.licenca.expira_em,onChange:h=>c(p=>{p.perfil.licenca.expira_em=h})}),u.jsx(RE,{rotulo:"Dias restantes (vazio = infinito)",valor:n.perfil.licenca.restam_dias??0,onChange:h=>c(p=>{p.perfil.licenca.restam_dias=h>0?h:null})})]})}),u.jsx("div",{className:"flex justify-end",children:u.jsxs("button",{onClick:d,disabled:r,className:"px-8 py-3 text-sm font-medium text-white bg-gradient-to-r from-indigo-500 to-purple-500 rounded-lg hover:opacity-90 transition disabled:opacity-60 shadow-sm",children:[u.jsx("i",{className:H("fas fa-save mr-2",r&&"fa-spin")}),r?"Salvando...":"Salvar configurações"]})})]})}function Va({titulo:t,icone:e,children:n}){return u.jsxs("div",{className:"bg-white rounded-xl shadow-sm border border-gray-100 p-6 space-y-4",children:[u.jsxs("h3",{className:"text-sm font-semibold text-gray-800 flex items-center gap-2",children:[u.jsx("i",{className:H(e,"text-indigo-400")})," ",t]}),n]})}function an({rotulo:t,valor:e,onChange:n,placeholder:s,tipo:r="text"}){return u.jsxs("div",{children:[u.jsx("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:t}),u.jsx("input",{type:r,value:e,onChange:i=>n(i.target.value),placeholder:s,className:"w-full px-3 py-2 text-sm border border-gray-200 rounded-lg focus:ring-2 focus:ring-indigo-400 outline-none"})]})}function RE({rotulo:t,valor:e,onChange:n}){return u.jsxs("div",{children:[u.jsx("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:t}),u.jsx("input",{type:"number",value:e??0,onChange:s=>n(Number(s.target.value)||0),className:"w-full px-3 py-2 text-sm border border-gray-200 rounded-lg focus:ring-2 focus:ring-indigo-400 outline-none"})]})}function OE({rotulo:t,configurado:e,onChange:n}){const[s,r]=S.useState(!1);return u.jsxs("div",{children:[u.jsxs("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:[t," ",e&&u.jsx("span",{className:"text-green-600",children:"• configurado"})]}),u.jsxs("div",{className:"relative",children:[u.jsx("input",{type:s?"text":"password",onChange:i=>n(i.target.value),placeholder:e?"•••••••• (deixe vazio para manter)":"cole a chave aqui",className:"w-full px-3 py-2 pr-10 text-sm border border-gray-200 rounded-lg focus:ring-2 focus:ring-indigo-400 outline-none"}),u.jsx("button",{type:"button",onClick:()=>r(i=>!i),title:s?"Ocultar chave":"Mostrar chave","aria-label":s?"Ocultar chave":"Mostrar chave",className:"absolute inset-y-0 right-0 px-3 text-gray-400 hover:text-indigo-600 transition",children:u.jsx("i",{className:s?"fas fa-eye-slash":"fas fa-eye"})})]})]})}function bm({rotulo:t,valor:e,onChange:n,linhas:s=3}){return u.jsxs("div",{children:[u.jsx("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:t}),u.jsx("textarea",{value:e,onChange:r=>n(r.target.value),rows:s,className:"w-full px-3 py-2 text-xs font-mono border border-gray-200 rounded-lg focus:ring-2 focus:ring-indigo-400 outline-none"})]})}function TE({rotulo:t,onClick:e,carregando:n}){return u.jsxs("button",{onClick:e,disabled:n,className:"text-xs text-indigo-600 hover:text-indigo-800 font-medium disabled:opacity-50",children:[u.jsx("i",{className:H("fas fa-vial-circle-check mr-1",n&&"fa-spin")})," ",t]})}const DE=[{id:"lead.criado",rotulo:"Lead criado"},{id:"lead.etapa",rotulo:"Lead mudou de etapa"},{id:"campanha.concluida",rotulo:"Campanha concluída"}];function LE(){const{toast:t}=en(),[e,n]=S.useState(""),[s,r]=S.useState(new Set),[i,o]=S.useState(""),[a,l]=S.useState(!1),[c,d]=S.useState(!1),f=S.useCallback(async()=>{const g=await W.webhook.obter();n(g.url),r(new Set(g.eventos))},[]);S.useEffect(()=>{f().catch(g=>t("erro",g.message))},[f,t]);const h=g=>r(b=>{const y=new Set(b);return y.has(g)?y.delete(g):y.add(g),y}),p=async()=>{d(!0);try{await W.webhook.salvar({url:e.trim(),eventos:[...s]}),t("sucesso","Webhook salvo.")}catch(g){t("erro",g instanceof Error?g.message:"Falha ao salvar webhook.")}finally{d(!1)}},m=async()=>{if(!e.trim()){t("erro","Informe a URL do webhook antes de testar.");return}try{const g=await W.webhook.testar(e.trim());g.ok?o(`✅ HTTP ${g.status_http} — o endpoint recebeu o evento de teste.
|
|
89
89
|
|
|
90
90
|
${g.resposta??""}`):o(`❌ ${g.mensagem??"Falha no teste."}`),l(!0)}catch(g){t("erro",g instanceof Error?g.message:"Falha no teste.")}};return u.jsxs("div",{className:"space-y-6 max-w-3xl",children:[u.jsxs("div",{className:"bg-white rounded-xl shadow-sm border border-gray-100 p-6 space-y-5",children:[u.jsx("p",{className:"text-sm text-gray-500",children:"Receba eventos do LeadMaster (lead criado, mudança de etapa, campanha concluída) em qualquer endpoint local ou externo — útil para integrar com automações (n8n, Make, Zapier etc.)."}),u.jsxs("div",{children:[u.jsx("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"URL do webhook"}),u.jsx("input",{value:e,onChange:g=>n(g.target.value),placeholder:"https://seu-endpoint.com/webhook",className:"w-full px-3 py-2.5 text-sm border border-gray-200 rounded-lg focus:ring-2 focus:ring-indigo-400 outline-none"})]}),u.jsxs("div",{children:[u.jsx("label",{className:"block text-xs font-medium text-gray-500 mb-2",children:"Eventos enviados"}),u.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-2",children:DE.map(g=>u.jsxs("label",{className:H("flex items-center gap-3 px-4 py-3 rounded-lg border text-sm cursor-pointer transition",s.has(g.id)?"bg-indigo-50 border-indigo-300 text-indigo-700":"bg-white border-gray-200 text-gray-500 hover:bg-gray-50"),children:[u.jsx("input",{type:"checkbox",checked:s.has(g.id),onChange:()=>h(g.id),className:"w-4 h-4 accent-indigo-500"}),g.rotulo,u.jsx("code",{className:"text-[10px] text-gray-400 ml-auto",children:g.id})]},g.id))})]}),u.jsxs("div",{className:"flex items-center gap-3",children:[u.jsxs("button",{onClick:p,disabled:c,className:"px-6 py-2.5 text-sm font-medium text-white bg-gradient-to-r from-indigo-500 to-purple-500 rounded-lg hover:opacity-90 disabled:opacity-60",children:[u.jsx("i",{className:"fas fa-save mr-2"})," Salvar"]}),u.jsxs("button",{onClick:m,className:"px-4 py-2.5 text-sm font-medium text-indigo-600 bg-indigo-50 border border-indigo-200 rounded-lg hover:bg-indigo-100",children:[u.jsx("i",{className:"fas fa-paper-plane mr-2"})," Enviar evento de teste"]})]})]}),u.jsx(Xt,{aberto:a,onFechar:()=>l(!1),titulo:"Resultado do teste",icone:"fas fa-satellite-dish",children:u.jsx("pre",{className:"text-xs text-gray-600 bg-gray-50 rounded-lg p-4 whitespace-pre-wrap",children:i})})]})}function AE(){const{toast:t}=en(),[e,n]=S.useState(null),[s,r]=S.useState(!1),i=async()=>{r(!0);try{n(await W.doctor()),t("sucesso","Diagnóstico concluído.")}catch(o){t("erro",o instanceof Error?o.message:"Falha no diagnóstico.")}finally{r(!1)}};return S.useEffect(()=>{i()},[]),u.jsxs("div",{className:"space-y-6 max-w-3xl",children:[u.jsxs("div",{className:"bg-white rounded-xl shadow-sm border border-gray-100 p-6",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("h3",{className:"text-sm font-semibold text-gray-800 flex items-center gap-2",children:[u.jsx("i",{className:"fas fa-heart-pulse text-indigo-400"})," Diagnóstico do ambiente"]}),u.jsxs("button",{onClick:i,disabled:s,className:"px-4 py-2 text-xs font-medium text-white bg-gradient-to-r from-indigo-500 to-purple-500 rounded-lg hover:opacity-90 disabled:opacity-60",children:[u.jsx("i",{className:H("fas fa-rotate mr-1",s&&"fa-spin")})," Executar novamente"]})]}),e&&u.jsxs("div",{className:"mt-4 space-y-2 text-sm",children:[u.jsx(Vi,{rotulo:"Versão do LeadMaster",valor:e.versao}),u.jsx(Vi,{rotulo:"Python",valor:e.python}),u.jsx(Vi,{rotulo:"Sistema",valor:e.sistema}),u.jsx(Vi,{rotulo:"Interface construída (dist)",valor:e.dist_frontend?"presente":"ausente (modo dev)"}),u.jsx(Vi,{rotulo:"Pasta de dados",valor:e.storage}),u.jsx("div",{className:"pt-2 flex flex-wrap gap-2",children:Object.entries(e.integracoes).map(([o,a])=>u.jsx(sr,{status:a?"ativo":"inativo",rotulo:`${IE(o)}: ${a?"ativo":"inativo"}`},o))})]})]}),u.jsxs("div",{className:"bg-white rounded-xl shadow-sm border border-gray-100 p-6",children:[u.jsxs("h3",{className:"text-sm font-semibold text-gray-800 mb-3",children:[u.jsx("i",{className:"fas fa-circle-question text-indigo-400 mr-2"})," Perguntas frequentes"]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx(Qt,{titulo:"Meus dados ficam na nuvem?",icone:"fas fa-cloud",children:"Não. O LeadMaster é 100% local: todos os dados (leads, campanhas e configuração) ficam em arquivos JSON na sua pasta de dados."}),u.jsx(Qt,{titulo:"Como turbinar os agentes com IA?",icone:"fas fa-brain",children:"Em Ferramentas → LLM, informe base URL, modelo e API key de qualquer API OpenAI-compatível. O agente de CRM passa a enriquecer e sugerir com mais contexto, e o de atendimento conversa por texto. Sem LLM, as heurísticas locais continuam funcionando."}),u.jsx(Qt,{titulo:"Como funcionam os disparos?",icone:"fas fa-paper-plane",children:"As campanhas de Disparos usam o OpenOutreach (eracle/OpenOutreach). Configure a URL em Ferramentas → Agentes — a validação acontece só na hora de iniciar a campanha."}),u.jsx(Qt,{titulo:"Onde reporto problemas?",icone:"fas fa-bug",children:"Abra uma issue em github.com/DanHachuel/LeadMaster ou use a página de diagnóstico acima ao pedir ajuda — ela resume todo o ambiente."})]})]}),u.jsxs("div",{className:"bg-[#1e1b4b] text-white rounded-xl p-6 flex items-center justify-between flex-wrap gap-4",children:[u.jsxs("div",{children:[u.jsx("p",{className:"text-sm font-semibold",children:"LeadMaster — SaaS local de prospecção e automação de conteúdo"}),u.jsx("p",{className:"text-xs text-gray-300 mt-1",children:"Instalável via npx · dados 100% locais · sem mensalidade de nuvem"})]}),u.jsxs("a",{href:"https://github.com/DanHachuel/LeadMaster",target:"_blank",rel:"noreferrer",className:"px-4 py-2.5 text-sm font-medium bg-white/10 hover:bg-white/20 rounded-lg transition",children:[u.jsx("i",{className:"fab fa-github mr-2"})," Repositório"]})]})]})}function Vi({rotulo:t,valor:e}){return u.jsxs("div",{className:"flex items-center justify-between border-b border-gray-50 pb-2",children:[u.jsx("span",{className:"text-xs text-gray-500",children:t}),u.jsx("span",{className:"text-xs font-medium text-gray-700 text-right break-all max-w-[60%]",children:e})]})}function IE(t){return{llm_configurado:"LLM",openoutreach:"OpenOutreach",pipecat:"pipecat"}[t]??t}const FE={"/":"Painel","/leads":"Leads","/agentes":"Agentes","/ferramentas":"Ferramentas","/extratores":"Extratores de Leads","/extrator-maps":"Extrator de Leads — Google Maps","/extrator-instagram":"Extrator de Leads — Instagram","/extrator-cnpj":"Extrator de Leads — CNPJ","/disparos":"Disparos","/crm":"CRM — Kanban","/webhook":"Webhook","/suporte":"Suporte"};function zE(){const[t,e]=S.useState(null),[n,s]=S.useState(!1),[r,i]=S.useState(!1),o=S.useCallback(async()=>{try{e(await W.config.obter())}catch{}},[]);return S.useEffect(()=>{o()},[o]),r?u.jsx("div",{className:"min-h-screen bg-[#1e1b4b] text-white flex items-center justify-center p-8",children:u.jsxs("div",{className:"text-center max-w-md",children:[u.jsx("i",{className:"fas fa-power-off text-4xl text-indigo-300 mb-4 block"}),u.jsx("h1",{className:"text-xl font-bold",children:"LeadMaster encerrado"}),u.jsx("p",{className:"text-sm text-gray-300 mt-3",children:"O servidor local foi desligado com sucesso. Seus dados estão salvos na pasta de dados."}),u.jsxs("p",{className:"text-xs text-gray-400 mt-6",children:["Para voltar, execute: ",u.jsx("code",{className:"bg-white/10 px-2 py-1 rounded",children:"npx --yes @danhachuel/leadmaster"})]})]})}):u.jsx(v_,{children:u.jsxs(GS,{children:[u.jsx(BE,{nomeUsuario:(t==null?void 0:t.perfil.nome)??"...",onSair:()=>s(!0),onConfigSalva:a=>e(a)}),u.jsxs(Xt,{aberto:n,onFechar:()=>s(!1),titulo:"Encerrar o LeadMaster",icone:"fas fa-power-off",children:[u.jsx("p",{className:"text-sm text-gray-600",children:"Isso encerra o servidor local (os processos do terminal também fecham). Seus dados permanecem salvos nos arquivos JSON da pasta de dados. Deseja continuar?"}),u.jsxs("div",{className:"flex justify-end gap-3 mt-6",children:[u.jsx("button",{onClick:()=>s(!1),className:"px-4 py-2.5 text-sm font-medium text-gray-600 bg-white border border-gray-200 rounded-lg hover:bg-gray-50",children:"Cancelar"}),u.jsxs("button",{onClick:async()=>{s(!1);try{await W.shutdown()}catch{}setTimeout(()=>i(!0),400)},className:"px-6 py-2.5 text-sm font-medium text-white bg-gradient-to-r from-indigo-500 to-purple-500 rounded-lg hover:opacity-90",children:[u.jsx("i",{className:"fas fa-power-off mr-2"})," Encerrar"]})]})]})]})})}function BE({nomeUsuario:t,onSair:e,onConfigSalva:n}){const s=Os(),r=FE[s.pathname]??"LeadMaster";return u.jsxs("div",{className:"bg-gray-100 min-h-screen flex",children:[u.jsx(m_,{onSair:e}),u.jsxs("main",{className:"flex-1 flex flex-col min-w-0",children:[u.jsx(p_,{titulo:r,nomeUsuario:t}),u.jsxs("div",{className:"p-8 space-y-6 overflow-y-auto flex-1",children:[u.jsxs(US,{children:[u.jsx(vt,{path:"/",element:u.jsx(gN,{nomeUsuario:t})}),u.jsx(vt,{path:"/leads",element:u.jsx(bN,{})}),u.jsx(vt,{path:"/crm",element:u.jsx(vE,{})}),u.jsx(vt,{path:"/disparos",element:u.jsx(bE,{})}),u.jsx(vt,{path:"/extratores",element:u.jsx(SE,{})}),u.jsx(vt,{path:"/extrator-maps",element:u.jsx(_E,{})}),u.jsx(vt,{path:"/extrator-instagram",element:u.jsx(kE,{})}),u.jsx(vt,{path:"/extrator-cnpj",element:u.jsx(jE,{})}),u.jsx(vt,{path:"/agentes",element:u.jsx(NE,{})}),u.jsx(vt,{path:"/ferramentas",element:u.jsx(PE,{onConfigSalva:n})}),u.jsx(vt,{path:"/webhook",element:u.jsx(LE,{})}),u.jsx(vt,{path:"/suporte",element:u.jsx(AE,{})})]}),u.jsxs("footer",{className:"flex items-center justify-between text-xs text-gray-400 pt-4 border-t border-gray-200",children:[u.jsx("span",{children:"© 2026 LeadMaster. Todos os direitos reservados."}),u.jsx("span",{children:"Dados 100% locais — sem nuvem"})]})]})]})]})}const $E=new W1({defaultOptions:{queries:{retry:1,staleTime:5e3,refetchOnWindowFocus:!0}}});_u.createRoot(document.getElementById("root")).render(u.jsx(pe.StrictMode,{children:u.jsx(x1,{client:$E,children:u.jsx(zE,{})})}));
|