1var Qe=Object.defineProperty;var Ue=(s,a,r)=>a in s?Qe(s,a,{enumerable:!0,configurable:!0,writable:!0,value:r}):s[a]=r;var je=(s,a,r)=>Ue(s,typeof a!="symbol"?a+"":a,r);import{r as i,j as e}from"./vendor-react-DIA7vK4g.js";import{P as Ve,C as Ge}from"./ParceiroAdminLayout-DR3iAduS.js";import{b7 as ue,ba as Y,bb as A,bc as me,bF as k,bd as K,be as J,bg as F,s as pe,o as de,bP as P,bm as f,al as fe,at as ge,c7 as Ke,aC as Je,$ as Re,b2 as re,aS as xe,bz as R,aa as oe,C as We,O as Xe,ci as te,X as Ye,b9 as Z,b6 as Ze,b8 as es,cs as ne,bL as be,bM as Ne,bN as ve,z as ss,aO as Ce,bO as we,bS as ye,a_ as _e,ao as Se,R as Pe,T as ke,bQ as Ae,aF as le,m as Ee,by as as,aE as ts,bi as ie,bA as os,bB as rs,bC as ns,bD as ls,bE as is,bT as cs,bU as ms,bV as ds,cw as xs,az as us,a$ as ps}from"./index-DtUVjOr4.js";import{u as hs,p as Ie,r as qe,f as js}from"./plan-catalog-CB20ndaT.js";import{c as fs,f as u,A as z,T as gs,g as bs}from"./simulator-pricing-C_AkzkqV.js";import{W as Ns}from"./wifi-s_lsBhn6.js";import{R as vs,a as Cs}from"./radio-group-CV0oqF9i.js";import{C as Le}from"./clock-x8uDBefL.js";import{I as ws}from"./index-DyreCcme.js";import{P as ys}from"./phone-input-DRTEOMnt.js";import{F as _s}from"./vendor-supabase-_bOAMmkC.js";import{u as Ss}from"./useHubSpotPropertyCache-By0WJBNk.js";import{C as Ps}from"./calendar-days-BNSiXEw2.js";import{C as Fe}from"./calendar-n1wfbzNV.js";import{j as De,p as ks,H as Oe,aB as ce,aP as As,aD as G}from"./vendor-utils-DWHjTIse.js";import{C as Es}from"./ComercialPageHeader-Dx0iWF8w.js";import"./vendor-docs-BA9xu9ak.js";import"./GlobalSearch-CILhhYPj.js";import"./command-8X5Fvwln.js";import"./useSandboxConfig-H_pzAYpM.js";import"./repeat-sulmqLMn.js";import"./billing-formatters-uNs-HNzw.js";import"./corner-down-left-BYgMx1Bm.js";import"./eye-DZWf3ZF4.js";import"./chevrons-up-down-D6Nd5u2s.js";import"./document-utils-DQEVigHH.js";import"./phone-BgqrZNH1.js";import"./PageHeader-DbudfU8v.js";const Fs="PLANO_PROFISSIONAL",Te={planoCode:Fs,colaboradores:20,colaboradoresCustom:!1,empresasAdicionaisPacotes:0,apiAberta:!1,reconhecimentoFacialQtd:0,treinamento:null,cupomCodigo:""};function Ds(){const[s,a]=i.useState(Te),[r,t]=i.useState(null),[c,n]=i.useState(null),{data:x=[],isLoading:h,error:j}=hs("monthly");i.useEffect(()=>{x.length!==0&&a(l=>x.some(d=>d.code===l.planoCode)?l:{...l,planoCode:x[0].code})},[x]);const m=i.useMemo(()=>x.find(l=>l.code===s.planoCode)??x[0]??null,[x,s.planoCode]),{refetch:S,isFetching:v}=ue({queryKey:["sim-cupom",s.cupomCodigo],queryFn:async()=>{if(!s.cupomCodigo.trim())return t(null),n("Informe um código de cupom"),null;const{data:l,error:d}=await Y.from("sim_cupons").select("*").eq("codigo",s.cupomCodigo.toUpperCase().trim()).eq("ativo",!0).maybeSingle();if(d){console.error("[simulador] erro ao validar cupom:",d);const b=d.code==="42501"||d.code==="PGRST301"||/permission denied|row-level security/i.test(d.message||"");return n(b?"Você não tem permissão para usar cupons. Fale com um administrador.":"Não foi possÃvel validar o cupom. Tente novamente."),t(null),null}if(!l)return n("Código não encontrado ou inativo"),t(null),null;const C=new Date;if(l.validade_inicio&&new Date(`${l.validade_inicio}T00:00:00`)>C)return n("Cupom ainda não está válido"),t(null),null;if(l.validade_fim&&new Date(`${l.validade_fim}T23:59:59`)<C)return n("Cupom expirado"),t(null),null;if(l.uso_maximo&&l.uso_atual>=l.uso_maximo)return n("Cupom esgotado (limite de usos atingido)"),t(null),null;const w={codigo:l.codigo,desconto_mensalidade_tipo:l.desconto_mensalidade_tipo||"nenhum",desconto_mensalidade_valor:Number(l.desconto_mensalidade_valor)||0,desconto_mensalidade_meses:l.desconto_mensalidade_meses||0,desconto_treinamento_tipo:l.desconto_treinamento_tipo||"nenhum",desconto_treinamento_valor:Number(l.desconto_treinamento_valor)||0};return t(w),n(null),w},enabled:!1}),D=i.useMemo(()=>m?Ie(m,s.colaboradores):null,[m,s.colaboradores]),_=i.useMemo(()=>m?qe(m,s.colaboradores):null,[m,s.colaboradores]),H=i.useMemo(()=>fs({planoCode:(m==null?void 0:m.code)??s.planoCode,planoNome:(m==null?void 0:m.name)??s.planoCode,colaboradores:s.colaboradores,precoB
1ase:D??0,faixaLabel:_,empresasAdicionaisPacotes:s.empresasAdicionaisPacotes,apiAberta:s.apiAberta,reconhecimentoFacialQtd:s.reconhecimentoFacialQtd,treinamento:s.treinamento,cupom:r}),[s,r,m,D,_]),O=i.useMemo(()=>m?js(m):[],[m]),I=i.useCallback(l=>{a(d=>{const C=x.find(p=>p.code===l);let w=d.colaboradores;C&&(w<C.minColaboradores&&(w=C.minColaboradores),C.maxColaboradores!=null&&w>C.maxColaboradores&&(w=C.maxColaboradores));const b=l==="PLANO_PROFISSIONAL"?d.reconhecimentoFacialQtd:0;return{...d,planoCode:l,colaboradores:w,colaboradoresCustom:d.colaboradores!==w?!1:d.colaboradoresCustom,reconhecimentoFacialQtd:b}})},[x]),q=i.useCallback((l,d=!1)=>{a(C=>({...C,colaboradores:l,colaboradoresCustom:d}))},[]),Q=i.useCallback(l=>{a(d=>({...d,empresasAdicionaisPacotes:Math.max(0,l)}))},[]),N=i.useCallback(l=>{a(d=>({...d,apiAberta:l}))},[]),T=i.useCallback(l=>{a(d=>({...d,reconhecimentoFacialQtd:Math.max(0,l)}))},[]),U=i.useCallback(l=>{a(d=>({...d,treinamento:l}))},[]),B=i.useCallback(l=>{a(d=>({...d,cupomCodigo:l})),t(null),n(null)},[]),M=i.useCallback(()=>{S()},[S]),E=i.useCallback(()=>{a(l=>({...l,cupomCodigo:""})),t(null),n(null)},[]),L=i.useCallback(()=>{a(Te),t(null),n(null)},[]);return{state:s,planos:x,planoAtual:m,carregandoPlanos:h,erroPlanos:j,precoBase:D,faixaLabel:_,resultado:H,faixasDisponiveis:O,cupomValidado:r,cupomError:c,validandoCupom:v,setPlano:I,setColaboradores:q,setEmpresasAdicionais:Q,setApiAberta:N,setReconhecimentoFacial:T,setTreinamento:U,setCupomCodigo:B,aplicarCupom:M,limparCupom:E,resetar:L}}function Os({planName:s,basePrice:a,features:r,maxEmployees:t,isSelected:c,onSelect:n,recommended:x=!1,pricePerEmployee:h,breakdown:j,indisponivel:m=!1}){const S=s.replace(/^Plano\s+/i,"");return e.jsxs(A,{className:me("relative cursor-pointer transition-all hover:shadow-lg",c?"ring-2 ring-primary border-primary":"hover:border-primary/50"),onClick:n,children:[x&&e.jsx(k,{className:"absolute -top-2 left-1/2 -translate-x-1/2 bg-primary",children:"Recomendado"}),e.jsxs(K,{className:"pb-2",children:[e.jsx(J,{className:"text-lg",children:S}),e.jsx("div",{className:"mt-2",children:m?e.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:"Não atende esta quantidade"}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-2xl font-bold text-primary",children:u(a)}),e.jsx("span",{className:"text-muted-foreground text-sm",children:"/mês"})]})}),!m&&typeof h=="number"&&h>0&&e.jsxs("p",{className:"text-xs font-medium text-muted-foreground",children:[u(h)," por colaborador"]}),!m&&j&&e.jsx("p",{className:"text-[11px] text-muted-foreground",children:j}),e.jsx("p",{className:"text-xs text-muted-foreground",children:typeof t=="number"?`Até ${t} colaboradores`:t})]}),e.jsx(F,{className:"pt-2",children:e.jsx("ul",{className:"space-y-2",children:r.map((v,D)=>e.jsxs("li",{className:"flex items-start gap-2 text-sm",children:[e.jsx(pe,{className:"h-4 w-4 text-green-500 mt-0.5 shrink-0"}),e.jsx("span",{children:v})]},D))})})]})}function Ts({planoCode:s,empresasAdicionaisPacotes:a,apiAberta:r,reconhecimentoFacialQtd:t,onEmpresasChange:c,onApiAbertaChange:n,onReconhecimentoChange:x}){const h=a*z.empresasAdicionais.empresasPorPacote,j=a*z.empresasAdicionais.precoPacote,m=s===z.reconhecimentoFacial.apenasPlanoCode,S=t*z.reconhecimentoFacial.precoUnitario;return e.jsxs(A,{children:[e.jsx(K,{className:"pb-3",children:e.jsx(J,{className:"text-base",children:"Adicionais"})}),e.jsxs(F,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(de,{className:"h-5 w-5 text-muted-foreground"}),e.jsxs("div",{children:[e.jsx(P,{className:"text-sm font-medium",children:"Empresas Adicionais"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Pacote de ",z.empresasAdicionais.empresasPorPacote," empresas por"," ",u(z.empresasAdicionais.precoPacote),"/mês"]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(f,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>c(a-1),disabled:a===0,children:e.jsx(fe,{className:"h-4 w-4"})}),e.jsxs("div",{className:"w-16 text-center",children:[e.jsx("span",{className:"text-lg font-semibold",children:h}),j>0&&e.jsx("p",{className:"text-xs text-muted-foreground",children:u(j)})]}),e.jsx(f,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>c(a+1),children:e.jsx(ge,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Ns,{className:"h-5 w-5 text-muted-foreground"}),e.jsxs("div",{children:[e.jsx(P,{className:"text-sm font-medium",children:"API Aberta"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[u(z.apiAberta.prec
1o),"/mês"]})]})]}),e.jsx(Ke,{checked:r,onCheckedChange:n})]}),e.jsx("div",{className:m?"":"opacity-50 pointer-events-none",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Je,{className:"h-5 w-5 text-muted-foreground"}),e.jsxs("div",{children:[e.jsx(P,{className:"text-sm font-medium",children:"Reconhecimento Facial"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[u(z.reconhecimentoFacial.precoUnitario),"/usuário",!m&&" (apenas Plano Profissional)"]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(f,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>x(t-1),disabled:t===0||!m,children:e.jsx(fe,{className:"h-4 w-4"})}),e.jsxs("div",{className:"w-16 text-center",children:[e.jsx("span",{className:"text-lg font-semibold",children:t}),S>0&&e.jsx("p",{className:"text-xs text-muted-foreground",children:u(S)})]}),e.jsx(f,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>x(t+1),disabled:!m,children:e.jsx(ge,{className:"h-4 w-4"})})]})]})})]})]})}function Ms({selected:s,onSelect:a,desconto:r=0}){const t=Object.entries(gs);return e.jsxs(A,{children:[e.jsx(K,{className:"pb-3",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(J,{className:"text-base flex items-center gap-2",children:[e.jsx(Re,{className:"h-5 w-5"}),"Treinamento"]}),s&&e.jsxs(f,{variant:"ghost",size:"sm",className:"h-7 text-xs",onClick:()=>a(null),children:[e.jsx(re,{className:"h-3 w-3 mr-1"}),"Remover"]})]})}),e.jsxs(F,{children:[e.jsx(vs,{value:s||"",onValueChange:c=>a(c),children:e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:t.map(([c,n])=>{const x=r>0?n.preco*(1-r/100):n.preco;return e.jsxs("label",{htmlFor:`treinamento-${c}`,className:` 2 relative flex flex-col items-center p-4 rounded-lg border cursor-pointer 3 transition-all hover:border-primary/50 4 ${s===c?"border-primary bg-primary/5 ring-1 ring-primary":""} 5 `,children:[e.jsx(Cs,{value:c,id:`treinamento-${c}`,className:"sr-only"}),e.jsx("span",{className:"font-semibold text-lg",children:c}),e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground mt-1",children:[e.jsx(Le,{className:"h-3 w-3"}),n.duracao]}),e.jsx("div",{className:"mt-2 text-center",children:r>0?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-xs text-muted-foreground line-through",children:u(n.preco)}),e.jsx("div",{className:"font-semibold text-primary",children:u(x)})]}):e.jsx("span",{className:"font-semibold",children:u(n.preco)})}),r>0&&e.jsxs(k,{variant:"secondary",className:"mt-1 text-xs",children:["-",r,"%"]})]},c)})})}),e.jsx("p",{className:"text-xs text-muted-foreground mt-3 text-center",children:"Até 3x sem juros ou até 12x com juros de 1,99% a.m."})]})]})}function Rs({codigo:s,cupomValidado:a,cupomError:r,validando:t,onCodigoChange:c,onAplicar:n,onLimpar:x}){const h=j=>{j.key==="Enter"&&s.trim()&&n()};return e.jsxs(A,{children:[e.jsx(K,{className:"pb-3",children:e.jsxs(J,{className:"text-base flex items-center gap-2",children:[e.jsx(xe,{className:"h-5 w-5"}),"Cupom de Desconto"]})}),e.jsxs(F,{children:[a?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between p-3 bg-green-50 dark:bg-green-950/20 rounded-lg border border-green-200 dark:border-green-900",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(pe,{className:"h-5 w-5 text-green-600"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-green-700 dark:text-green-400",children:a.codigo}),e.jsx("p",{className:"text-xs text-green-600 dark:text-green-500",children:"Cupom aplicado com sucesso!"})]})]}),e.jsx(f,{variant:"ghost",size:"sm",onClick:x,className:"text-green-700 hover:text-green-900",children:e.jsx(re,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[a.desconto_mensalidade_tipo!=="nenhum"&&e.jsxs(k,{variant:"secondary",children:[a.desconto_mensalidade_tipo==="percentual"?`${a.desconto_mensalidade_valor}% off mensalidade`:`${u(a.desconto_mensalidade_valor)} off mensalidade`,a.desconto_mensalidade_meses>0&&` (${a.desconto_mensalidade_meses} meses)`]}),a.desconto_treinamento_tipo!=="nenhum"&&e.jsx(k,{variant:"secondary",children:a.desconto_treinamento_tipo==="percentual"?`${a.desconto_treinamento_valor}% off treinamento`:`${u(a.desconto_treinamento_valor)} off treinamento`})]})]}):e.jsxs("div",{className:"flex gap-2",children:[e.jsx(R,{placeholder:"Digite o código do cupom",value:s,onChange:j=>c(j.target.value.toUpperCase()),onKeyDown:h,className:"uppercase"}),e.jsx(f,{onClick:n,disabled:!s.trim()||t,className:"shrink-0",children:t?e.jsx(oe,{className:"h-4 w-4 animate-spin"}):"Aplicar"})]}),r&&!a&&e.jsxs("p",{className:"text-sm text-destructive mt-2 flex items-center gap-1",children:[e.jsx(re,{className:"h-4 w-4"}),r]})]})]})}function Is({resultado:s,onCriarOrcamento:a}){const[r,t]=i.useState(!1),c=s.colaboradores>
50?s.precoBase/s.colaboradores:0,n=s.descontoMensalidade?s.totalMensalComDesconto:s.totalMensal,x=s.colaboradores>0?n/s.colaboradores:0,h=async()=>{const j=bs(s);try{await navigator.clipboard.writeText(j),t(!0),Z.success("Resumo copiado para a área de transferência!"),setTimeout(()=>t(!1),2e3)}catch{Z.error("Erro ao copiar resumo")}};return e.jsxs(A,{className:"sticky top-20",children:[e.jsx(K,{className:"pb-3",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(J,{className:"text-base flex items-center gap-2",children:[e.jsx(We,{className:"h-5 w-5"}),"Resumo da Simulação"]}),e.jsx(f,{variant:"outline",size:"sm",onClick:h,className:"gap-1",children:r?e.jsxs(e.Fragment,{children:[e.jsx(pe,{className:"h-4 w-4"}),"Copiado!"]}):e.jsxs(e.Fragment,{children:[e.jsx(Xe,{className:"h-4 w-4"}),"Copiar"]})})]})}),e.jsxs(F,{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Plano"}),e.jsx("p",{className:"font-semibold",children:s.plano}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[s.colaboradores," colaboradores"]})]}),e.jsx(te,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{children:"Plano base"}),e.jsx("span",{children:u(s.precoBase)})]}),s.faixaLabel&&e.jsx("p",{className:"text-xs text-muted-foreground",children:s.faixaLabel}),c>0&&e.jsxs("div",{className:"flex justify-between text-xs text-muted-foreground",children:[e.jsx("span",{children:"Custo por colaborador (plano base)"}),e.jsx("span",{children:u(c)})]}),s.empresasAdicionais>0&&e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsxs("span",{children:["Empresas (+",s.empresasAdicionaisQtd,")"]}),e.jsx("span",{children:u(s.empresasAdicionais)})]}),s.apiAberta>0&&e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{children:"API Aberta"}),e.jsx("span",{children:u(s.apiAberta)})]}),s.reconhecimentoFacial>0&&e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsxs("span",{children:["Rec. Facial (",s.reconhecimentoFacialQtd,")"]}),e.jsx("span",{children:u(s.reconhecimentoFacial)})]}),x>0&&e.jsxs("div",{className:"flex justify-between text-xs font-medium",children:[e.jsx("span",{children:"Custo por colaborador (total)"}),e.jsx("span",{children:u(x)})]})]}),e.jsx(te,{}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex justify-between items-baseline",children:[e.jsx("span",{className:"font-medium",children:"Total Mensal"}),e.jsx("span",{className:`text-xl font-bold ${s.descontoMensalidade?"text-muted-foreground line-through text-base":"text-primary"}`,children:u(s.totalMensal)})]}),s.descontoMensalidade&&e.jsxs("div",{className:"flex justify-between items-baseline",children:[e.jsxs(k,{variant:"secondary",className:"gap-1",children:[e.jsx(xe,{className:"h-3 w-3"}),s.descontoMensalidade.tipo==="percentual"?`${s.descontoMensalidade.valor}% off`:`${u(s.descontoMensalidade.valor)} off`]}),e.jsx("span",{className:"text-xl font-bold text-primary",children:u(s.totalMensalComDesconto)})]}),s.descontoMensalidade&&s.descontoMensalidade.meses>0&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Desconto válido por ",s.descontoMensalidade.meses," meses"]})]}),s.treinamento&&e.jsxs(e.Fragment,{children:[e.jsx(te,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium",children:"Treinamento"}),e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{children:s.treinamento.nome}),s.treinamento.desconto>0?e.jsxs("div",{className:"text-right",children:[e.jsx("span",{className:"text-muted-foreground line-through text-xs",children:u(s.treinamento.precoOriginal)}),e.jsx("span",{className:"font-semibold ml-1",children:u(s.treinamento.precoFinal)})]}):e.jsx("span",{className:"font-semibold",children:u(s.treinamento.precoOriginal)})]}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[e.jsx("p",{children:"Parcelamento:"}),e.jsx("ul",{className:"mt-1 space-y-0.5",children:s.treinamento.parcelamento.slice(0,4).map(j=>e.jsxs("li",{className:"flex justify-between",children:[e.jsxs("span",{children:[j.parcelas,"x ",j.comJuros&&"(c/ juros)"]}),e.jsx("span",{children:u(j.valorParcela)})]},j.parcelas))})]})]})]}),s.cupomAplicado&&e.jsx("div",{className:"bg-green-50 dark:bg-green-950/20 p-2 rounded-md",children:e.jsxs("p",{className:"text-xs text-green-700 dark:text-green-400 flex items-center gap-1",children:[e.jsx(xe,{className:"h-3 w-3"}),"Cupom ",e.jsx("strong",{children:s.cupomAplicado})," aplicado"]}
5)}),a&&e.jsxs(e.Fragment,{children:[e.jsx(te,{}),e.jsxs("div",{className:"relative group",children:[e.jsx("div",{className:"absolute -inset-1 bg-gradient-to-r from-destructive via-primary to-destructive rounded-2xl opacity-0 group-hover:opacity-75 blur-lg transition-all duration-500"}),e.jsx("div",{className:"absolute -inset-[2px] rounded-2xl bg-[conic-gradient(from_var(--gradient-angle),hsl(var(--destructive))_0%,hsl(var(--primary))_25%,hsl(var(--destructive))_50%,hsl(var(--primary))_75%,hsl(var(--destructive))_100%)] animate-[spin-gradient_2s_linear_infinite]"}),e.jsx("div",{className:"absolute inset-[2px] rounded-[14px] bg-primary"}),e.jsxs("button",{onClick:a,disabled:!s.precoBase,className:"relative w-full h-11 px-6 rounded-2xl text-primary-foreground font-medium disabled:opacity-50 disabled:pointer-events-none flex items-center justify-center gap-2 overflow-hidden whitespace-nowrap",children:[e.jsx("div",{className:"absolute inset-0 bg-gradient-to-r from-transparent via-white/20 to-transparent -translate-x-full animate-[shimmer_2s_ease-in-out_infinite]"}),e.jsx(Ye,{className:"h-4 w-4 relative z-10 flex-shrink-0"}),e.jsx("span",{className:"relative z-10 animate-text-shimmer font-semibold",children:"Criar Orçamento no HubSpot"})]})]})]})]})]})}function qs(){const s=Ze();return es({mutationFn:async a=>{var c;const{data:r}=await Y.auth.getSession();if(!r.session)throw new Error("Usuário não autenticado");const t=await Y.functions.invoke("create-hubspot-quote",{body:a});if(t.error)throw new Error(t.error.message||"Erro ao criar orçamento");if(!((c=t.data)!=null&&c.success))throw new Error("Falha ao criar orçamento no HubSpot");return t.data},onSuccess:a=>{s.invalidateQueries({queryKey:["sim-orcamentos"]}),Z.success("Orçamento criado com sucesso!",{description:"O orçamento foi sincronizado com o HubSpot.",action:{label:"Ver no HubSpot",onClick:()=>window.open(a.hubspot_deal_url,"_blank")}})},onError:a=>{console.error("Error creating quote:",a),Z.error("Erro ao criar orçamento",{description:a.message})}})}class Me extends Error{constructor(r,t){super(r);je(this,"code");this.name="HubSpotDealSearchError",this.code=t}}async function ze(s){const{data:a,error:r}=await Y.functions.invoke("hubspot-search-deals",{body:s});if(r){let t=r.message,c;if(r instanceof _s)try{const n=JSON.parse(await r.context.text());t=(n==null?void 0:n.error)||t,c=n==null?void 0:n.code}catch{}throw new Me(t,c)}if(a!=null&&a.error)throw new Me(a.error,a.code);return a}function Ls(s,a=400){const[r,t]=i.useState(s);return i.useEffect(()=>{const c=setTimeout(()=>t(s),a);return()=>clearTimeout(c)},[s,a]),r}function zs(s,a){const r=Ls(s);return ue({queryKey:["hubspot-deal-search",r],enabled:a,staleTime:6e4,retry:!1,queryFn:async()=>{const t=await ze({action:"search",term:r});return{deals:(t==null?void 0:t.deals)??[],allOwners:(t==null?void 0:t.allOwners)===!0}}})}function Bs(s){return ue({queryKey:["hubspot-deal-detail",s],enabled:!!s,staleTime:6e4,retry:!1,queryFn:async()=>await ze({action:"detail",dealId:s})})}const $s=ce({contato:ce({nome:G().min(2,"Nome deve ter pelo menos 2 caracteres"),email:G().email("Email inválido"),telefone:G().optional(),cargo:G().optional()}),empresa:ce({nome:G().min(2,"Nome da empresa é obrigatório"),cnpj:G().optional(),quantidade_funcionarios:As().optional()})});function Hs({open:s,onOpenChange:a,resultado:r}){const[t,c]=i.useState({nome:"",email:"",telefone:"",cargo:""}),[n,x]=i.useState({nome:"",cnpj:"",quantidade_funcionarios:r.colaboradores}),[h,j]=i.useState({}),[m,S]=i.useState(!1),[v,D]=i.useState(null),[_,H]=i.useState(De(new Date,7)),[O,I]=i.useState("existente"),[q,Q]=i.useState(""),[N,T]=i.useState(null),[U,B]=i.useState(!1),M=i.useRef(!1),{data:E,isLoading:L,error:l}=zs(q,s&&O==="existente"&&!N),d=(E==null?void 0:E.deals)??[],C=(E==null?void 0:E.allOwners)===!0,w=l?l.message:null,{data:b,isFetching:p}=Bs((N==null?void 0:N.id)??null);i.useEffect(()=>{b&&(b.contato&&c(o=>{var y,g,V,$;return{nome:((y=b.contato)==null?void 0:y.nome)||o.nome,email:((g=b.contato)==null?void 0:g.email)||o.email,telefone:((V=b.contato)==null?void 0:V.telefone)||o.telefone,cargo:(($=b.contato)==null?void 0:$.cargo)||o.cargo}}),b.empresa&&x(o=>{var y,g;return{nome:((y=b.empresa)==null?void 0:y.nome)||o.nome,cnpj:((g=b.empresa)==null?void 0:g.cnpj)||o.cnpj,quantidade_funcionarios:o.quantidade_funcionarios}}))},[b]);const{options:W,isLoading:ee}=Ss("cargo_select");i.useEffect(()=>{v&&!M.current&&(M.current=!0,ne({particleCount:100,spread:70,origin:{y:.6},colors:["#081a4f","#F59E0B","#22C55E","#3B82F6"]}),setTimeout(()=>{ne({particleCount:50,angle:60,spread:55,origin:{x:0},colors:["#081a4f","#F59E0B","#22C55E"]}),ne({particleCount:50,angle:120,spread:55,origin:{x:1},colors:["#081a4f","#F59E0B","#3B82F6"]})},200))},[v]),i.useEffect(()=>{s&&(M.current=!1)},[s]);const{mutate:se,isPending:X}=qs();i.useEffect(()=>{s&&(c({nome:"",email:"",telefone:"",cargo:""}),x({nome:"",cnpj:"",quantidade_funcionarios:r.colaboradores}),j({}),D(null),H(De(new Date,7)),I("existente"),Q(""),T(null),B(!1))},[s,r.colaboradores]);const Be=async o=>{const y=o.replace(/\D/g,"");if(y.length===14){S(!0);try{const{data:g,error:V}=await Y.functions.invoke("consultar-documento",{body:{documento:y,tipo:"cnpj"}});
5if(!V&&(g!=null&&g.success)&&(g!=null&&g.dados)){const $=g.dados;x(ae=>({...ae,nome:$.razao_social||$.nome_fantasia||ae.nome})),$.telefone&&!t.telefone&&c(ae=>({...ae,telefone:$.telefone}))}}catch(g){console.error("Error consulting CNPJ:",g)}finally{S(!1)}}},$e=()=>{if(O==="existente"&&!N){Z.error("Selecione um negócio do HubSpot ou mude para criar um novo.");return}const o=$s.safeParse({contato:t,empresa:n});if(!o.success){const y={};o.error.errors.forEach(g=>{const V=g.path.join(".");y[V]=g.message}),j(y);return}j({}),se({contato:t,empresa:n,simulacao:r,dataExpiracao:_.toISOString().split("T")[0],...O==="existente"&&N?{dealId:N.id,atualizarValorNegocio:U}:{}},{onSuccess:y=>{D({hubspot_deal_url:y.hubspot_deal_url,hubspot_quote_url:y.hubspot_quote_url||null,createdAt:new Date})}})},he=r.totalMensalComDesconto*12,He=o=>new Intl.DateTimeFormat("pt-BR",{day:"2-digit",month:"2-digit",year:"numeric",hour:"2-digit",minute:"2-digit"}).format(o);return v?e.jsx(be,{open:s,onOpenChange:a,children:e.jsxs(Ne,{className:"max-w-md overflow-hidden",children:[e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute -inset-4 bg-gradient-to-r from-green-500/20 via-primary/20 to-amber-500/20 rounded-3xl blur-xl animate-pulse"}),e.jsx("div",{className:"relative",children:e.jsxs(ve,{className:"text-center pb-2",children:[e.jsx("div",{className:"flex justify-center mb-4",children:e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-0 bg-green-500/30 rounded-full blur-lg animate-ping"}),e.jsx("div",{className:"relative w-20 h-20 bg-gradient-to-br from-green-400 to-green-600 rounded-full flex items-center justify-center shadow-lg animate-[bounce_0.5s_ease-out]",children:e.jsx(ss,{className:"h-10 w-10 text-white"})}),e.jsx(Ce,{className:"absolute -top-2 -right-2 h-6 w-6 text-amber-400 animate-pulse"}),e.jsx(Ce,{className:"absolute -bottom-1 -left-3 h-5 w-5 text-primary animate-pulse delay-75"})]})}),e.jsx(we,{className:"text-2xl font-bold bg-gradient-to-r from-primary via-green-600 to-amber-500 bg-clip-text text-transparent animate-[fadeIn_0.5s_ease-out]",children:"ð Orçamento Criado!"}),e.jsx(ye,{className:"text-base animate-[fadeIn_0.7s_ease-out]",children:"Sincronizado com sucesso no HubSpot"})]})})]}),e.jsxs("div",{className:"space-y-4 py-2",children:[e.jsx("div",{className:"flex justify-center animate-[fadeIn_0.6s_ease-out]",children:e.jsxs(k,{variant:"secondary",className:"px-3 py-1.5 gap-2 text-sm bg-muted/50",children:[e.jsx(Le,{className:"h-3.5 w-3.5"}),"Criado em ",He(v.createdAt)]})}),e.jsx(A,{className:"border-green-200/50 bg-gradient-to-br from-background to-green-50/30 dark:to-green-950/10 shadow-lg animate-[slideUp_0.5s_ease-out]",children:e.jsx(F,{className:"pt-5 pb-4",children:e.jsxs("div",{className:"space-y-3 text-sm",children:[e.jsxs("div",{className:"flex justify-between items-center py-1.5 border-b border-border/50",children:[e.jsxs("span",{className:"text-muted-foreground flex items-center gap-2",children:[e.jsx(de,{className:"h-4 w-4"}),"Empresa"]}),e.jsx("span",{className:"font-semibold text-right max-w-[200px] truncate",children:n.nome})]}),e.jsxs("div",{className:"flex justify-between items-center py-1.5 border-b border-border/50",children:[e.jsxs("span",{className:"text-muted-foreground flex items-center gap-2",children:[e.jsx(_e,{className:"h-4 w-4"}),"Contato"]}),e.jsx("span",{className:"font-semibold",children:t.nome})]}),e.jsxs("div",{className:"flex justify-between items-center py-1.5 border-b border-border/50",children:[e.jsxs("span",{className:"text-muted-foreground flex items-center gap-2",children:[e.jsx(Se,{className:"h-4 w-4"}),"Plano"]}),e.jsx(k,{variant:"outline",className:"font-semibold",children:r.plano})]}),e.jsxs("div",{className:"flex justify-between items-center py-1.5",children:[e.jsxs("span",{className:"text-muted-foreground flex items-center gap-2",children:[e.jsx(Pe,{className:"h-4 w-4"}),"Valor Anual"]}),e.jsx("span",{className:"font-bold text-lg text-primary",children:u(he)})]})]})})}),e.jsxs("div",{className:"space-y-2 animate-[fadeIn_0.8s_ease-out]",children:[v.hubspot_quote_url&&e.jsxs(f,{className:"w-full bg-gradient-to-r from-primary to-primary/80 hover:from-primary/90 hover:to-primary shadow-lg hover:shadow-xl transition-all duration-300",onClick:()=>window.open(v.hubspot_quote_url,"_blank"),children:[e.jsx(ke,{className:"h-4 w-4 mr-2"}),"Ver Orçamento Público"]}),e.jsxs(f,{variant:v.hubspot_quote_url?"outline":"default",className:`w-full transition-all duration-300 ${v.hubspot_quote_url?"hover:bg-muted":"bg-gradient-to-r from-primary to-primary/80 hover:from-primary/90 hover:to-primary shadow-lg hover:shadow-xl"}`,onClick:()=>window.open(v.hubspot_deal_url,"_blank"),children:[e.jsx(ke,{className:"h-4 w-4 mr-2"}),"Ver Negócio no HubSpot"]})]})]}),e.jsx(Ae,{className:"animate-[fadeIn_1s_ease-out]",children:e.jsx(f,{variant:"ghost",onClick:()=>a(!1),className:"w-full hover:bg-muted",children:"Fechar"})})]})}):e.jsx(be,{open:s,onOpenChange:a,children:e.jsxs(Ne,{className:"max-w-2xl max-h-[90vh] overflow-y-auto p-4 sm:p-6 border-2 border-primary/20 shadow-[0_0_30px_-5px_hsl(var(--primary)/0.3)]",children:[e.jsxs(ve,{children:[e.jsxs(we,{className:"flex items-center gap-2 text-lg sm:text-xl",children:[e.jsx(le,{className:"h-5 w-5"}),"Criar Orçamento no HubSpot"]}),e.jsx(ye,{className:"text-sm",children:"Use um negócio que já existe no HubSpot ou crie um novo do zero."})]}),e.jsxs("div",{className:"space-y-4 py-2",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs(f,{type:"button",variant:O==="existente"?"default":"outline",className:"h-auto py-2 text-xs sm:text-sm",onClick:()=>I("existente"),children:[e.jsx(Ee,{className:"h-4 w-4 mr-2"}),"Usar negócio existente"]}),e.jsxs(f,{type:"button",variant:O==="novo"?"default":"outline",className:"h-auto py-2 text-xs sm:text-sm",onClick:()=>{I("novo"),T(null)},children:[e.jsx(le,{className:"h-4 w-4 mr-2"}),"Criar novo negócio"]})]}),O==="existente"&&e.jsx(A,{className:"border-primary/30",children:e.jsx(F,{className:"p-4 space-y-3",children:N?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold",children:[e.jsx(Ee,{className:"h-4 w-4 text-primary shrink-0"}),e.jsx("span",{className:"truncate",children:N.name})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mt-1",children:[e.jsx(k,{variant:"secondary",className:"text-xs",children:N.pipelineLabel}),N.amount!=null&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["Valor atual: ",u(N.amount)]})]})]}),e.jsxs(f,{type:"button",variant:"ghost",size:"sm",onClick:()=>T(null),children:[e.jsx(re,{className:"h-4 w-4 mr-1"}),"Trocar"]})]}),p&&e.jsxs("p",{className:"text-xs text-muted-foreground flex items-center gap-1",children:[e.jsx(oe,{className:"h-3 w-3 animate-spin"}),"Carregando contato e empresa do negócio..."]}),e.jsxs("label",{className:"flex items-start gap-2 text-xs sm:text-sm cursor-pointer",children:[e.jsx(as,{checked:U,onCheckedChange:o=>B(o===!0),className:"mt-0.5"}),e.jsxs("span",{children:["Atualizar o valor do negócio com o valor da simulação",e.jsx("span",{className:"block text-xs text-muted-foreground",children:"Substitui o valor anual e o cupom do negócio no HubSpot."})]})]})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsx(P,{className:"text-xs sm:text-sm",children:C?"Buscar negócio (todos os responsáveis)":"Buscar negócio (somente os seus)"}),e.jsxs("div",{className:"relative",children:[e.jsx(ts,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(R,{placeholder:"Nome do negócio...",value:q,onChange:o=>Q(o.target.value),className:"h-9 sm:h-10 pl-9"})]}),w?e.jsxs("div",{className:"rounded-md border border-amber-500/30 bg-amber-500/10 p-3 space-y-2",children:[e.jsx("p",{className:"text-xs text-amber-700 dark:text-amber-400",children:w}),e.jsx(f,{type:"button",variant:"outline",size:"sm",className:"h-7 text-xs",onClick:()=>{I("novo"),T(null)},children:"Criar novo negócio"})]}):e.jsxs("div",{className:"max-h-56 overflow-y-auto rounded-md border border-border/50 divide-y divide-border/50",children:[L&&e.jsxs("div",{className:"p-3 space-y-2",children:[e.jsx(ie,{className:"h-4 w-3/4"}),e.jsx(ie,{className:"h-4 w-1/2"})]}),!L&&d.length===0&&e.jsx("p",{className:"p-3 text-xs text-muted-foreground",children:q?`Nenhum negócio encontrado para "${q}".`:"Nenhum negócio encontrado."}),!L&&d.map(o=>e.jsxs("button",{type:"button",onClick:()=>T({id:o.id,name:o.name,pipelineLabel:o.pipelineLabel,amount:o.amount}),className:"w-full text-left p-3 hover:bg-muted/50 transition-colors",children:[e.jsx("div",{className:"text-sm font-medium truncate",children:o.name}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mt-1",children:[e.jsx(k,{variant:"outline",className:"text-[10px]",children:o.pipelineLabel}),o.ownerName&&e.jsx("span",{className:"text-xs text-muted-foreground truncate",children:o.ownerName}),o.amount!=null&&e.jsx("span",{className:"text-xs text-muted-foreground",children:u(o.amount)})]})]},o.id))]})]})})}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsx(A,{className:"border-border/50",children:e.jsxs(F,{className:"p-4 space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold text-primary border-b border-border/50 pb-2",children:[e.jsx(_e,{className:"h-4 w-4"}),"Dados do Contato"]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx(P,{htmlFor:"nome",className:"text-xs sm:text-sm",children:"Nome *"}),e.jsx(R,{id:"nome",placeholder:"Nome completo",value:t.nome,onChange:o=>c({...t,nome:o.target.value}),className:`h-9 sm:h-10 ${h["contato.nome"]?"border-destructive":""}`}),h["contato.nome"]&&e.jsx("p",{className:"text-xs text-destructive mt-1",children:h["contato.nome"]})]}),e.jsxs("div",{children:[e.jsx(P,{htmlFor:"email",className:"text-xs sm:text-sm",children:"Email *"}),e.jsx(R,{id:"email",type:"email",placeholder:"[email protected]",value:t.email,onChange:o=>c({...t,email:o.target.value}),className:`h-9 sm:h-10 ${h["contato.email"]?"border-destructive":""}`}),h["contato.email"]&&e.jsx("p",{className:"text-xs text-destructive mt-1",children:h["contato.email"]})]}),e.jsxs("div",{children:[e.jsx(P,{htmlFor:"telefone",className:"text-xs sm:text-sm",children:"Telefone"}),e.jsx(ys,{value:t.telefone||"",onChange:o=>c({...t,telefone:o}),showValidation:!1})]}),e.jsxs("div",{children:[e.jsx(P,{htmlFor:"cargo",className:"text-xs sm:text-sm",children:"Cargo"}),ee?e.jsx(ie,{className:"h-9 sm:h-10 w-full rounded-lg"}):W.length>0?e.jsxs(os,{value:t.cargo,onValueChange:o=>c({...t,cargo:o}),children:[e.jsx(rs,{id:"cargo",className:"h-9 sm:h-10",children:e.jsx(ns,{placeholder:"Selecione o cargo"})}),e.jsx(ls,{children:W.map(o=>e.jsx(is,{value:o.value,children:o.label},o.value))})]}):e.jsx(R,{id:"cargo",placeholder:"Ex: Gerente de RH",value:t.cargo,onChange:o=>c({...t,cargo:o.target.value}),className:"h-9 sm:h-10"})]})]})]})}),e.jsx(A,{className:"border-border/50",children:e.jsxs(F,{className:"p-4 space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold text-primary border-b border-border/50 pb-2",children:[e.jsx(de,{className:"h-4 w-4"}),"Dados da Empresa"]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx(P,{htmlFor:"cnpj",className:"text-xs sm:text-sm",children:"CNPJ"}),e.jsx(ws,{mask:"99.999.999/9999-99",value:n.cnpj,onChange:o=>x({...n,cnpj:o.target.value}),onBlur:o=>Be(o.target.value),disabled:m,children:o=>{const{ref:y,...g}=o;return e.jsx(R,{...g,id:"cnpj",placeholder:"00.000.000/0000-00",className:"h-9 sm:h-10"})}}),m&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-1 flex items-center gap-1",children:[e.jsx(oe,{className:"h-3 w-3 animate-spin"}),"Consultando CNPJ..."]})]}),e.jsxs("div",{children:[e.jsx(P,{htmlFor:"empresa-nome",className:"text-xs sm:text-sm",children:"Nome da Empresa *"}),e.jsx(R,{id:"empresa-nome",placeholder:"Razão social ou nome fantasia",value:n.nome,onChange:o=>x({...n,nome:o.target.value}),className:`h-9 sm:h-10 ${h["empresa.nome"]?"border-destructive":""}`}),h["empresa.nome"]&&e.jsx("p",{className:"text-xs text-destructive mt-1",children:h["empresa.nome"]})]}),e.jsxs("div",{children:[e.jsx(P,{htmlFor:"funcionarios",className:"text-xs sm:text-sm",children:"Quantidade de Funcionários"}),e.jsx(R,{id:"funcionarios",type:"number",value:n.quantidade_funcionarios||"",onChange:o=>x({...n,quantidade_funcionarios:parseInt(o.target.value)||void 0}),className:"h-9 sm:h-10"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Pré-preenchido com a quantidade do simulador"})]})]})]})})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center gap-2 p-3 rounded-lg bg-muted/30 border border-border/50",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium",children:[e.jsx(Ps,{className:"h-4 w-4 text-primary"}),e.jsx("span",{children:"Validade do Orçamento:"})]}),e.jsxs(cs,{children:[e.jsx(ms,{asChild:!0,children:e.jsxs(f,{variant:"outline",className:me("w-full sm:w-auto justify-start text-left font-normal h-9",!_&&"text-muted-foreground"),children:[e.jsx(Fe,{className:"mr-2 h-4 w-4"}),_?ks(_,"dd/MM/yyyy",{locale:Oe}):e.jsx("span",{children:"Selecione a data"})]})}),e.jsx(ds,{className:"w-auto p-0",align:"start",children:e.jsx(xs,{mode:"single",selected:_,onSelect:o=>o&&H(o),disabled:o=>o<new Date,initialFocus:!0,className:me("p-3 pointer-events-auto"),locale:Oe})})]}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["(",Math.ceil((_.getTime()-new Date().getTime())/(1e3*60*60*24))," dias)"]})]}),e.jsx(A,{className:"bg-muted/30",children:e.jsxs(F,{className:"p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold",children:[e.jsx(Se,{className:"h-4 w-4 text-primary"}),"Resumo do Orçamento"]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"font-medium",children:r.plano}),e.jsxs(k,{variant:"secondary",className:"text-xs",children:[r.colaboradores," colaboradores"]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2 text-sm",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Pe,{className:"h-4 w-4 text-muted-foreground shrink-0"}),e.jsx("span",{className:"text-muted-foreground",children:"Total Mensal:"}),e.jsx("span",{className:"font-medium",children:u(r.totalMensalComDesconto)})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Fe,{className:"h-4 w-4 text-muted-foreground shrink-0"}),e.jsx("span",{className:"text-muted-foreground",children:"Valor Anual:"}),e.jsx("span",{className:"font-semibold text-primary",children:u(he)})]})]}),r.treinamento&&e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(Re,{className:"h-4 w-4 text-muted-foreground shrink-0"}),e.jsx("span",{className:"text-muted-foreground",children:"Treinamento:"}),e.jsxs("span",{className:"font-medium",children:[r.treinamento.nome," - ",u(r.treinamento.precoFinal)]})]}),r.cupomAplicado&&e.jsxs(k,{variant:"secondary",className:"text-xs",children:["Cupom: ",r.cupomAplicado]})]})})]}),e.jsxs(Ae,{className:"flex-col sm:flex-row gap-2 pt-2",children:[e.jsx(f,{variant:"outline",onClick:()=>a(!1),disabled:X,className:"w-full sm:w-auto order-2 sm:order-1",children:"Cancelar"}),e.jsx(f,{onClick:$e,disabled:X,className:"w-full sm:w-auto order-1
5sm:order-2",children:X?e.jsxs(e.Fragment,{children:[e.jsx(oe,{className:"h-4 w-4 mr-2 animate-spin"}),"Criando..."]}):e.jsxs(e.Fragment,{children:[e.jsx(le,{className:"h-4 w-4 mr-2"}),"Criar Orçamento"]})})]})]})})}const Qs={PLANO_EMPREENDEDOR:["Controle de ponto básico","App mobile","Relatórios simples","Suporte por email"],PLANO_PROFISSIONAL:["Tudo do Empreendedor","Banco de horas","Gestão de escalas","API de integração","Reconhecimento facial","Suporte prioritário"],PLANO_CORPORATIVO:["Tudo do Profissional","Multi-empresas","Relatórios avançados","Consultoria de implantação","SLA garantido","Suporte 24/7"]};function Us(){const{state:s,planos:a,planoAtual:r,carregandoPlanos:t,erroPlanos:c,precoBase:n,faixaLabel:x,resultado:h,faixasDisponiveis:j,cupomValidado:m,cupomError:S,validandoCupom:v,setPlano:D,setColaboradores:_,setEmpresasAdicionais:H,setApiAberta:O,setReconhecimentoFacial:I,setTreinamento:q,setCupomCodigo:Q,aplicarCupom:N,limparCupom:T,resetar:U}=Ds(),[B,M]=i.useState(!1),[E,L]=i.useState(""),[l,d]=i.useState(null),[C,w]=i.useState(!1),b=()=>{const p=parseInt(E,10);if(!Number.isInteger(p)||p<1||p>5e3){d("Informe um número inteiro entre 1 e 5000 colaboradores.");return}d(null),_(p,!0),M(!1)};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Simulador de Planos"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Configure o plano ideal para seu cliente"})]}),e.jsxs(f,{variant:"outline",size:"sm",onClick:U,children:[e.jsx(us,{className:"h-4 w-4 mr-2"}),"Resetar"]})]}),c&&e.jsx("p",{className:"text-sm text-destructive",children:"Não foi possÃvel carregar o catálogo de planos. Recarregue a página."}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-3",children:[e.jsxs("div",{className:"lg:col-span-2 space-y-6",children:[e.jsxs(A,{children:[e.jsx(K,{className:"pb-3",children:e.jsxs(J,{className:"text-base flex items-center gap-2",children:[e.jsx(ps,{className:"h-5 w-5"}),"Quantidade de Colaboradores"]})}),e.jsxs(F,{children:[B?e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(R,{type:"number",placeholder:"Ex: 85",value:E,onChange:p=>{L(p.target.value),d(null)},onKeyDown:p=>{p.key==="Enter"&&b()},className:"max-w-[150px]",min:1,max:5e3,step:1}),e.jsx(f,{onClick:b,children:"Confirmar"}),e.jsx(f,{variant:"outline",onClick:()=>{M(!1),L(""),d(null)},children:"Cancelar"})]}),l?e.jsx("p",{className:"text-sm text-destructive",children:l}):e.jsx("p",{className:"text-xs text-muted-foreground",children:"Qualquer quantidade é aceita: o valor entra na faixa correspondente do catálogo."})]}):e.jsxs("div",{className:"flex flex-wrap gap-2",children:[j.map(p=>e.jsx(f,{variant:s.colaboradores===p?"default":"outline",size:"sm",onClick:()=>_(p),children:p},p)),e.jsx(f,{variant:s.colaboradoresCustom?"default":"outline",size:"sm",onClick:()=>M(!0),children:"Personalizado"})]}),s.colaboradoresCustom&&!B&&e.jsxs("p",{className:"text-sm text-muted-foreground mt-2",children:["Quantidade personalizada: ",e.jsx("strong",{children:s.colaboradores})," colaboradores"]}),x&&e.jsxs("p",{className:"text-sm text-muted-foreground mt-2",children:[e.jsx(k,{variant:"secondary",className:"mr-2",children:(r==null?void 0:r.name)??"Plano"}),x]}),r&&n==null&&e.jsxs("p",{className:"text-sm text-destructive mt-2",children:[r.name," atende até ",r.maxColaboradores," colaboradores. Escolha outro plano para esta quantidade."]})]})]}),e.jsxs("div",{children:[e.jsx(P,{className:"text-base font-medium mb-3 block",children:"Selecione o Plano"}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-3",children:[t&&[0,1,2].map(p=>e.jsx(A,{className:"h-64 animate-pulse bg-muted/40"},p)),!t&&a.map(p=>{const W=Ie(p,s.colaboradores),ee=W==null,se=W??0,X=!ee&&s.colaboradores>0?se/s.colaboradores:void 0;return e.jsx(Os,{planName:p.name,basePrice:se,pricePerEmployee:X,breakdown:qe(p,s.colaboradores)??void 0,indisponivel:ee,features:Qs[p.code]??[],maxEmployees:p.maxColaboradores==null?"Sem limite de faixa":p.maxColaboradores,isSelected:s.planoCode===p.code,onSelect:()=>D(p.code),recommended:p.code==="PLANO_PROFISSIONAL"},p.code)})]})]}),e.jsx(Ts,{planoCode:s.planoCode,empresasAdicionaisPacotes:s.empresasAdicionaisPacotes,apiAberta:s.apiAberta,reconhecimentoFacialQtd:s.reconhecimentoFacialQtd,onEmpresasChange:H,onApiAbertaChange:O,onReconhecimentoChange:I}),e.jsx(Ms,{selected:s.treinamento,onSelect:q,desconto:(m==null?void 0:m.desconto_treinamento_tipo)==="percentual"?m.desconto_treinamento_valor:0}),e.jsx(Rs,{codigo:s.cupomCodigo,cupomValidado:m,cupomError:S,validando:v,onCodigoChange:Q,onAplicar:N,onLimpar:T})]}),e.jsx("div",{children:e.jsx(Is,{resultado:h,onCriarOrcamento:()=>w(!0)})})]}),e.jsx(Hs,{open:C,onOpenChange:w,resultado:h})]})}function va(){return e.jsx(Ve,{children:e.jsxs(Ge,{children:[e.jsx(Es,{title:"Simulador de Planos",subtitle:"Calcule o valor ideal para seus clientes"}),e.jsx("div",{className:"space-y-6",children:e.jsx(Us,{})})]})})}export{va as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.