1import{c as u,r as n,j as e,U as X,a2 as $,D as F,a as U,b as q,d as A,e as O,f as Y,B as z,s as M,t as v,a3 as Z}from"./main-BL8THdY_.js";import{A as ee}from"./AdminLayout-w4oWKWEY.js";import{u as se,F as te}from"./use-current-user-0BLrg37k.js";import{T as ae}from"./target-BQI1wYrC.js";import{H as re,T as de}from"./trending-up-DNlcmSjx.js";import{T as V}from"./trash-2-BTMu2kr0.js";import{M as H}from"./mail-CSpp_7mV.js";import{P as I,M as R}from"./phone-Crerl43p.js";import{C as ne}from"./credit-card-CX52l3TF.js";import{C as le}from"./clock-B7mexrkm.js";import"./StationLogo-xzYvyR8Y.js";import"./sparkles-Ku93JdAy.js";const oe=[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"19",cy:"12",r:"1",key:"1wjl8i"}],["circle",{cx:"5",cy:"12",r:"1",key:"1pcz8c"}]],ie=u("ellipsis",oe);const ce=[["path",{d:"M10 20a1 1 0 0 0 .553.895l2 1A1 1 0 0 0 14 21v-7a2 2 0 0 1 .517-1.341L21.74 4.67A1 1 0 0 0 21 3H3a1 1 0 0 0-.742 1.67l7.225 7.989A2 2 0 0 1 10 14z",key:"sc7q7i"}]],xe=u("funnel",ce);const me=[["circle",{cx:"9",cy:"12",r:"1",key:"1vctgf"}],["circle",{cx:"9",cy:"5",r:"1",key:"hp0tcf"}],["circle",{cx:"9",cy:"19",r:"1",key:"fkjjf6"}],["circle",{cx:"15",cy:"12",r:"1",key:"1tmaij"}],["circle",{cx:"15",cy:"5",r:"1",key:"19l28e"}],["circle",{cx:"15",cy:"19",r:"1",key:"f4zoj3"}]],pe=u("grip-vertical",me);const ue=[["path",{d:"M15 21v-5a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v5",key:"slp6dd"}],["path",{d:"M17.774 10.31a1.12 1.12 0 0 0-1.549 0 2.5 2.5 0 0 1-3.451 0 1.12 1.12 0 0 0-1.548 0 2.5 2.5 0 0 1-3.452 0 1.12 1.12 0 0 0-1.549 0 2.5 2.5 0 0 1-3.77-3.248l2.889-4.184A2 2 0 0 1 7 2h10a2 2 0 0 1 1.653.873l2.895 4.192a2.5 2.5 0 0 1-3.774 3.244",key:"o0xfot"}],["path",{d:"M4 10.95V19a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8.05",key:"wn3emo"}]],B=u("store",ue);const he=[["path",{d:"M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z",key:"vktsd0"}],["circle",{cx:"7.5",cy:"7.5",r:".5",fill:"currentColor",key:"kqv944"}]],fe=u("tag",he);const ge=[["path",{d:"M16 17h6v-6",key:"t6n2it"}],["path",{d:"m22 17-8.5-8.5-5 5L2 7",key:"x473p"}]],je=u("trending-down",ge),p=[{id:"novo",title:"Prospecção",dot:"bg-muted-foreground/40"},{id:"contato",title:"Em contato",dot:"bg-brand-glow"},{id:"proposta",title:"Proposta",dot:"bg-brand-lime"},{id:"ganho",title:"Ganho",dot:"bg-brand-mint"},{id:"perdido",title:"Perdido",dot:"bg-destructive"}];function Te(){const{user:r}=se(),l=(r?.roles.includes("wl_vendedor")??!1)&&!(r?.roles.includes("administrador")??!1)&&!(r?.roles.includes("wl")??!1)&&!(r?.roles.includes("la")??!1),[d,o]=n.useState([]),[c,i]=n.useState(!0),[x,y]=n.useState(null),[k,E]=n.useState("kanban"),[a,T]=n.useState(null),[G,_]=n.useState(!1),[h,f]=n.useState(null),[C,P]=n.useState(!1),K=async()=>{i(!0);const{data:s,error:t}=await M.from("leads").select("id, site_id, full_name, email, phone, cpf, rg, cep, address, preferred_store, wants_machine, status, source, la_user_id, created_at").order("created_at",{ascending:!1});if(i(!1),t){v.error("Erro ao carregar leads");return}o(s??[])};n.useEffect(()=>{K()},[]);const m=n.useMemo(()=>{const s={novo:[],contato:[],proposta:[],ganho:[],perdido:[]};for(const t of d)s[t.status].push(t);return s},[d]),N=d.length,g=m.ganho.length,Q=d.filter(s=>s.wants_machine).length,j=N>0?Math.round(g/N*100):0,W=async(s,t)=>{const b=d;o(S=>S.map(L=>L.id===s?{...L,status:t}:L));const{error:D}=await M.from("leads").update({status:t}).eq("id",s);D&&(o(b),v.error("Não foi possÃvel mover o lead"))},J=async()=>{if(!h)return;P(!0);const{error:s}=await M.from("leads").delete().eq("id",h.id);if(P(!1),s){v.error("Não foi possÃvel excluir o lead");return}o(t=>t.filter(b=>b.id!==h.id)),v.success("Lead excluÃdo"),f(null)};return e.jsx(ee,{title:"Funil de Vendas",breadcrumb:e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"Confrapag"}),e.jsx("span",{className:"h-1 w-1 rounded-full bg-muted-foreground/40"}),e.jsx("span",{className:"text-brand-glow",children:"Leads do site"})]}),description:"Gerencie os leads recebidos pelo seu site público",children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-4",children:[e.jsx(w,{label:"Total de leads",value:N.toString(),trend:"+novos este mês",trendUp:!0,icon:e.jsx(X,{className:"h-6 w-6"}),tone:"brand"}),e.jsx(w,{label:"Taxa de conversão",value:`${j}%`,trend:j>=20?"boa performance":"pode melhorar",trendUp:j>=20,icon:e.jsx(ae,{className:"h-6 w-6"}),tone:"mint"}),e.jsx(w,{label:"Interesse em máquina",value:Q.toString(),trend:"leads qualificados",trendUp:!0,icon:e.jsx($,{className:"h-6 w-6"}),tone:"lime"}),e.jsx(w,{label:"Negócios fechados",value:g.toString(),trend:g>0?"parabéns!":"sem fechamentos",trendUp:g>0,icon:e.jsx(re,{className:"h-6 w-6"}),tone:"glow"})]}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-[1fr_320px]",children:[e.jsxs("div",{className:"bg-card p-6 rounded-xl border border-border shadow-sm",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsx("h2",{className:"text-lg font-semibold text-brand",children:"Visualização do pipeline"}),e.jsx("div",{className:"flex gap-2",children:e.jsx("span",{className:"px-3 py-1 bg-muted rounded-full text-xs text-muted-foreground border border-border",children:"Ãltimos 30 dias"})})]}),e.jsx("div",{className:"h-48 flex items-end justify-between gap-4 px-2",children:p.map(s=>{const t=m[s.id].length,b=Math.max(...p.map(S=>m[S.id].length),1),D=Math.max(t/b*100,8);return e.jsx("div",{className:"flex-1 flex flex-col items-center gap-2 group",children:e.jsx("div",{className:"w-full relative flex items-end h-full",children:e.jsx("div",{className:"w-full rounded-t-lg bg-[image:var(--gradient-brand)] opacity-70 group-hover:opacity-100 transition-opacity relative",style:{height:`${D}%`},children:e.jsxs("div",{className:"absolute -top-7 left-1/2 -translate-x-1/2 bg-brand text-brand-foreground text-[10px] px-2 py-1 rounded opacity-0 group-hover:opacity-100 transition-opacity whitespace-nowrap",children:[t," ",t===1?"lead":"leads"]})})})},s.id)})}),e.jsx("div",{className:"flex justify-between mt-4 text-xs text-muted-foreground font-medium border-t border-border pt-4",children:p.map(s=>e.jsx("span",{className:"flex-1 text-center uppercase tracking-wide",children:s.title},s.id))})]}),e.jsxs("div",{className:"bg-brand rounded-xl p-6 text-brand-foreground shadow-xl flex flex-col justify-between",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx($,{className:"h-5 w-5 text-brand-lime"}),e.jsx("span",{className:"text-xs font-bold uppercase tracking-widest opacity-80",children:"Meta do funil"})]}),e.jsxs("p",{className:"text-4xl font-bold mb-2",children:[j,"%"]}),e.jsxs("p",{className:"text-sm opacity-80 leading-relaxed",children:[g," de ",N," leads convert
1idos. Continue acompanhando os contatos para aumentar suas conversões."]})]}),e.jsx("div",{className:"mt-6",children:e.jsx("div",{className:"h-2 w-full bg-brand-foreground/10 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-brand-lime transition-all",style:{width:`${j}%`}})})})]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h2",{className:"text-lg font-semibold text-brand",children:"Pipeline de leads"}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"flex bg-muted p-1 rounded-lg",children:[e.jsx("button",{onClick:()=>E("kanban"),className:`px-3 py-1.5 rounded-md text-xs font-bold transition ${k==="kanban"?"bg-background text-brand shadow-sm":"text-muted-foreground hover:text-brand"}`,children:"Kanban"}),e.jsx("button",{onClick:()=>E("lista"),className:`px-3 py-1.5 rounded-md text-xs font-bold transition ${k==="lista"?"bg-background text-brand shadow-sm":"text-muted-foreground hover:text-brand"}`,children:"Lista"})]}),e.jsxs("button",{className:"flex items-center gap-2 px-4 py-2 bg-background border border-border rounded-lg text-sm font-medium hover:bg-muted transition",children:[e.jsx(xe,{className:"h-4 w-4"}),"Filtros"]})]})]}),c?e.jsx("p",{className:"text-muted-foreground",children:"Carregandoâ¦"}):k==="kanban"?e.jsx("div",{className:"flex gap-4 overflow-x-auto pb-4",children:p.map(s=>e.jsxs("div",{onDragOver:t=>!l&&t.preventDefault(),onDrop:()=>{l||(x&&W(x,s.id),y(null))},className:"w-[280px] shrink-0 flex flex-col gap-3",children:[e.jsxs("div",{className:"flex items-center justify-between px-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`w-2 h-2 rounded-full ${s.dot}`}),e.jsx("h3",{className:"text-sm font-bold text-foreground uppercase tracking-wide",children:s.title}),e.jsx("span",{className:"bg-muted text-muted-foreground text-[10px] px-2 py-0.5 rounded-full font-bold",children:m[s.id].length})]}),e.jsx(ie,{className:"h-4 w-4 text-muted-foreground cursor-pointer"})]}),e.jsxs("div",{className:"flex-1 flex flex-col gap-3 min-h-[200px]",children:[m[s.id].map(t=>e.jsx(be,{lead:t,onDragStart:()=>!l&&y(t.id),onDragEnd:()=>y(null),onClick:()=>{T(t),_(!0)},onDelete:l?void 0:()=>f(t)},t.id)),m[s.id].length===0&&e.jsx("div",{className:"border border-dashed border-border rounded-xl p-6 text-center",children:e.jsx("p",{className:"text-xs text-muted-foreground",children:"Sem leads"})})]})]},s.id))}):e.jsx("div",{className:"bg-card rounded-xl border border-border overflow-hidden",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-muted/50 text-left text-xs uppercase tracking-wide text-muted-foreground",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-3",children:"Nome"}),e.jsx("th",{className:"px-4 py-3",children:"Email"}),e.jsx("th",{className:"px-4 py-3",children:"Telefone"}),e.jsx("th",{className:"px-4 py-3",children:"Loja"}),e.jsx("th",{className:"px-4 py-3",children:"Status"}),e.jsx("th",{className:"px-4 py-3",children:"Data"}),e.jsx("th",{className:"px-4 py-3 w-10"})]})}),e.jsxs("tbody",{children:[d.map(s=>e.jsxs("tr",{className:"border-t border-border hover:bg-muted/30 cursor-pointer",onClick:()=>{T(s),_(!0)},children:[e.jsx("td",{className:"px-4 py-3 font-medium text-foreground",children:s.full_name}),e.jsx("td",{className:"px-4 py-3 text-muted-foreground",children:s.email??"â"}),e.jsx("td",{className:"px-4 py-3 text-muted-foreground",children:s.phone}),e.jsx("td",{className:"px-4 py-3 text-muted-foreground",children:s.preferred_store??"â"}),e.jsx("td",{className:"px-4 py-3",children:e.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide text-brand",children:p.find(t=>t.id===s.status)?.title})}),e.jsx("td",{className:"px-4 py-3 text-muted-foreground text-xs",children:new Date(s.created_at).toLocaleDateString("pt-BR")}),e.jsx("td",{className:"px-4 py-3",children:!l&&e.jsx("button",{onClick:t=>{t.stopPropagation(),f(s)},className:"text-muted-foreground hover:text-destructive transition p-1 rounded","aria-label":"Excluir lead",children:e.jsx(V,{className:"h-4 w-4"})})})]},s.id)),d.length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:7,className:"px-4 py-12 text-center text-muted-foreground",children:"Nenhum lead recebido ainda."})})]})]})}),e.jsx(F,{open:G,onOpenChange:_,children:e.jsx(U,{className:"max-w-lg max-h-[90vh] overflow-y-auto",children:a&&e.jsxs(e.Fragment,{children:[e.jsxs(q,{children:[e.jsx(A,{className:"text-brand",children:a.full_name}),e.jsxs(O,{children:["Lead #",a.id.slice(0,6).toUpperCase()," ·"," ",new Date(a.created_at).toLocaleDateString("pt-BR",{day:"2-digit",month:"long",year:"numeric",hour:"2-digit",minute:"2-digit"})]})]}
1),e.jsxs("div",{className:"space-y-4 mt-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"bg-muted/50 p-3 rounded-lg",children:[e.jsx("p",{className:"text-[10px] font-bold uppercase text-muted-foreground mb-1",children:"Status"}),e.jsx("p",{className:"text-sm font-semibold text-foreground",children:p.find(s=>s.id===a.status)?.title})]}),e.jsxs("div",{className:"bg-muted/50 p-3 rounded-lg",children:[e.jsx("p",{className:"text-[10px] font-bold uppercase text-muted-foreground mb-1",children:"Origem"}),e.jsx("p",{className:"text-sm font-semibold text-foreground capitalize",children:a.source??"â"})]})]}),e.jsxs("div",{className:"space-y-3",children:[a.email&&e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(H,{className:"h-4 w-4 text-muted-foreground mt-0.5 shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] font-bold uppercase text-muted-foreground",children:"E-mail"}),e.jsx("p",{className:"text-sm text-foreground",children:a.email})]})]}),e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(I,{className:"h-4 w-4 text-muted-foreground mt-0.5 shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] font-bold uppercase text-muted-foreground",children:"Telefone"}),e.jsx("p",{className:"text-sm text-foreground",children:a.phone})]})]}),a.cpf&&e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(ne,{className:"h-4 w-4 text-muted-foreground mt-0.5 shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] font-bold uppercase text-muted-foreground",children:"CPF"}),e.jsx("p",{className:"text-sm text-foreground",children:a.cpf})]})]}),a.rg&&e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(te,{className:"h-4 w-4 text-muted-foreground mt-0.5 shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] font-bold uppercase text-muted-foreground",children:"RG"}),e.jsx("p",{className:"text-sm text-foreground",children:a.rg})]})]}),a.cep&&e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(R,{className:"h-4 w-4 text-muted-foreground mt-0.5 shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] font-bold uppercase text-muted-foreground",children:"CEP"}),e.jsx("p",{className:"text-sm text-foreground",children:a.cep})]})]}),a.address&&e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(R,{className:"h-4 w-4 text-muted-foreground mt-0.5 shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] font-bold uppercase text-muted-foreground",children:"Endereço"}),e.jsx("p",{className:"text-sm text-foreground",children:a.address})]})]}),a.preferred_store&&e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(B,{className:"h-4 w-4 text-muted-foreground mt-0.5 shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] font-bold uppercase text-muted-foreground",children:"Loja Preferida"}),e.jsx("p",{className:"text-sm text-foreground",children:a.preferred_store})]})]}),e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(fe,{className:"h-4 w-4 text-muted-foreground mt-0.5 shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] font-bold uppercase text-muted-foreground",children:"Quer máquina?"}),e.jsx("p",{className:"text-sm text-foreground",children:a.wants_machine?"Sim":"Não"})]})]})]})]})]})})}),e.jsx(F,{open:!!h,onOpenChange:s=>!s&&f(null),children:e.jsxs(U,{className:"max-w-md",children:[e.jsxs(q,{children:[e.jsx(A,{className:"text-brand",children:"Excluir lead"}),e.jsxs(O,{children:["Tem certeza que deseja excluir o lead"," ",e.jsx("span",{className:"font-semibold text-foreground",children:h?.full_name}),"? Esta ação não poderá ser desfeita."]})]}),e.jsxs(Y,{className:"gap-2 sm:gap-2",children:[e.jsx(z,{variant:"outline",onClick:()=>f(null),disabled:C,children:"Cancelar"}),e.jsx(z,{variant:"destructive",onClick:J,disabled:C,children:C?"Excluindoâ¦":"Excluir"})]})]})})]})})}function w({label:r,value:l,trend:d,trendUp:o,icon:c,tone:i}){const x={brand:"bg-brand/5 text-brand",mint:"bg-brand-mint/15 text-brand",lime:"bg-brand-lime/15 text-brand",glow:"bg-brand-glow/15 text-brand"};return e.jsxs("div",{className:"bg-card p-6 rounded-xl border border-border shadow-sm flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-muted-foreground text-xs font-bold mb-1 uppercase tracking-wider",children:r}),e.jsx("h3",{className:"text-3xl font-bold text-brand",children:l}),e.jsxs("p",{className:`text-xs flex items-center gap-1 mt-1 ${o?"text-brand-mint":"text-destructive"}`,children:[o?e.jsx(de,{className:"h-3 w-3"}):e.jsx(je,{className:"h-3 w-3"}),d]})]}
1),e.jsx("div",{className:`w-14 h-14 rounded-2xl flex items-center justify-center ${x[i]}`,children:c})]})}function be({lead:r,onDragStart:l,onDragEnd:d,onClick:o,onDelete:c}){const i=Math.floor((Date.now()-new Date(r.created_at).getTime())/864e5);return e.jsxs("div",{draggable:!0,onDragStart:l,onDragEnd:d,onClick:o,className:"bg-card p-4 rounded-xl border border-border shadow-sm hover:shadow-md transition-shadow cursor-grab active:cursor-grabbing group",children:[e.jsxs("div",{className:"flex justify-between items-start mb-3",children:[e.jsxs("span",{className:"px-2 py-0.5 bg-muted text-[10px] font-bold text-muted-foreground rounded border border-border",children:["#",r.id.slice(0,6).toUpperCase()]}),e.jsxs("div",{className:"flex items-center gap-1",children:[c&&e.jsx("button",{onClick:x=>{x.stopPropagation(),c()},className:"text-muted-foreground/60 hover:text-destructive transition p-1 rounded opacity-0 group-hover:opacity-100","aria-label":"Excluir lead",children:e.jsx(V,{className:"h-3.5 w-3.5"})}),e.jsx(pe,{className:"h-4 w-4 text-muted-foreground/40 opacity-0 group-hover:opacity-100 transition-opacity"})]})]}),e.jsxs("h4",{className:"font-bold text-brand mb-3 truncate flex items-center gap-2 flex-wrap",children:[r.full_name,r.source==="licenciado"&&e.jsx("span",{className:"text-[9px] font-bold uppercase px-1.5 py-0.5 rounded bg-brand-lime/20 text-brand",children:"Licenciado"}),r.source==="whatsapp"&&e.jsx("span",{className:"text-[9px] font-bold uppercase px-1.5 py-0.5 rounded bg-[#25D366]/15 text-[#25D366]",children:"WhatsApp"})]}),e.jsxs("div",{className:"space-y-1.5 text-xs text-muted-foreground mb-3",children:[r.email&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(H,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{className:"truncate",children:r.email})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(I,{className:"h-3 w-3 shrink-0"})," ",r.phone]}),r.preferred_store&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(B,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{className:"truncate",children:r.preferred_store})]})]}),e.jsxs("div",{className:"flex items-center justify-between border-t border-border pt-3",children:[r.wants_machine?e.jsxs("div",{className:"flex items-center gap-1 text-brand-mint",children:[e.jsx(Z,{className:"h-3 w-3"}),e.jsx("span",{className:"text-[10px] font-bold uppercase",children:"Quer máquina"})]}):e.jsx("span",{}),e.jsxs("div",{className:"flex items-center gap-1 text-muted-foreground",children:[e.jsx(le,{className:"h-3 w-3"}),e.jsx("span",{className:"text-[10px] font-medium",children:i===0?"hoje":`${i}d`})]})]})]})}export{Te as component};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.