1import{b as M,a as B,G as H,E as q,u as O,r as i,w as G,aJ as J,aK as K,aL as W,t as N,j as e,aH as X,z as _,I as Q,af as V,X as Y,c as U,ak as P,S as Z,x as ee,W as g}from"./main-DX7XzkoU.js";import{U as ae}from"./upload-CRdrqrw1.js";import{S as te}from"./search-Du1BtiHK.js";import{I as se}from"./instagram-uOX4SJX4.js";const de=()=>{const{t:a}=M(),v=B(),{addProfileToCache:y}=H(),{toast:d}=q(),{user:n,isLoading:f}=O(),[o,u]=i.useState("connecting"),[re,w]=i.useState(null),x=i.useRef(!1),[h,R]=i.useState(""),[b,T]=i.useState(""),[m,S]=i.useState(null),[k,I]=i.useState(null),[ne,E]=i.useState(!1),j=i.useRef(null),s=G();console.log("[InstagramSetup] Component mounted, pendingUsername:",s,"authLoading:",f,"user:",!!n);const L=async()=>{if(console.log("[InstagramSetup] connectProfile called, pendingUsername:",s),!s){console.log("[InstagramSetup] Sem username pendente, indo para dashboard"),v("/dashboard",{replace:!0});return}u("connecting"),w(null);try{console.log("[InstagramSetup] Conectando perfil:",s);const t=await ee.saveInstagramProfile({username:s,context_data:{}});console.log("[InstagramSetup] Perfil conectado:",t.profile.username),localStorage.removeItem("pendingInstagramHandle"),y(t.profile),N("setup_complete",{page:"/setup",mode:"automatic"},n==null?void 0:n.id),v(`/profile-onboarding?profileId=${t.profile.id}&analyze=true`,{replace:!0})}catch(t){console.error("[InstagramSetup] Erro ao conectar perfil:",t),u("error"),w(t instanceof Error?t.message:"Erro ao conectar perfil")}};i.useEffect(()=>{if(console.log("[InstagramSetup] useEffect triggered, authLoading:",f,"user:",!!n,"hasStarted:",x.current),f){console.log("[InstagramSetup] Auth still loading, waiting...");return}if(!n){console.log("[InstagramSetup] Usuário não autenticado, aguardando...");return}if(x.current){console.log("[InstagramSetup] Already started, skipping...");return}x.current=!0,console.log("[InstagramSetup] Starting profile connection..."),J("instagram_setup",n.id),K("instagram_setup",n.id),W(n.id),N("setup_start",{page:"/setup"},n.id),L()},[f,n]);const C=()=>{x.current=!1,L()},F=()=>{u("manual")},z=t=>{var c;const r=(c=t.target.files)==null?void 0:c[0];if(!r)return;if(!["image/jpeg","image/png","image/gif","image/webp"].includes(r.type)){d({title:a("common.error"),description:a("onboarding_steps.toasts.invalid_image"),variant:"destructive"});return}if(r.size>5*1024*1024){d({title:a("common.error"),description:a("onboarding_steps.toasts.file_too_large"),variant:"destructive"});return}S(r),I(URL.createObjectURL(r))},$=()=>{S(null),I(null),j.current&&(j.current.value="")},A=async t=>{if(!m)return null;try{E(!0);const r=m.name.split(".").pop(),l=`profile-pics/${t}/${s}-${Date.now()}.${r}`,{error:c}=await g.storage.from("instagram-profile-pics").upload(l,m,{contentType:m.type,cacheControl:"86400"});if(c)throw c;const{data:{publicUrl:p}}=g.storage.from("instagram-profile-pics").getPublicUrl(l);return p}catch(r){return console.error("[InstagramSetup] Erro no upload do logo:",r),null}finally{E(!1)}},D=async()=>{if(s){if(!h.trim()){d({title:a("instagram_setup.manual.name_required"),variant:"destructive"});return}if(!b.trim()){d({title:a("instagram_setup.manual.description_required"),variant:"destructive"});return}u("submitting");try{let t=null;const{data:{user:r}}=await g.auth.getUser();r&&m&&(t=await A(r.id));const{data:l,error:c}=await g.functions.invoke("fetch-instagram-profile",{body:{username:s,manual_mode:!0,manual_data:{full_name:h.trim(),biography:b.trim(),profile_pic_url:t}}});if(c)throw c;if(!l.success)throw new Error(l.error||"Erro ao criar perfil");console.log("[InstagramSetup] Perfil manual criado:",l.profile.username),localStorage.removeItem("pendingInstagramHandle"),y(l.profile);const{data:{user:p}}=await g.auth.getUser();N("setup_complete",{page:"/setup",mode:"manual"},p==null?void 0:p.id),v(`/profile-onboarding?profileId=${l.profile.id}&analyze=true`,{replace:!0})}catch(t){console.error("[InstagramSetup] Erro ao criar perfil manual:",t),u("manual"),d({title:a("instagram_setup.add_error"),description:t instanceof Error?t.message:a("instagram_setup.add_error_desc"),variant:"destructive"})}}};return o==="manual"||o==="submitting"?e.jsx("div",{className:"min-h-screen bg-background flex items-center justify-center p-4",children:e.jsxs("div",{className:"w-full max-w-md
1space-y-6",children:[e.jsxs("div",{className:"text-center space-y-3",children:[e.jsx("div",{className:"w-16 h-16 rounded-full bg-amber-100 dark:bg-amber-900/30 flex items-center justify-center mx-auto",children:e.jsx(X,{className:"w-8 h-8 text-amber-600"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-semibold text-foreground",children:a("instagram_setup.manual.title")}),s&&e.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:["@",s]})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:a("instagram_setup.manual.description")})]}),e.jsxs("div",{className:"space-y-4 bg-card border rounded-lg p-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(_,{htmlFor:"fullName",children:[a("instagram_setup.manual.profile_name")," ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx(Q,{id:"fullName",value:h,onChange:t=>R(t.target.value),placeholder:a("instagram_setup.manual.profile_name_placeholder"),disabled:o==="submitting"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(_,{htmlFor:"biography",children:[a("instagram_setup.manual.business_description")," ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx(V,{id:"biography",value:b,onChange:t=>T(t.target.value),placeholder:a("instagram_setup.manual.business_description_placeholder"),className:"min-h-[120px] resize-none",disabled:o==="submitting"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("instagram_setup.manual.business_description_hint")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(_,{children:a("instagram_setup.manual.upload_logo")}),k?e.jsxs("div",{className:"relative w-20 h-20",children:[e.jsx("img",{src:k,alt:"Logo preview",className:"w-20 h-20 rounded-lg object-cover border"}),e.jsx("button",{type:"button",onClick:$,className:"absolute -top-2 -right-2 w-6 h-6 bg-red-500 text-white rounded-full flex items-center justify-center hover:bg-red-600",disabled:o==="submitting",children:e.jsx(Y,{className:"w-4 h-4"})})]}):e.jsxs("div",{onClick:()=>{var t;return(t=j.current)==null?void 0:t.click()},className:"w-full h-24 border-2 border-dashed rounded-lg flex flex-col items-center justify-center gap-2 cursor-pointer hover:border-primary/50 hover:bg-muted/50 transition-colors",children:[e.jsx(ae,{className:"w-6 h-6 text-muted-foreground"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:a("instagram_setup.manual.click_to_upload")})]}),e.jsx("input",{ref:j,type:"file",accept:"image/jpeg,image/png,image/gif,image/webp",onChange:z,className:"hidden"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("instagram_setup.manual.upload_logo_hint")})]})]}),e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(U,{onClick:D,disabled:o==="submitting"||!h.trim()||!b.trim(),className:"bg-gradient-to-r from-purple-600 to-pink-600 hover:from-purple-700 hover:to-pink-700",size:"lg",children:o==="submitting"?e.jsxs(e.Fragment,{children:[e.jsx(P,{className:"w-4 h-4 mr-2 animate-spin"}),a("instagram_setup.manual.creating_profile")]}):a("instagram_setup.continue")}),e.jsx(U,{variant:"ghost",onClick:C,disabled:o==="submitting",children:a("instagram_setup.manual.try_automatic")})]})]})}):o==="error"?e.jsx("div",{className:"min-h-screen bg-background flex items-center justify-center p-4",children:e.jsxs("div",{className:"w-full max-w-md
1space-y-6",children:[e.jsxs("div",{className:"text-center space-y-4",children:[e.jsx("div",{className:"w-20 h-20 rounded-2xl bg-gradient-to-br from-purple-100 to-pink-100 dark:from-purple-900/30 dark:to-pink-900/30 flex items-center justify-center mx-auto",children:e.jsx(te,{className:"w-10 h-10 text-purple-600 dark:text-purple-400"})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h2",{className:"text-xl font-semibold text-foreground",children:a("instagram_setup.alternative.title")}),s&&e.jsxs("p",{className:"text-primary font-medium",children:["@",s]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:a("instagram_setup.alternative.description")})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("button",{onClick:F,className:"w-full p-4 rounded-xl border-2 border-primary/20 bg-primary/5 hover:bg-primary/10 hover:border-primary/40 transition-all text-left group",children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"w-12 h-12 rounded-xl bg-gradient-to-r from-purple-600 to-pink-600 flex items-center justify-center flex-shrink-0",children:e.jsx(Z,{className:"w-6 h-6 text-white"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h3",{className:"font-semibold text-foreground group-hover:text-primary transition-colors",children:a("instagram_setup.alternative.manual_option_title")}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:a("instagram_setup.alternative.manual_option_desc")})]})]})}),e.jsx("button",{onClick:C,className:"w-full p-4 rounded-xl border border-border hover:bg-muted/50 transition-all text-left group",children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"w-12 h-12 rounded-xl bg-muted flex items-center justify-center flex-shrink-0",children:e.jsx(P,{className:"w-5 h-5 text-muted-foreground group-hover:text-foreground transition-colors"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h3",{className:"font-medium text-foreground",children:a("instagram_setup.alternative.retry_option_title")}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:a("instagram_setup.alternative.retry_option_desc")})]})]})})]})]})}):e.jsx("div",{className:"min-h-screen bg-background flex items-center justify-center",children:e.jsxs("div",{className:"text-center space-y-6 p-8",children:[e.jsx("div",{className:"w-24 h-24 rounded-2xl bg-gradient-to-r from-purple-600 to-pink-600 mx-auto flex items-center justify-center animate-pulse",children:e.jsx(se,{className:"w-12 h-12 text-white"})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h2",{className:"text-2xl font-bold text-foreground",children:a("common.connecting_profile","Conectando seu perfil")}),s&&e.jsxs("p",{className:"text-lg text-muted-foreground",children:["@",s]})]}),e.jsx("p",{className:"text-muted-foreground max-w-sm mx-auto",children:a("instagram_setup.connecting_description","Estamos buscando as informações do seu perfil do Instagram...")}),e.jsxs("div",{className:"flex justify-center gap-2 pt-4",children:[e.jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-purple-500 animate-bounce",style:{animationDelay:"0ms"}}),e.jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-purple-500 animate-bounce",style:{animationDelay:"150ms"}}),e.jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-purple-500 animate-bounce",style:{animationDelay:"300ms"}})]})]})})};export{de 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.