1import{a as K,u as V,G,al as H,r as t,t as T,ah as L,aN as J,j as n,o as U,c as W,A as Y}from"./main-DX7XzkoU.js";import{D as b,E as X,S as Z,a as ee,P as se}from"./Shell-Be4b4G4B.js";import{Q as te}from"./QuestionStep-RxoHXWyj.js";import{i as M,b as ne,t as ae,Q as re,h as oe}from"./questions-BNbuY1z3.js";import{d as $}from"./diagnosticService-DCDJsjWt.js";import"./avatar-DOhOFDwI.js";import"./list-checks-C7F0SyKS.js";const D="/dashboard",ie=["handle","confirma"],ce=({profile:u,onStart:a})=>n.jsxs("div",{className:"animate-in fade-in slide-in-from-bottom-2 duration-300",children:[n.jsx(X,{children:"Aproveite o máximo do seu plano"}),n.jsx(Z,{children:"Falta a IA conhecer o seu negócio"}),n.jsx(ee,{children:"Responda em um minuto e os próximos posts já saem com a cara do seu negócio."}),n.jsx("div",{className:"mt-7",children:n.jsx(se,{photo:u.photo,name:u.name,username:u.username})}),n.jsxs("div",{className:"mt-9",children:[n.jsxs(W,{size:"lg",onClick:a,className:"w-full gap-2 sm:w-auto",children:["Vamos lá",n.jsx(Y,{className:"h-4 w-4"})]}),n.jsx("p",{className:"mt-3.5 text-sm text-muted-foreground",children:"Você responde uma vez só."})]})]}),ge=()=>{const u=K(),{user:a}=V(),{selectedProfile:e,profilesLoading:w,hasInitialized:A,updateProfileInCache:y}=G(),{isAgency:C}=H(),[d,x]=t.useState("intro"),[m,v]=t.useState({}),[o,E]=t.useState(0),[S,N]=t.useState(!1),[f,O]=t.useState(!1),i=t.useRef({}),j=t.useRef(Promise.resolve()),l=(e==null?void 0:e.id)??null,k=(e==null?void 0:e.business_category_slug)??null,p=oe(k)?k:null;t.useEffect(()=>{!A||w||(!e||e.business_context_answered_at||C)&&u(D,{replace:!0})},[A,w,e,C,u]),t.useEffect(()=>{if(!e||f)return;const s=e.business_context,r=s&&typeof s=="object"&&!Array.isArray(s)?s:{};i.current=p?{...r,categoria:p}:r,v(i.current),Object.keys(r).some(_=>M(r,_))&&x("quiz"),O(!0)},[e,p,f]);const R=t.useMemo(()=>f?Object.keys(m).filter(s=>M(m,s)):[],[f]),I=t.useMemo(()=>[...ie,...p?["categoria"]:[],...R],[p,R]),c=t.useMemo(()=>ne(m,null,I),[m,I]),h=c[o],q=h?re[h]:void 0;t.useEffect(()=>{window.scrollTo({top:0,behavior:"smooth"})},[o,d]),t.useEffect(()=>{const s=d==="intro"?"intro":h;!s||!l||T("questionnaire_step",{step:s,profile_id:l},a==null?void 0:a.id,`${l}_${s}`)},[d,h,a==null?void 0:a.id,l]);const P=t.useCallback((s,r)=>{i.current={...i.current,[s]:r},v(i.current)},[]),B=t.useCallback((s,r)=>{i.current=ae(i.current,s,r),v(i.current)},[]),g=t.useCallback(async({silent:s=!1}={})=>{if(!(!e||S)){N(!0);try{await j.current.catch(()=>{});const r=i.current,_=await $.saveQuestionnaire(e.id,r,!0);y({...e,business_context:r,business_context_answered_at:_}),T("questionnaire_step",{step:"concluido",profile_id:e.id},a==null?void 0:a.id,`${e.id}_concluido`),s||L.success("Respostas salvas"),u(D,{replace:!0})}catch{L.error("Não conseguimos salvar suas respostas. Tente de novo."),N(!1)}}},[u,S,e,y,a==null?void 0:a.id]),Q=t.useRef(!1);t.useEffect(()=>{!f||c.length>0||!e||e.business_context_answered_at||Q.current||(Q.current=!0,g({silent:!0}))},[f,c.length,e,g]);const F=t.useCallback(()=>{if(o+1>=c.length){g();return}E(s=>s+1)},[g,o,c.length]);if(t.useEffect(()=>{d!=="quiz"||o===0||!l||(j.current=j.current.catch(()=>{}).then(()=>$.saveQuestionnaire(l,i.current,!1)).catch(s=>J.warn("gravação parcial do questionário falhou",{error:s})))},[o,d,l]),!e)return n.jsx(b,{children:n.jsxs("div",{className:"flex items-center gap-3 text-muted-foreground",children:[n.jsx(U,{className:"h-5 w-5 animate-spin text-primary"}),n.jsx("span",{children:"Preparandoâ¦"})]})});if(d==="intro"||c.length===0)return n.jsx(b,{children:n.jsx(ce,{profile:{photo:e.profile_pic_url,name:e.full_name||e.username,username:e.username},onStart:()=>c.length===0?void g():x("quiz")})});if(!q)return null;const z=o===c.length-1;return n.jsx(b,{counter:`${o+1} de ${c.length}`,steps:{total:c.length,current:o+1},children:n.jsx(te,{question:q,answers:m,categorySlug:m.categoria||null,onAnswer:P,onToggle:B,onAdvance:F,onBack:o>0?()=>E(s=>Math.max(0,s-1)):()=>x("intro"),cta:z?S?"Salvandoâ¦":"Concluir":"Continuar",isLast:z},h)})};export{ge 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.