1import{b as E,j as e,C as B,U as ne,c as A,o as $s,r as m,I as F,H,a2 as k,X as _s,ak as X,z as P,aH as Ys,af as te,S as re,a as Le,E as js,G as ys,W as ge,x as Ns,d as Vs,a4 as Ws,aI as q,a6 as qs}from"./main-DX7XzkoU.js";import{A as xe,a as fe,b as he,c as be,d as _e,e as je,f as ye,g as Ne}from"./alert-dialog-W0hIlYre.js";import{c as Js,f as ds}from"./imageCompression-CmCw4g5L.js";import{i as Ks}from"./image-file-BbkB38iy.js";import{p as Xs,e as Zs}from"./pt-BR-g-tPW2Ip.js";import{I as us}from"./instagram-uOX4SJX4.js";import{f as Qs}from"./formatDistanceToNow-BwcGd3xH.js";import{P as Pe,a as Ie,b as Oe}from"./popover-C2ojZSpS.js";import{S as De,a as Fe,b as Re,c as ze,d as Be}from"./sheet-D4yLKOxB.js";import{S as Ue}from"./scroll-area-D4uBgFjC.js";import{u as Me}from"./useMobile-BUXe42ED.js";import{S as Ge}from"./search-Du1BtiHK.js";import{C as He,u as et}from"./useBusinessCategories-CGGBgn3A.js";import{U as ve}from"./upload-CRdrqrw1.js";import{P as vs}from"./palette-OTKsHiwO.js";import{T as ws}from"./type-BrJDeCW1.js";import{b as st}from"./index-Bf_8NQ-v.js";import{G as Ss}from"./globe-BBWCCznd.js";import{B as ke}from"./badge-BOGaWzi1.js";import{P as Cs}from"./plus-C6FQ2-b-.js";import{m as ae}from"./proxy-BFtvzxWL.js";import{C as ks}from"./chevron-right-D27HfhtL.js";import{A as Es}from"./index-CSlo_wNj.js";import{P as tt}from"./pencil-DKi-GZ7V.js";import{T as at}from"./trash-2-pjGqSJFK.js";import{A as nt}from"./arrow-left-Cf41rOjY.js";import{S as rt}from"./save-eqVbSOS7.js";import{C as ot}from"./chevron-left-B_lb0x5L.js";import{F as ee}from"./Loading-EXr7BTFZ.js";import{u as As}from"./useInstagramProfiles-D_KQvT_K.js";import{P as ms,a as lt}from"./routes-Dh-CjbFu.js";import"./constructNow-CO-G4Rcw.js";import"./endOfMonth-DpURBOFe.js";const we=[{code:"pt-br",label:"Português (Brasil)",flag:"ð§ð·"},{code:"pt",label:"Português (Portugal)",flag:"ðµð¹"},{code:"en",label:"English",flag:"ðºð¸"},{code:"en-us",label:"English (US)",flag:"ðºð¸"},{code:"en-gb",label:"English (UK)",flag:"ð¬ð§"},{code:"es",label:"Español",flag:"ðªð¸"},{code:"es-mx",label:"Español (México)",flag:"ð²ð½"},{code:"fr",label:"Français",flag:"ð«ð·"},{code:"fr-ca",label:"Français (Canada)",flag:"ð¨ð¦"},{code:"de",label:"Deutsch",flag:"ð©ðª"},{code:"de-ch",label:"Deutsch (Schweiz)",flag:"ð¨ð"},{code:"it",label:"Italiano",flag:"ð®ð¹"},{code:"nl",label:"Nederlands",flag:"ð³ð±"},{code:"sv",label:"Svenska",flag:"ð¸ðª"},{code:"da",label:"Dansk",flag:"ð©ð°"},{code:"no",label:"Norsk",flag:"ð³ð´"},{code:"nb",label:"Norsk BokmÃ¥l",flag:"ð³ð´"},{code:"fi",label:"Suomi",flag:"ð«ð®"},{code:"is",label:"Ãslenska",flag:"ð®ð¸"},{code:"pl",label:"Polski",flag:"ðµð±"},{code:"ru",label:"Ð ÑÑÑкий",flag:"ð·ðº"},{code:"uk",label:"УкÑаÑнÑÑка",flag:"ðºð¦"},{code:"cs",label:"ÄeÅ¡tina",flag:"ð¨ð¿"},{code:"el",label:"Îλληνικά",flag:"ð¬ð·"},{code:"ro",label:"RomânÄ",flag:"ð·ð´"},{code:"hu",label:"Magyar",flag:"ððº"},{code:"ca",label:"Català ",flag:"ðªð¸"},{code:"ja",label:"æ¥æ¬èª",flag:"ð¯ðµ"},{code:"ko",label:"íêµì´",flag:"ð°ð·"},{code:"zh",label:"䏿 (ç®ä½)",flag:"ð¨ð³"},{code:"zh-tw",label:"䏿 (ç¹é«)",flag:"ð¹ð¼"},{code:"ar",label:"Ø§ÙØ¹Ø±Ø¨ÙØ©",flag:"ð¸ð¦"},{code:"he",label:"×¢×ר×ת",flag:"ð®ð±"},{code:"tr",label:"Türkçe",flag:"ð¹ð·"},{code:"hi",label:"हिनà¥à¤¦à¥",flag:"ð®ð³"},{code:"th",label:"à¹à¸à¸¢",flag:"ð¹ð"},{code:"vi",label:"Tiếng Viá»t",flag:"ð»ð³"},{code:"id",label:"Bahasa Indonesia",flag:"ð®ð©"},{code:"ms",label:"Bahasa Melayu",flag:"ð²ð¾"}],ps="pt-br",it=(s,a)=>new Intl.NumberFormat(a,{notation:"compact",maximumFractionDigits:1}).format(s),ct=({profile:s,onSync:a,syncing:r})=>{const{t:o,i18n:l}=E(),i=l.language.startsWith("pt")?Xs:Zs,u=s.last_synced?new Date(s.last_synced):null;return e.jsxs(B,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"relative flex h-12 w-12 shrink-0 items-center justify-center overflow-hidden rounded-full bg-muted ring-2 ring-border/60",children:s.profile_pic_url?e.jsx("img",{src:s.profile_pic_url,alt:"",className:"h-full w-full object-cover"}):e.jsx(us,{className:"h-5 w-5 text-muted-foreground"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("p",{className:"truncate font-semibold",children:["@",s.username]}),e.jsxs("p",{className:"flex flex-wrap items-center gap-x-1.5 text-xs text-muted-foreground",children:[e.jsxs("span",{className:"flex items-center gap-1 whitespace-nowrap",children:[e.jsx(ne,{className:"h-3 w-3"}),o("profile_settings.instagram_sync.followers",{formatted:it(s.followers??0,l.language)})]}),u&&e.jsxs("span",{className:"whitespace-nowrap",children:[e.jsx("span",{"aria-hidden":"true",children:"· "}),o("profile_settings.instagram_sync.last_synced",{when:Qs(u,{addSuffix:!0,locale:i})})]})]})]}),e.jsxs(A,{type:"button",variant:"outline",size:"sm",onClick:a,disabled:r,className:"shrink-0 gap-1.5",children:[r?e.jsx($s,{className:"h-4 w-4 animate-spin"}):e.jsx(us,{className:"h-4 w-4"}),o("profile_settings.instagram_sync.action")]})]}),e.jsx("p",{className:"mt-3 text-xs text-muted-foreground",children:o("profile_settings.instagram_sync.description")})]})},G=[{slug:"montserrat",name:"Montserrat"},{slug:"poppins",name:"Poppins"},{slug:"inter",name:"Inter"},{slug:"bebas-neue",name:"Bebas Neue"},{slug:"playfair-display",name:"Playfair Display"},{slug:"oswald",name:"Oswald"},{slug:"raleway",name:"Raleway"},{slug:"lato",name:"Lato"},{slug:"roboto",name:"Roboto"},{slug:"urbanist",name:"Urbanist"},{slug:"anton",name:"Anton"},{slug:"alfa-slab-one",name:"Alfa Slab One"},{slug:"archivo-black",name:"Archivo Black"},{slug:"passion-one",name:"Passion One"}
1,{slug:"righteous",name:"Righteous"},{slug:"staatliches",name:"Staatliches"},{slug:"fjalla-one",name:"Fjalla One"},{slug:"teko",name:"Teko"},{slug:"bangers",name:"Bangers"},{slug:"russo-one",name:"Russo One"},{slug:"acme",name:"Acme"},{slug:"patua-one",name:"Patua One"},{slug:"dela-gothic-one",name:"Dela Gothic One"},{slug:"lilita-one",name:"Lilita One"},{slug:"syne",name:"Syne"},{slug:"unbounded",name:"Unbounded"},{slug:"chewy",name:"Chewy"},{slug:"luckiest-guy",name:"Luckiest Guy"},{slug:"shrikhand",name:"Shrikhand"},{slug:"titan-one",name:"Titan One"},{slug:"dancing-script",name:"Dancing Script"},{slug:"pacifico",name:"Pacifico"},{slug:"caveat",name:"Caveat"},{slug:"lobster",name:"Lobster"},{slug:"great-vibes",name:"Great Vibes"},{slug:"satisfy",name:"Satisfy"},{slug:"yellowtail",name:"Yellowtail"},{slug:"permanent-marker",name:"Permanent Marker"},{slug:"kaushan-script",name:"Kaushan Script"},{slug:"indie-flower",name:"Indie Flower"},{slug:"shadows-into-light",name:"Shadows Into Light"},{slug:"londrina-solid",name:"Londrina Solid"},{slug:"plus-jakarta-sans",name:"Plus Jakarta Sans"},{slug:"league-spartan",name:"League Spartan"},{slug:"sora",name:"Sora"},{slug:"dm-sans",name:"DM Sans"},{slug:"space-grotesk",name:"Space Grotesk"},{slug:"manrope",name:"Manrope"},{slug:"outfit",name:"Outfit"},{slug:"figtree",name:"Figtree"},{slug:"lexend",name:"Lexend"},{slug:"work-sans",name:"Work Sans"},{slug:"nunito",name:"Nunito"},{slug:"quicksand",name:"Quicksand"},{slug:"comfortaa",name:"Comfortaa"},{slug:"fredoka-one",name:"Fredoka One"},{slug:"baloo-2",name:"Baloo 2"},{slug:"epilogue",name:"Epilogue"},{slug:"instrument-sans",name:"Instrument Sans"},{slug:"bricolage-grotesque",name:"Bricolage Grotesque"},{slug:"lora",name:"Lora"},{slug:"merriweather",name:"Merriweather"},{slug:"libre-baskerville",name:"Libre Baskerville"},{slug:"dm-serif-text",name:"DM Serif Text"},{slug:"prata",name:"Prata"},{slug:"abril-fatface",name:"Abril Fatface"},{slug:"fraunces",name:"Fraunces"},{slug:"cinzel",name:"Cinzel"},{slug:"yeseva-one",name:"Yeseva One"},{slug:"gloock",name:"Gloock"},{slug:"barlow-condensed",name:"Barlow Condensed"},{slug:"roboto-condensed",name:"Roboto Condensed"},{slug:"archivo-narrow",name:"Archivo Narrow"},{slug:"six-caps",name:"Six Caps"},{slug:"rubik",name:"Rubik"},{slug:"mulish",name:"Mulish"},{slug:"josefin-sans",name:"Josefin Sans"},{slug:"jost",name:"Jost"},{slug:"barlow",name:"Barlow"},{slug:"red-hat-display",name:"Red Hat Display"},{slug:"kanit",name:"Kanit"}],Ee=new Set;let gs=!1;function dt(){if(gs)return;const s=G.map(r=>r.name.replace(/ /g,"+")).join("&family="),a=document.createElement("link");a.href=`https://fonts.googleapis.com/css2?family=${s}&display=swap`,a.rel="stylesheet",document.head.appendChild(a),G.forEach(r=>Ee.add(r.name)),gs=!0}function ut(s){if(Ee.has(s))return;const a=document.createElement("link"),r=s.replace(/ /g,"+");a.href=`https://fonts.googleapis.com/css2?family=${r}:wght@400;700&display=swap`,a.rel="stylesheet",document.head.appendChild(a),Ee.add(s)}function xs({value:s,onValueChange:a,placeholder:r,className:o,triggerClassName:l}){const{t:i}=E(),[u,c]=m.useState(!1),[t,n]=m.useState(""),d=Me();m.useEffect(()=>{u&&dt()},[u]),m.useEffect(()=>{if(s){const h=G.find(I=>I.name===s||I.slug===s);h&&ut(h.name)}},[s]);const g=m.useMemo(()=>{if(!t)return G;const h=t.toLowerCase();return G.filter(I=>I.name.toLowerCase().includes(h)||I.slug.toLowerCase().includes(h))},[t]),p=G.find(h=>h.name===s||h.slug===s),x=h=>{a(h),c(!1),n("")},f=e.jsxs("div",{className:k("flex flex-col overflow-hidden",d?"h-full":"max-h-[400px]"),children:[e.jsxs("div",{className:"flex items-center border-b px-3 py-2 shrink-0",children:[e.jsx(Ge,{className:"mr-2 h-4 w-4 shrink-0 opacity-50"}),e.jsx(F,{placeholder:i("font_select.search_placeholder"),value:t,onChange:h=>n(h.target.value),className:"flex-1 h-8 border-0 bg-transparent p-0 placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-0 focus-visible:ring-offset-0"})]}),e.jsx(Ue,{className:k("flex-1 overflow-auto",d?"h-full":"max-h-[340px]"),children:e.jsx("div",{className:"p-1",children:g.length===0?e.jsx("p",{className:"py-6 text-center text-sm text-muted-foreground",children:i("font_select.no_fonts_found")}):g.map(h=>e.jsxs("button",{onClick:()=>x(h.name),className:k("relative flex w-full cursor-pointer select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors hover:bg-accent hover:text-accent-foreground",d&&"px-4 py-3 text-lg rounded-md",s===h.name&&"bg-accent text-accent-foreground"),style:{fontFamily:`"${h.name}", sans-serif`},children:[e.jsx("span",{className:"flex-1 text-left truncate",children:h.name}),s===h.name&&e.jsx(H,{className:k("ml-2 h-4 w-4",d&&"h-5 w-5")})]},h.slug))})})]}),N=e.jsxs(A,{variant:"outline",role:"combobox","aria-expanded":u,className:k("w-full justify-between font-normal",d&&"h-12 px-4 text-base",!s&&"text-muted-foreground",l),children:[e.jsx("span",{className:"truncate",style:{fontFamily:p?`"${p.name}", sans-serif`:void 0},children:(p==null?void 0:p.name)||r||i("font_select.placeholder")}),e.jsx(He,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]});
1return d?e.jsxs(De,{open:u,onOpenChange:c,children:[e.jsx(Fe,{asChild:!0,children:N}),e.jsxs(Re,{side:"bottom",className:"h-[85vh] p-0 flex flex-col rounded-t-xl",children:[e.jsx(ze,{className:"px-4 py-4 border-b",children:e.jsx(Be,{className:"text-center",children:i("font_select.choose_font")})}),e.jsx("div",{className:"flex-1 overflow-hidden",children:f})]})]}):e.jsxs(Pe,{open:u,onOpenChange:c,children:[e.jsx(Ie,{asChild:!0,children:N}),e.jsx(Oe,{className:k("w-[300px] p-0",o),align:"start",children:f})]})}const mt=({brandColors:s,setBrandColors:a,logoUrl:r,setLogoUrl:o,typography:l,setTypography:i,fileInputRef:u,isUploadingLogo:c})=>{const{t}=E();return e.jsxs("div",{className:"space-y-6",children:[e.jsxs(B,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-primary/10 flex items-center justify-center",children:e.jsx(ve,{className:"w-4 h-4 text-primary"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold",children:t("onboarding_steps.visual_identity.logo_title")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("onboarding_steps.visual_identity.logo_description")})]})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("div",{className:"relative group",children:[e.jsx("div",{className:"w-24 h-24 rounded-2xl border-2 border-dashed flex items-center justify-center bg-muted/50 overflow-hidden",children:r?e.jsx("img",{src:r,alt:"Logo",className:"w-full h-full object-cover"}):e.jsx(ve,{className:"w-8 h-8 text-muted-foreground/50"})}),r&&e.jsx("button",{type:"button",onClick:()=>o(null),className:"absolute -top-2 -right-2 bg-destructive text-white p-1.5 rounded-full shadow-lg z-10 hover:bg-destructive/90 transition-colors no-touch-target",children:e.jsx(_s,{className:"w-4 h-4"})})]}),e.jsxs("div",{className:"flex-1",children:[e.jsxs(A,{variant:"outline",size:"sm",className:"w-full",onClick:()=>{var n;return(n=u.current)==null?void 0:n.click()},disabled:c,children:[c?e.jsx(X,{className:"w-4 h-4 mr-2 animate-spin"}):e.jsx(ve,{className:"w-4 h-4 mr-2"}),t(r?"onboarding_steps.visual_identity.change_logo":"onboarding_steps.visual_identity.upload_logo")]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-2 text-center",children:t("onboarding_steps.visual_identity.file_hint")})]})]})]}),e.jsxs(B,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-primary/10 flex items-center justify-center",children:e.jsx(vs,{className:"w-4 h-4 text-primary"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold",children:t("onboarding_steps.visual_identity.colors_title")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("onboarding_steps.visual_identity.colors_description")})]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsx(Se,{label:t("onboarding_steps.visual_identity.primary"),id:"color-primary",value:s.primary,onChange:n=>a({...s,primary:n})}),e.jsx(Se,{label:t("onboarding_steps.visual_identity.secondary"),id:"color-secondary",value:s.secondary,onChange:n=>a({...s,secondary:n})}),e.jsx(Se,{label:t("onboarding_steps.visual_identity.accent"),id:"color-accent",value:s.accent,onChange:n=>a({...s,accent:n})})]}),e.jsx("div",{className:"mt-4 p-3 rounded-xl border",style:{background:`linear-gradient(135deg, ${s.primary}20, ${s.secondary}20)`},children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-3 h-3 rounded-full",style:{backgroundColor:s.primary}}),e.jsx("div",{className:"w-3 h-3 rounded-full",style:{backgroundColor:s.secondary}}),e.jsx("div",{className:"w-3 h-3 rounded-full",style:{backgroundColor:s.accent}}),e.jsx("span",{className:"text-xs text-muted-foreground ml-2",children:t("onboarding_steps.visual_identity.palette_preview")})]})})]}),e.jsxs(B,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-primary/10 flex items-center justify-center",children:e.jsx(ws,{className:"w-4 h-4 text-primary"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold",children:t("onboarding_steps.visual_identity.typography_title")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("onboarding_steps.visual_identity.typography_description")})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(P,{className:"text-xs",children:t("onboarding_steps.visual_identity.primary_font")}),e.jsx("p",{className:"text-[10px] text-muted-foreground -mt-1",children:t("onboarding_steps.visual_identity.primary_font_hint")}),e.jsx(xs,{value:l.primary_font,onValueChange:n=>i({...l,primary_font:n}),placeholder:"Selecione uma fonte...",triggerClassName:"h-11"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(P,{className:"text-xs",children:t("onboarding_steps.visual_identity.secondary_font")}),e.jsx("p",{className:"text-[10px] text-muted-foreground -mt-1",children:t("onboarding_steps.visual_identity.secondary_font_hint")}),e.jsx(xs,{value:l.secondary_font,onValueChange:n=>i({...l,secondary_font:n}),placeholder:"Selecione uma fonte...",triggerClassName:"h-11"})]})]})]})]})},Se=({label:s,id:a,value:r,onChange:o})=>{const[l,i]=m.useState(r),[u,c]=m.useState(!1);m.useEffect(()=>{u||i(r)},[r,u]);const t=n=>{n=n.trim(),n&&!n.startsWith("#")&&(n="#"+n),/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.test(n)?(n.length===4&&(n="#"+n[1]+n[1]+n[2]+n[2]+n[3]+n[3]),o(n.toLowerCase()),i(n.toLowerCase())):(!n||n==="#")&&i(r)};return e.jsxs("div",{className:"space-y-2",children:[e.jsx(P,{className:"text-xs text-muted-foreground",children:s}),e.jsxs("label",{htmlFor:a,className:"relative block cursor-pointer",children:[e.jsx("div",{className:"w-full h-14 roun
1ded-xl border-2 shadow-inner transition-transform hover:scale-105 pointer-events-none",style:{backgroundColor:r}}),e.jsx("input",{id:a,type:"color",value:r,onChange:n=>{o(n.target.value),i(n.target.value)},className:"absolute inset-0 w-full h-full opacity-0 cursor-pointer",style:{WebkitAppearance:"none",minHeight:"56px"}})]}),e.jsx("input",{type:"text",value:l,onChange:n=>i(n.target.value),onFocus:()=>c(!0),onBlur:()=>{c(!1),t(l)},onKeyDown:n=>{n.key==="Enter"&&(t(l),n.target.blur())},placeholder:"#000000",maxLength:7,className:"w-full text-xs text-center font-mono text-muted-foreground bg-transparent border border-border rounded-md px-2 py-1 focus:outline-none focus:ring-1 focus:ring-primary"})]})},pt=({value:s,onChange:a})=>{const{t:r}=E(),{categories:o}=et(),[l,i]=m.useState(!1),[u,c]=m.useState(""),t=Me(),n=m.useMemo(()=>{if(!u.trim())return o;const f=u.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g,"");return o.filter(N=>N.label.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g,"").includes(f)||N.value.includes(f))},[o,u]),d=o.find(f=>f.value===s),g=f=>{a(f),i(!1),c("")},p=e.jsxs("div",{className:k("flex flex-col overflow-hidden",t?"h-full":"max-h-[400px]"),children:[e.jsxs("div",{className:"flex items-center border-b px-3 py-2 shrink-0",children:[e.jsx(Ge,{className:"mr-2 h-4 w-4 shrink-0 opacity-50"}),e.jsx(F,{placeholder:r("onboarding_steps.business.search_category"),value:u,onChange:f=>c(f.target.value),className:"flex-1 h-8 border-0 bg-transparent p-0 placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-0 focus-visible:ring-offset-0"})]}),e.jsx(Ue,{className:k("flex-1 overflow-auto",t?"h-full":"max-h-[340px]"),children:e.jsx("div",{className:"p-1",children:n.length===0?e.jsx("div",{className:"py-6 text-center text-sm text-muted-foreground",children:r("onboarding_steps.business.no_category_found")}):n.map(f=>e.jsxs("button",{onClick:()=>g(f.value),className:k("relative flex w-full cursor-pointer select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors hover:bg-accent hover:text-accent-foreground",t&&"px-4 py-3 text-lg rounded-md",s===f.value&&"bg-accent text-accent-foreground"),children:[e.jsxs("span",{className:"flex items-center gap-2 flex-1 text-left truncate",children:[e.jsx("span",{className:"text-lg",children:f.icon}),f.label]}),s===f.value&&e.jsx(H,{className:k("ml-2 h-4 w-4",t&&"h-5 w-5")})]},f.value))})})]}),x=e.jsxs(A,{variant:"outline",role:"combobox","aria-expanded":l,className:"w-full h-11 justify-between font-normal",children:[d?e.jsxs("span",{className:"truncate flex items-center gap-2",children:[e.jsx("span",{children:d.icon})," ",d.label]}):e.jsx("span",{className:"text-muted-foreground",children:r("onboarding_steps.business.category_placeholder")}),e.jsx(He,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]});return t?e.jsxs(De,{open:l,onOpenChange:i,children:[e.jsx(Fe,{asChild:!0,children:x}),e.jsxs(Re,{side:"bottom",className:"h-[80vh] rounded-t-[20px] px-0",children:[e.jsx(ze,{className:"px-4 pb-2 text-left",children:e.jsx(Be,{children:r("onboarding_steps.business.select_category")})}),p]})]}):e.jsxs(Pe,{open:l,onOpenChange:i,children:[e.jsx(Ie,{asChild:!0,children:x}),e.jsx(Oe,{className:"w-[--radix-popover-trigger-width] p-0",align:"start",children:p})]})},gt=({value:s,onChange:a})=>{const{t:r}=E(),[o,l]=m.useState(!1),[i,u]=m.useState(""),c=Me(),t=m.useMemo(()=>{if(!i.trim())return we;const x=i.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g,"");return we.filter(f=>f.label.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g,"").includes(x)||f.code.includes(x))},[i]),n=we.find(x=>x.code===s),d=x=>{a(x),l(!1),u("")},g=e.jsxs("div",{className:k("flex flex-col overflow-hidden",c?"h-full":"max-h-[400px]"),children:[e.jsxs("div",{className:"flex items-center border-b px-3 py-2 shrink-0",children:[e.jsx(Ge,{className:"mr-2 h-4 w-4 shrink-0 opacity-50"}),e.jsx(F,{placeholder:r("onboarding_steps.business.search_language"),value:i,onChange:x=>u(x.target.value),className:"flex-1 h-8 border-0 bg-transparent p-0 placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-0 focus-visible:ring-offset-0"})]}),e.jsx(Ue,{className:k("flex-1 overflow-auto",c?"h-full":"max-h-[340px]"),children:e.jsx("div",{className:"p-1",children:t.length===0?e.jsx("div",{className:"py-6 text-center text-sm text-muted-foreground",children:r("onboarding_steps.business.no_language_found")}):t.map(x=>e.jsxs("button",{onClick:()=>d(x.code),className:k("relative flex w-full cursor-pointer select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors hover:bg-accent hover:text-accent-foreground",c&&"px-4 py-3 text-lg rounded-md",s===x.code&&"bg-accent text-accent-foreground"),children:[e.jsxs("span",{className:"flex items-center gap-2 flex-1 text-left truncate",children:[e.jsx("span",{className:"text-lg",children:x.flag}),x.label]}),s===x.code&&e.jsx(H,{className:k("ml-2 h-4 w-4",c&&"h-5 w-5")})]},x.code))})})]}),p=e.jsxs(A,{variant:"outline",role:"combobox","aria-expanded":o,className:"w-full h-11 justify-between font-normal",children:[n?e.jsxs("span",{className:"truncate flex items-center gap-2",children:[e.jsx("span",{children:n.flag})," ",n.label]}):e.jsx("span",{className:"text-muted-foreground",children:r("onboarding_steps.business.language_placeholder")}),e.jsx(He,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]});return c?e.jsxs(De,{open:o,onOpenChange:l,children:[e.jsx(Fe,{asChild:!0,children:p}),e.jsxs(Re,{side:"bottom",className:"h-[80vh] rounded-t-[20px] px-0",children:[e.jsx(ze,{className:"px-4 pb-2 text-left",children:e.jsx(Be,{children:r("onboarding_steps.business.select_language")})}),g]})]}):e.jsxs(Pe,{open:o,onOpenChange:l,children:[e.jsx(Ie,{asChild:!0,children:p}),e.jsx(Oe,{className:"w-[--radix-popover-trigger-width] p-0",align:"start",children:g})]})},xt=({businessCategorySlug:s,setBusinessCategorySlug:a,businessDescription:r,setBusinessDescription:o,language:l,setLanguage:i,siteReadHost:u,businessContext:c=null})=>{const{t}=E(),n=st(s,c);return e.jsx("div",{className:"space-y-6",children:e.jsxs(B,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-primary/10 flex items-center justify-center",children:e.jsx(Ys,{className:"w-4 h-4 text-primary"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold",children:t("onboarding_steps.business.title")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("onboarding_steps.business.description")})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(P,{children:t("onboarding_steps.business.category_label")}),e.jsx(pt,{value:s,onChange:a}),n&&e.jsx("p",{className:"text-xs text-muted-foreground",children:t("onboarding_steps.business.niche_rules_n
1ote",{source:n.source})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(P,{children:t("onboarding_steps.business.description_label")}),e.jsx(te,{placeholder:t("onboarding_steps.business.description_placeholder"),value:r,onChange:d=>o(d.target.value),className:"min-h-[200px] resize-none"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:u?t("onboarding_steps.business.description_from_site",{site:u}):t("onboarding_steps.business.description_hint")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(P,{className:"flex items-center gap-2",children:[e.jsx(Ss,{className:"w-4 h-4"}),t("onboarding_steps.business.language_label")]}),e.jsx("p",{className:"text-xs text-muted-foreground -mt-1",children:t("onboarding_steps.business.language_hint")}),e.jsx(gt,{value:l,onChange:i})]})]})]})})},Ts={offer:"",audience:"",cta:"",tone:"",proof:""},Ae=6,Te=200,$e=s=>s&&typeof s=="object"&&!Array.isArray(s)?s:null,D=s=>typeof s=="string"?s.trim():"";function Ls(s){const a=$e(s);if(!a)return Ts;const r=Array.isArray(a.proof)?a.proof.filter(o=>D(o)):[];return{offer:D(a.offer),audience:D(a.audience),cta:D(a.cta),tone:D(a.tone),proof:r.map(o=>D(o)).join(` 2`)}}function ft(s,a,r){const o=$e(s),l=a.proof.split(` 3`).map(d=>d.trim()).filter(Boolean),i={offer:a.offer.trim(),audience:a.audience.trim(),cta:a.cta.trim(),tone:a.tone.trim(),proof:l.join(` 4`)},u=Ls(o);if(!Object.keys(i).some(d=>u[d]!==i[d]))return;const t={...o??{}};for(const d of["offer","audience","cta","tone"])i[d]?t[d]=i[d]:delete t[d];if(i.proof===u.proof){const d=Array.isArray(o==null?void 0:o.proof)?o.proof.filter(g=>typeof g=="string"&&g.trim()):[];d.length?t.proof=d:delete t.proof}else{const d=l.slice(0,Ae).map(g=>g.slice(0,Te));d.length?t.proof=d:delete t.proof}return!!(t.offer||t.audience||t.cta||t.tone||t.proof)?(t.ok=!0,delete t.mismatch,delete t.retryable,delete t.skipped,t.edited_at=r):delete t.edited_at,t}const fs=s=>{if(!(typeof s!="string"||!s.trim()))try{return new URL(s).hostname.replace(/^www\./,"")}catch{return}};function ht(s){const a=$e(s);if(!a)return{kind:"none"};const r={host:fs(a.read_url),hubHost:fs(a.hub_url),url:D(a.url)||void 0,readUrl:/^https?:\/\//i.test(D(a.read_url))?D(a.read_url):void 0,readAt:D(a.read_at)||void 0,editedAt:D(a.edited_at)||void 0};return r.editedAt?{...r,kind:"edited"}:a.skipped?{...r,kind:"skipped",skipped:a.skipped}:a.retryable?{...r,kind:"retry"}:a.ok!==!0?{...r,kind:"failed"}:a.mismatch?{...r,kind:"mismatch"}:[a.offer,a.audience,a.cta,a.tone].some(l=>D(l))||Array.isArray(a.proof)&&a.proof.some(l=>
4D(l))?{...r,kind:"read"}:{...r,kind:"empty"}}const bt=({siteContext:s,fields:a,onChange:r})=>{const{t:o,i18n:l}=E(),i=ht(s),u=c=>t=>r({...a,[c]:t});return e.jsxs(B,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-primary/10 flex items-center justify-center",children:e.jsx(Ss,{className:"w-4 h-4 text-primary"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold",children:o("profile_settings.site_context.title")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:o("profile_settings.site_context.description")})]})]}),e.jsx(_t,{origin:i,language:l.language}),e.jsxs("div",{className:"space-y-4 mt-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(P,{htmlFor:"site-context-offer",children:o("profile_settings.site_context.offer_label")}),e.jsx(F,{id:"site-context-offer",value:a.offer,onChange:c=>u("offer")(c.target.value),placeholder:o("profile_settings.site_context.offer_placeholder"),maxLength:300})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(P,{htmlFor:"site-context-audience",children:o("profile_settings.site_context.audience_label")}),e.jsx(F,{id:"site-context-audience",value:a.audience,onChange:c=>u("audience")(c.target.value),placeholder:o("profile_settings.site_context.audience_placeholder"),maxLength:300})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(P,{htmlFor:"site-context-cta",children:o("profile_settings.site_context.cta_label")}),e.jsx(F,{id:"site-context-cta",value:a.cta,onChange:c=>u("cta")(c.target.value),placeholder:o("profile_settings.site_context.cta_placeholder"),maxLength:200})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(P,{htmlFor:"site-context-tone",children:o("profile_settings.site_context.tone_label")}),e.jsx(F,{id:"site-context-tone",value:a.tone,onChange:c=>u("tone")(c.target.value),placeholder:o("profile_settings.site_context.tone_placeholder"),maxLength:200})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(P,{htmlFor:"site-context-proof",children:o("profile_settings.site_context.proof_label")}),e.jsx(te,{id:"site-context-proof",value:a.proof,onChange:c=>u("proof")(c.target.value),placeholder:o("profile_settings.site_context.proof_placeholder"),className:"min-h-[96px]",maxLength:Ae*(Te+1),"aria-describedby":"site-context-proof-hint"}),e.jsx("p",{id:"site-context-proof-hint",className:"text-xs text-muted-foreground",children:o("profile_settings.site_context.proof_hint",{max:Ae,maxLength:Te})})]})]})]})},_t=({origin:s,language:a})=>{const{t:r}=E(),o=t=>{if(!t)return null;const n=new Date(t);return Number.isNaN(n.getTime())?null:n.toLocaleDateString(a)},l=s.host??s.url??"",i=o(s.readAt),u=o(s.editedAt),c=(()=>{switch(s.kind){case"edited":return"origin_edited";case"read":return s.hubHost?"origin_read_hub":"origin_read";case"empty":return"origin_empty";case"mismatch":return"origin_mismatch";case"failed":return"origin_failed";case"retry":return"origin_retry";case"skipped":return s.skipped==="no-link"?"origin_no_link":"origin_unreadable_host";default:return"origin_none"}})();return e.jsxs("div",{className:"rounded-md bg-muted/60 px-3 py-2 text-xs text-muted-foreground space-y-1",children:[e.jsx("p",{children:r(`profile_settings.site_context.${c}`,{site:l,hub:s.hubHost??"",date:u??i??""})}),s.kind==="edited"&&s.host&&i&&e.jsx("p",{children:r("profile_settings.site_context.origin_edited_source",{site:s.host,date:i})}),s.readUrl&&e.jsx("a",{href:s.readUrl,target:"_blank",rel:"noopener noreferrer",className:"inline-block underline underline-offset-2 hover:text-foreground",children:r("profile_settings.site_context.open_read_page")})]})},jt=({targetAudiences:s,onAddAudience:a,onEditAudience:r,onDeleteAudience:o})=>{const{t:l}=E(),[i,u]=m.useState(null),[c,t]=m.useState(!1),[n,d]=m.useState(null),[g,p]=m.useState({name:"",age_range:"",interests:"",pain_points:""}),x=C=>{u(i===C?null:C)},f=()=>{p({name:"",age_range:"",interests:"",pain_points:""}),d(null),t(!0)},N=C=>{const S=s[C];p({name:S.name,age_range:S.age_range,interests:S.interests.join(", "),pain_points:S.pain_points.join(", ")}),d(C),t(!0)},h=()=>{const C={name:g.name,age_range:g.age_range,interests:g.interests.split(",").map(S=>S.trim()).filter(S=>S),pain_points:g.pain_points.split(",").map(S=>S.trim()).filter(S=>S)};n!==null?r(n,C):a(C),t(!1),d(null)},I=()=>{t(!1),d(null)},v=C=>{o(C),u(null)};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs(B,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-primary/10 flex items-center justify-center",children:e.jsx(ne,{className:"w-4 h-4 text-primary"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold",children:l("onboarding_steps.audience.title")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:l("onboarding_steps.audience.description")})]})]}),!c&&e.jsxs(A,{size:"sm",variant:"outline",onClick:f,children:[e.jsx(Cs,{className:"w-4 h-4 mr-1"}),l("common.add")]})]}),c?e.jsx(yt,{form:g,setForm:p,onSave:h,onCancel:I}):s.length===0?e.jsx(Nt,{}):e.jsx(vt,{audiences:s,expandedIndex:i,onToggleExpand:x,onEdit:N,onDelete:v})]}),s.length>0&&!c&&e.jsx("p",{className:"text-xs text-center text-muted-foreground px-4",children:l("onboarding_steps.audience.tap_hint")})]})},yt=({form:s,setForm:a,onSave:r,onCancel:o})=>{const{t:l}=E();return e.jsxs(ae.div,{initial:{opacity:0,y:10}
4,animate:{opacity:1,y:0},className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(P,{children:l("onboarding_steps.audience.persona_name")}),e.jsx(F,{placeholder:l("onboarding_steps.audience.persona_name_placeholder"),value:s.name,onChange:i=>a({...s,name:i.target.value}),className:"h-11"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(P,{children:l("onboarding_steps.audience.age_range")}),e.jsx(F,{placeholder:l("onboarding_steps.audience.age_range_placeholder"),value:s.age_range,onChange:i=>a({...s,age_range:i.target.value}),className:"h-11"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(P,{children:[l("onboarding_steps.audience.interests")," ",e.jsx("span",{className:"text-muted-foreground font-normal",children:l("onboarding_steps.audience.comma_separated")})]}),e.jsx(te,{placeholder:l("onboarding_steps.audience.interests_placeholder"),value:s.interests,onChange:i=>a({...s,interests:i.target.value}),className:"min-h-[80px] resize-none"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(P,{children:[l("onboarding_steps.audience.pain_points")," ",e.jsx("span",{className:"text-muted-foreground font-normal",children:l("onboarding_steps.audience.comma_separated")})]}),e.jsx(te,{placeholder:l("onboarding_steps.audience.pain_points_placeholder"),value:s.pain_points,onChange:i=>a({...s,pain_points:i.target.value}),className:"min-h-[80px] resize-none"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(A,{variant:"outline",className:"flex-1",onClick:o,children:l("common.cancel")}),e.jsxs(A,{className:"flex-1",onClick:r,disabled:!s.name,children:[e.jsx(H,{className:"w-4 h-4 mr-1"}),l("common.save")]})]})]})},Nt=()=>{const{t:s}=E();return e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(ne,{className:"w-12 h-12 mx-auto mb-3 opacity-20"}),e.jsx("p",{className:"text-sm",children:s("onboarding_steps.audience.empty")}),e.jsx("p",{className:"text-xs mt-1",children:s("onboarding_steps.audience.empty_hint")})]})},vt=({audiences:s,expandedIndex:a,onToggleExpand:r,onEdit:o,onDelete:l})=>{const{t:i}=E();return e.jsx("div",{className:"space-y-3",children:s.map((u,c)=>e.jsxs(ae.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:c*.1},className:"rounded-xl border bg-card overflow-hidden",children:[e.jsxs("button",{onClick:()=>r(c),className:"w-full p-3 flex items-center justify-between text-left hover:bg-muted/50 transition-colors",children:[e.jsx("div",{className:"flex items-center gap-3",children:e.jsxs("div",{children:[e.jsx("h4",{className:"font-medium",children:u.name}),u.age_range&&e.jsx("p",{className:"text-xs text-muted-foreground",children:u.age_range})]})}),e.jsx(ks,{className:k("w-5 h-5 text-muted-foreground transition-transform",a===c&&"rotate-90")})]}),e.jsx(Es,{children:a===c&&e.jsx(ae.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.2},className:"overflow-hidden",children:e.jsxs("div",{className:"px-3 pb-3 pt-1 space-y-3 border-t bg-muted/30",children:[u.interests.length>0&&e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground mb-2",children:i("onboarding_steps.audience.interests")}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:u.interests.map((t,n)=>e.jsx(ke,{variant:"secondary",className:"text-xs",children:t},n))})]}),u.pain_points.length>0&&e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground mb-2",children:i("onboarding_steps.audience.pain_points")}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:u.pain_points.map((t,n)=>e.jsx(ke,{variant:"outline",className:"text-xs",children:t},n))})]}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsxs(A,{variant:"outline",size:"sm",className:"flex-1",onClick:t=>{t.stopPropagation(),o(c)},children:[e.jsx(tt,{className:"w-3 h-3 mr-1"}),i("common.edit")]}),e.jsx(A,{variant:"outline",size:"sm",className:"text-destructive hover:text-destructive",onClick:t=>{t.stopPropagation(),l(c)},children:e.jsx(at,{className:"w-3 h-3"})})]})]})})})]},c))})},wt=({items:s,onChange:a})=>{const{t:r}=E(),[o,l]=m.useState(""),i=m.useRef(null),u=(n,d)=>{a(s.map((g,p)=>p===n?{text:d,source:"user",updated_at:new Date().toISOString()}:g))},c=n=>{a(s.filter((d,g)=>g!==n))},t=()=>{const n=o.trim();n&&(a([{text:n,source:"user",updated_at:new Date().toISOString()},...s]),l(""))};return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(F,{placeholder:r("profile_preferences.add_placeholder"),value:o,onChange:n=>l(n.target.value),onKeyDown:n=>{n.key==="Enter"&&(n.preventDefault(),t())},onBlur:n=>{n.relatedTarget!==i.current&&t()},maxLength:200}),e.jsxs(A,{ref:i,type:"button",variant:"outline",onClick:t,disabled:!o.trim(),children:[e.jsx(Cs,{className:"w-4 h-4 mr-1"}),r("common.add")]})]}),s.length===0?e.jsx("p",{className:"text-xs sm:text-sm text-muted-foreground text-center py-2",children:r("profile_preferences.empty")}):e.jsx("div",{className:"space-y-2 max-h-64 overflow-y-auto",children:s.map((n,d)=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(F,{value:n.text,onChange:g=>u(d,g.target.value),maxLength:200,className:"text-xs sm:text-sm"}),n.source==="ai"&&e.jsx(ke,{variant:"secondary",className:"text-xs flex-shrink-0",children:r("profile_preferences.ai_badge")}),e.jsx(A,{type:"button",variant:"ghost",size:"sm",onClick:()=>c(d),className:"text-red-500 hover:text-red-700 flex-shrink-0 h-8 w-8 p-0",title:r("profile_preferences.remove"),"aria-label":r("profile_preferences.remove"),children:e.jsx(_s,{className:"w-4 h-4"})})]},d))})]})},hs=({aiPreferences:s,setAiPreferences:a})=>{const{t:r}=E();return e.jsx("div",{className:"space-y-6",children:e.jsxs(B,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-primary/10 flex items-center justify-center",children:e.jsx(re,{className:"w-4 h-4 text-primary"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold",children:r("profile_preferences.title")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r("profile_preferences.help")})]})]}),e.jsx(wt,{items:s,onChange:a})]})})}
4,St=["visual","business","audience"],Ct=["visual","business","audience","preferences"],J={primary:"#000000",secondary:"#ffffff",accent:"#000000",palette:[]},K={primary_font:"Inter",secondary_font:"Inter",style:"modern",auto_detected:!0},bs=s=>({brand_colors:{...s.brandColors,palette:[s.brandColors.primary,s.brandColors.secondary,s.brandColors.accent]},logo_url:s.logoUrl,typography:s.typography,business_category_slug:s.businessCategorySlug,business_description:s.businessDescription,target_audience:s.targetAudiences,language:s.language,ai_preferences:s.aiPreferences.filter(a=>a.text.trim()),...s.siteContextFields?{site_context_fields:s.siteContextFields}:{}}),se=s=>JSON.stringify(s),kt=s=>{var r;const a=s;if(!(a!=null&&a.ok)||!a.read_url||!((r=a.offer)!=null&&r.trim())||typeof a.edited_at=="string")return null;try{return new URL(a.read_url).hostname.replace(/^www\./,"")}catch{return null}},Et=({profile:s,onComplete:a,showBackButton:r=!1,mode:o="onboarding",onBack:l,onReanalyze:i,onSyncProfile:u,syncingProfile:c=!1})=>{const{t}=E(),n=Le(),{toast:d}=js(),{updateProfileInCache:g}=ys(),p=o==="settings",x=p?Ct:St,f=x.length,N=t(p?"profile_settings.section_titles":"onboarding_steps.step_titles",{returnObjects:!0}),h=t(p?"profile_settings.section_descriptions":"onboarding_steps.step_descriptions",{returnObjects:!0}),I=p?t("profile_settings.section_tabs",{returnObjects:!0}):N,[v,C]=m.useState(0),[S,U]=m.useState(0),[y,b]=m.useState(!1),w=x[v],[L,$]=m.useState(null),[Ps,oe]=m.useState(!1),[Is,le]=m.useState(!1),[Os,ie]=m.useState(!1),Ye=m.useRef(null),[Ve,We]=m.useState(!1),[qe,Je]=m.useState(J),[Ke,ce]=m.useState(null),[Xe,Ze]=m.useState(K),[Qe,es]=m.useState(null),[ss,ts]=m.useState(""),[as,ns]=m.useState(ps),[de,ue]=m.useState([]),[rs,Z]=m.useState([]),[os,ls]=m.useState(Ts);m.useEffect(()=>{if(!s)return;let j=J;if(s.brand_colors&&typeof s.brand_colors=="object"){const T=s.brand_colors;j={primary:T.primary||J.primary,secondary:T.secondary||J.secondary,accent:T.accent||J.accent,palette:Array.isArray(T.palette)?T.palette:[]}}Je(j);const _=s.logo_url||null;ce(_);let R=K;if(s.typography&&typeof s.typography=="object"){const T=s.typography;R={primary_font:T.primary_font||K.primary_font,secondary_font:T.secondary_font||K.secondary_font,style:T.style||K.style,auto_detected:T.auto_detected!==!1}}Ze(R);const O=s.business_category_slug||null,V=s.business_description||"",Q=s.language||ps,W=Array.isArray(s.ai_preferences)?s.ai_preferences.filter(T=>typeof(T==null?void 0:T.text)=="string"):[];es(O),ts(V),ns(Q),ue(W);let M=[];Array.isArray(s.target_audience)?M=s.target_audience:typeof s.target_audience=="string"&&(M=[{name:s.target_audience,age_range:"",interests:[],pain_points:[]}]),Z(M);const z=Ls(s.site_context);ls(z),$(se(bs({brandColors:j,logoUrl:_,typography:R,businessCategorySlug:O,businessDescription:V,targetAudiences:M,language:Q,aiPreferences:W,siteContextFields:p?z:void 0})))},[s,p]);const me=bs({brandColors:qe,logoUrl:Ke,typography:Xe,businessCategorySlug:Qe,businessDescription:ss,targetAudiences:rs,language:as,aiPreferences:de,siteContextFields:p?os:void 0}),Y=L!==null&&se(me)!==L;m.useEffect(()=>{if(!p||!Y)return;const j=_=>{_.preventDefault(),_.returnValue=""};return window.addEventListener("beforeunload",j),()=>window.removeEventListener("beforeunload",j)},[p,Y]);const Ds=async j=>{var R;const _=(R=j.target.files)==null?void 0:R[0];if(!(!_||!s)){if(!Ks(_)){d({title:t("common.error"),description:t("onboarding_steps.toasts.invalid_image"),variant:"destructive"});return}if(_.size>5*1024*1024){d({title:t("common.error"),description:t("onboarding_steps.toasts.file_too_large"),variant:"destructive"});return}We(!0);try{const O=await Js(_,{maxWidth:800,maxHeight:800,quality:.9,maxSizeMB:2}),V=O.file;O.wasCompressed&&console.log(`ð¦ Logo otimizado: ${ds(O.originalSize)} â ${ds(O.compressedSize)}`);const Q=V.name.split(".").pop()||"jpg",W=`profile-pics/${s.user_id}/logo-${Date.now()}.${Q}`,{error:M}=await ge.storage.from("instagram-profile-pics").upload(W,V);if(M)throw M;const{data:{publicUrl:z}}=ge.storage.from("instagram-profile-pics").getPublicUrl(W),{error:T}=await ge.from("instagram_profiles").update({logo_url:z,logo_no_bg_url:null,logo_analysis:null}).eq("id",s.id);if(T)throw T;ce(z),g({...s,logo_url:z,logo_no_bg_url:null,logo_analysis:null}),$(pe=>pe&&se({...JSON.parse(pe),logo_url:z}
4)),Ns.processLogoInBackground(s.id,z),d({title:t("onboarding_steps.toasts.logo_updated"),description:t("onboarding_steps.toasts.logo_updated_desc")})}catch(O){console.error("Error uploading logo:",O),d({title:t("onboarding_steps.toasts.upload_error"),description:t("onboarding_steps.toasts.upload_error_desc"),variant:"destructive"})}finally{We(!1)}}},Fs=j=>{Z(_=>[..._,j])},Rs=(j,_)=>{Z(R=>{const O=[...R];return O[j]=_,O})},zs=j=>{Z(_=>_.filter((R,O)=>O!==j))},is=j=>{U(j>v?1:-1),C(j)},Bs=()=>{v<f-1?(U(1),C(j=>j+1)):cs()},Us=()=>{v>0&&(U(-1),C(j=>j-1))},cs=async()=>{b(!0);try{await a(me),$(se(me))}catch{}finally{b(!1)}},Ms=()=>{if(p&&Y){oe(!0);return}l?l():n(-1)},Gs=()=>{oe(!1),l?l():n(-1)},Hs={enter:j=>({x:j>0?300:-300,opacity:0}),center:{x:0,opacity:1},exit:j=>({x:j<0?300:-300,opacity:0})};return e.jsxs("div",{className:"min-h-screen bg-gradient-to-b from-background to-muted/30 flex flex-col",children:[e.jsxs("div",{className:"sticky top-0 z-10 bg-background/80 backdrop-blur-lg border-b px-4 py-4 safe-area-inset-top",children:[e.jsxs("div",{className:"flex items-center justify-between max-w-lg mx-auto",children:[p||r?e.jsxs(A,{variant:"ghost",size:"sm",onClick:Ms,className:"flex items-center gap-1","aria-label":t("common.back"),children:[e.jsx(nt,{className:"w-4 h-4"}),e.jsx("span",{className:"hidden sm:inline",children:t("common.back")})]}):e.jsx("div",{className:"w-16"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(re,{className:"w-5 h-5 text-primary"}),e.jsx("span",{className:"font-semibold text-sm",children:t(p?"profile_settings.title":"onboarding_steps.configure_profile")})]}),p&&i?e.jsxs(A,{variant:"ghost",size:"sm",onClick:()=>le(!0),disabled:c,className:"flex items-center gap-1",title:t("profile_settings.reanalyze"),children:[e.jsx(X,{className:"w-4 h-4"}),e.jsx("span",{className:"sr-only sm:not-sr-only sm:inline text-xs",children:t("profile_settings.reanalyze")})]}):e.jsx("div",{className:"w-16"})]}),p?e.jsx("nav",{"aria-label":t("profile_settings.title"),className:"flex gap-1 mt-4 max-w-lg mx-auto p-1 bg-muted/60 rounded-lg overflow-x-auto",children:x.map((j,_)=>e.jsx("button",{type:"button","aria-current":v===_?"step":void 0,onClick:()=>is(_),className:k("flex-1 whitespace-nowrap rounded-md px-2 sm:px-3 py-2 text-xs sm:text-sm font-medium transition-all",v===_?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:I[_]},j))}):e.jsx("div",{className:"flex items-center justify-center gap-2 mt-4 max-w-lg mx-auto",children:Array.from({length:f}).map((j,_)=>e.jsxs("button",{onClick:()=>is(_),className:"flex items-center gap-2 group",children:[e.jsx("div",{className:k("w-8 h-8 rounded-full flex items-center justify-center text-sm font-medium transition-all",v===_?"bg-primary text-primary-foreground scale-110 shadow-lg":v>_?"bg-primary/20 text-primary":"bg-muted text-muted-foreground"),children:v>_?e.jsx(H,{className:"w-4 h-4"}):_+1}),_<f-1&&e.jsx("div",{className:k("w-8 h-0.5 transition-all",v>_?"bg-primary":"bg-muted")})]},_))})]}),e.jsxs("div",{className:"px-4 pt-6 pb-2 text-center",children:[e.jsx("h1",{className:"text-2xl font-bold",children:N[v]}),e.jsx("p",{className:"text-muted-foreground text-sm mt-1",children:h[v]})]}),e.jsx("div",{className:"flex-1 overflow-hidden px-4",children:e.jsxs("fieldset",{disabled:c,"aria-busy":c,className:"max-w-lg mx-auto min-w-0 border-0 p-0 m-0 disabled:opacity-60",children:[p&&u&&w==="visual"&&e.jsx("div",{className:"pt-4",children:e.jsx(ct,{profile:s,syncing:c||Ve,onSync:()=>Y?ie(!0):u()})}),e.jsx(Es,{mode:"wait",custom:S,children:e.jsxs(ae.div,{custom:S,variants:Hs,initial:"enter",animate:"center",exit:"exit",transition:{duration:.3,ease:"easeInOut"},className:"py-4",children:[w==="visual"&&e.jsx(mt,{brandColors:qe,setBrandColors:Je,logoUrl:Ke,setLogoUrl:ce,typography:Xe,setTypography:Ze,fileInputRef:Ye,isUploadingLogo:Ve}),w==="business"&&e.jsxs("div",{className:"space-y-6",children:[e.jsx(xt,{businessCategorySlug:Qe,setBusinessCategorySlug:es,businessDescription:ss,setBusinessDescription:ts,language:as,setLanguage:ns,siteReadHost:kt(s.site_context),businessContext:p?s.business_context:null}),p&&e.jsx(bt,{siteContext:s.site_context,fields:os,onChange:ls}),!p&&e.jsx(hs,{aiPreferences:de,setAiPreferences:ue})]}),w==="audience"&&e.jsx(jt,{targetAudiences:rs,onAddAudience:Fs,onEditAudience:Rs,onDeleteAudience:zs}),w==="preferences"&&e.jsx(hs,{aiPreferences:de,setAiPreferences:ue})]},v)})]})}),e.jsx("div",{className:"sticky bottom-0 bg-background/80 backdrop-blur-lg border-t px-4 py-4 safe-area-inset-bottom",children:p?e.jsx("div",{className:"max-w-lg mx-auto",children:e.jsx(A,{onClick:cs,className:"w-full",disabled:!Y||y||c,children:y?e.jsx(X,{className:"w-4 h-4 animate-spin"}):e.jsxs(e.Fragment,{children:[e.jsx(rt,{className:"w-4 h-4 mr-2"}),t("profile_settings.save_changes")]})})}):e.jsxs("div",{className:"flex gap-3 max-w-lg mx-auto",children:[v>0&&e.jsxs(A,{variant:"outline",onClick:Us,className:"flex-1",children:[e.jsx(ot,{className:"w-4 h-4 mr-1"}),t("common.back")]},"onboarding-back"),e.jsx(A,{onClick:Bs,className:k("flex-1",v===0&&"w-full"),disabled:y,children:y?e.jsx(X,{className:"w-4 h-4 animate-spin"}):v===f-1?e.jsxs(e.Fragment,{children:[t("common.complete"),e.jsx(H,{className:"w-4 h-4 ml-1"})]}):e.jsxs(e.Fragment,{children:[t("common.next"),e.jsx(ks,{className:"w-4 h-4 ml-1"})]})},"onboarding-next")]})}),e.jsx("input",{type:"file",ref:Ye,className:"hidden",accept:"image/*,.heic,.heif,.avif,.bmp,.tiff,.tif,.jfif",onChange:Ds}),e.jsx(xe,{open:Ps,onOpenChange:oe,children:e.jsxs(fe,{children:[e.jsxs(he,{children:[e.jsx(be,{children:t("profile_settings.unsaved_title")}),e.jsx(_e,{children:t("profile_settings.unsaved_description")})]}),e.jsxs(je,{children:[e.jsx(ye,{children:t("profile_settings.unsaved_keep")}),e.jsx(Ne,{onClick:Gs,children:t("profile_settings.unsaved_discard")})]})]})}),e.jsx(xe,{open:Os,onOpenChange:ie,children:e.jsxs(fe,{children:[e.jsxs(he,{children:[e.jsx(be,{children:t("profile_settings.instagram_sync.confirm_title")}),e.jsx(_e,{children:t("profile_settings.instagram_sync.confirm_description")})]}),e.jsxs(je,{children:[e.jsx(ye,{children:t("profile_settings.unsaved_keep")}),e.jsx(Ne,{onClick:()=>{ie(!1),u==null||u()},children:t("profile_settings.instagram_sync.confirm_action")})]})]})}),e.jsx(xe,{open:Is,onOpenChange:le,children:e.jsxs(fe,{children:[e.jsxs(he,{children:[e.jsx(be,{children:t("profile_settings.reanalyze_confirm_title")}),e.jsx(_e,{children:t("profile_settings.reanalyze_confirm_description")})]}),e.jsxs(je,{children:[e.jsx(ye,{children:t("common.cancel")}),e.jsx(Ne,{onClick:()=>{le(!1),i==null||i()},children:t("profile_settings.reanalyze_confirm_action")})]})]})})]})},At={onboardingState:"loading",profile:null,currentStep:0,error:null};function Tt(s,a){switch(a.type){case"SET_LOADING":return{...s,onboardingState:"loading",error:null};case"SET_ANALYZING":return{...s,onboardingState:"analyzing",profile:a.profile,currentStep:0,error:null};case"SET_READY":return{...s,onboardingState:"ready",profile:a.profile,error:null};case"SET_ERROR":return{...s,onboardingState:"error",error:a.error};case"SET_NO_PROFILE":return{...s,onboardingState:"no-profile"};case"SET_STEP":return{...s,currentStep:a.step};case"SET_PROFILE":return{...s,profile:a.profile};case"RESET_FOR_RETRY":return{...s,onboardingState:"loading",error:null,currentStep:0};default:return s}}const Ce=s=>!!(s.business_category_slug&&s.business_category_slug.trim()!==""),Lt=({autoAnalyze:s=!0,basePath:a="/profile-onboarding"}={})=>{const r=Le(),[o]=Vs(),l=o.get("profileId"),{profiles:i,analyzeProfile:u,loading:c}=As(),{setSelectedProfile:t,addProfileToCache:n}=ys(),[d,g]=m.useReducer(Tt,At),p=m.useRef(!1),x=m.useRef(!1),f=d.profile?Ce(d.profile):!1,N=m.useCallback(async y=>{if(x.current){console.log("âï¸ Análise ignorada: já em progresso");return}console.log("ð Iniciando análise do perfil:",y.username),x.current=!0,g({type:"SET_ANALYZING",profile:y});let b=0;const w=setInterval(()=>{b=Math.min(b+1,3),g({type:"SET_STEP",step:b})},5e3);try{const L=await u(y.id);console.log("â
Análise concluÃda:",L.profile.username),g({type:"SET_READY",profile:L.profile})}catch(L){console.error("â Erro ao analisar perfil:",L);const $=L instanceof Error?L.message:"Erro desconhecido ao analisar perfil";g({type:"SET_ERROR",error:$})}finally{clearInterval(w),x.current=!1}},[u]),h=m.useCallback(async y=>{console.log("â³ Buscando perfil diretamente da API...");try{const b=await Ns.getUserInstagramProfiles();console.log("ð Perfis buscados:",b.length);const w=b.find(L=>
4L.id===y);w?(console.log("â
Perfil encontrado:",w.username),n(w),Ce(w)||!s?g({type:"SET_READY",profile:w}):N(w)):(console.log("â ï¸ Perfil não encontrado na API"),g({type:"SET_NO_PROFILE"}))}catch(b){console.error("â Erro ao buscar perfis:",b);const w=b instanceof Error?b.message:"Erro ao buscar perfil";g({type:"SET_ERROR",error:w})}},[n,N,s]);m.useEffect(()=>{if(p.current||x.current)return;if(c){g({type:"SET_LOADING"});return}if(i.length===0&&l){p.current=!0,h(l);return}if(i.length===0){g({type:"SET_NO_PROFILE"});return}let y;if(l){if(y=i.find(b=>b.id===l),!y){console.log("â ï¸ Perfil não encontrado, redirecionando para dashboard"),r("/dashboard",{replace:!0});return}}else{y=i[0],console.log("ð Redirecionando para URL com profileId"),r(`${a}?profileId=${y.id}${s?"&analyze=true":""}`,{replace:!0});return}p.current=!0,Ce(y)?(console.log("â
Perfil já completo, pulando análise"),g({type:"SET_READY",profile:y})):s?(console.log("ð Iniciando análise automática (perfil sem categoria)"),N(y)):(console.log("âï¸ Modo configurações: análise só quando o usuário pedir"),g({type:"SET_READY",profile:y}))},[l,i,c,r,N,h,s,a]);const I=m.useCallback(()=>{p.current=!1,x.current=!1,g({type:"RESET_FOR_RETRY"}),d.profile&&N(d.profile)},[d.profile,N]),v=m.useCallback(()=>{d.profile&&N(d.profile)},[d.profile,N]),C=m.useCallback(()=>{r("/dashboard",{replace:!0})},[r]),S=m.useCallback(y=>{t(y)},[t]),U=m.useCallback(y=>{g({type:"SET_PROFILE",profile:y})},[]);return{state:d.onboardingState,profile:d.profile,currentStep:d.currentStep,error:d.error,hasExistingData:f,retry:I,analyze:v,goToDashboard:C,selectProfile:S,setProfile:U}},Pt=()=>{const{t:s}=E();return[{icon:re,label:s("onboarding.connecting_ai"),sublabel:s("onboarding.preparing_analysis")},{icon:vs,label:s("onboarding.analyzing_colors"),sublabel:s("onboarding.identifying_palette")},{icon:ws,label:s("onboarding.detecting_typography"),sublabel:s("onboarding.choosing_fonts")},{icon:ne,label:s("onboarding.identifying_audience"),sublabel:s("onboarding.mapping_segments")}]},It=({profilePicUrl:s,username:a,currentStep:r,steps:o})=>{const{t:l}=E(),i=o[r].icon;return e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-background",children:e.jsxs("div",{className:"text-center space-y-8 max-w-md px-4",children:[s&&e.jsx("div",{className:"w-20 h-20 rounded-full overflow-hidden mx-auto ring-4 ring-purple-500/30 animate-pulse",children:e.jsx("img",{src:s,alt:a,className:"w-full h-full object-cover"})}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"w-24 h-24 rounded-full bg-gradient-to-r from-purple-500 to-pink-500 mx-auto flex items-center justify-center animate-pulse",children:e.jsx(i,{className:"w-12 h-12 text-white"})}),e.jsx("div",{className:"absolute inset-0 w-24 h-24 mx-auto",children:e.jsx("div",{className:"w-full h-full rounded-full border-4 border-purple-500/30 border-t-purple-500 animate-spin"})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h2",{className:"text-xl font-semibold text-foreground",children:o[r].label}),e.jsx("p",{className:"text-muted-foreground",children:o[r].sublabel})]}),e.jsx("div",{className:"flex justify-center gap-2",children:o.map((u,c)=>e.jsx("div",{className:`w-2.5 h-2.5 rounded-full transition-all duration-300 ${c<=r?"bg-purple-500 scale-100":"bg-gray-300 dark:bg-gray-600 scale-75"}`},c))}),e.jsxs("div",{className:"inline-flex items-center gap-2 px-4 py-2 bg-muted rounded-full",children:[e.jsx(re,{className:"w-4 h-4 text-purple-500"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:l("onboarding.ai_analysis_badge")})]})]})})},Ot=({onRetry:s})=>{const{t:a}=E();return e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-background",children:e.jsxs("div",{className:"text-center space-y-6 max-w-md px-4",children:[e.jsx("div",{className:"w-20 h-20 rounded-full bg-red-100 dark:bg-red-900/30 flex items-center justify-center mx-auto",children:e.jsx(qs,{className:"w-10 h-10 text-red-500"})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h2",{className:"text-xl font-semibold text-foreground",children:a("onboarding.analysis_error_title")}),e.jsx("p",{className:"text-muted-foreground",children:a("onboarding.analysis_error_description")}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[a("onboarding.analysis_error_support_hint","Se o problema persistir,")," ",e.jsx("a",{href:"/support",className:"text-primary hover:underline font-medium",children:a("onboarding.contact_support","entre em contato com o suporte")})]})]}),e.jsxs(A,{onClick:s,className:"bg-gradient-to-r from-purple-600 to-pink-600 hover:from-purple-700 hover:to-pink-700",size:"lg",children:[e.jsx(X,{className:"w-4 h-4 mr-2"}),a("onboarding.try_again")]})]})})},ga=()=>{const s=Le(),a=Ws(),{t:r}=E(),{toast:o}=js(),l=Pt(),{updateProfile:i,syncProfile:u}=As(),c=a.pathname.startsWith(ms),{state:t,profile:n,currentStep:d,hasExistingData:g,retry:p,analyze:x,goToDashboard:f,selectProfile:N,setProfile:h}=Lt({autoAnalyze:!c,basePath:c?ms:lt});q.useEffect(()=>{t==="no-profile"&&f()},[t,f]);const I=q.useCallback(()=>{var w;(((w=window.history.state)==null?void 0:w.idx)??0)>0?s(-1):s("/dashboard")},[s]),[v,C]=q.useState(!1),S=q.useRef(!1),U=q.useCallback(async()=>
4{if(!(!n||S.current)){S.current=!0,C(!0);try{const b=await u(n.id);h(b.profile),o({title:r("instagram_dropdown.profile_updated"),description:r("instagram_dropdown.profile_synced",{username:b.profile.username})})}catch{o({title:r("instagram_dropdown.error"),description:r("instagram_dropdown.sync_error"),variant:"destructive"})}finally{S.current=!1,C(!1)}}},[n,u,h,o,r]),y=async b=>{if(!n)return;const w=b.site_context_fields?ft(n.site_context,b.site_context_fields,new Date().toISOString()):void 0;try{const L=await i({id:n.id,brand_colors:b.brand_colors,logo_url:b.logo_url,typography:b.typography,business_category_slug:b.business_category_slug,business_description:b.business_description,target_audience:b.target_audience,language:b.language,ai_preferences:b.ai_preferences,...w!==void 0&&{site_context:w}});if(N(L),c){o({title:r("profile_settings.saved_title"),description:r("profile_settings.saved_description")}),I();return}s("/welcome",{replace:!0})}catch(L){throw console.error("Erro ao salvar configurações:",L),o({title:r("common.error"),description:r("profile_settings.save_error"),variant:"destructive"}),L}};switch(t){case"loading":return e.jsx(ee,{});case"analyzing":return e.jsx(It,{profilePicUrl:n==null?void 0:n.profile_pic_url,username:n==null?void 0:n.username,currentStep:d,steps:l});case"error":return e.jsx(Ot,{onRetry:p});case"no-profile":return e.jsx(ee,{});case"ready":return n?e.jsx(Et,{profile:n,onComplete:y,showBackButton:g,mode:c?"settings":"onboarding",onBack:I,onReanalyze:c?x:void 0,onSyncProfile:c?U:void 0,syncingProfile:v}):e.jsx(ee,{});default:return e.jsx(ee,{})}};export{ga 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.