PageSourceSearch

https://prevamp.ai/assets/RequestOrganization-DmZnl9rS.js

js prevamp.ai collected 2026-10-05 14:53:23 UTC 96,923 bytes, 1 lines download raw bytes

1import{r as a,j as e}from"./vendor-motion-CA1YqSI-.js";import{c as Mt,eV as Hs,eW as Ks,eX as Js,eY as Mr,s as L,eZ as Qs,aK as ce,L as re,V as W,I as J,au as is,b9 as Xs,B as F,aW as Zs,a4 as ea,J as $t,K as Wt,M as pt,Q as ft,R as ht,d as O,b7 as ta,aN as ra,bW as sa,bX as aa,bY as na,bZ as oa,e as ls,g as ia,aq as la,b as ds,j as da,T as Vr,bw as ca,bx as zr,a6 as ua,bK as ma,a as ga,b_ as pa,bO as fa,e_ as We,c5 as Gr,e$ as Hr,C as ha,h as xa,f0 as te,t as ya,A as Kr,df as ba,f1 as Jr,dk as _a,f2 as Qr,$ as wa,f3 as va,f4 as ja,c6 as Ut,f5 as Na,f6 as Ca,aS as Sa}from"./index-CAsjarNH.js";import{b as ka,i as Xr,e as Zr,c as Bt,h as Ra,d as Pa,f as es}from"./onboardingStorePreview-BPQTMSv4.js";import{A as Ea}from"./AppHeader-bPQ-1Sj1.js";import{A as Aa,a as qa,b as Ta,c as Ia,d as Oa,e as Da,f as La,g as Fa}from"./alert-dialog-CVDW1RzQ.js";import{C as Ua}from"./checkbox-C_yS6NGN.js";import{t as Ye}from"./countries-BAv9iHe5.js";import{u as Ba}from"./useCalendlySetting-BiXGebMf.js";import{u as $a}from"./useAnalyticsEvents-xGPJbMWb.js";import{V as Wa}from"./VisualiserBrandPreview-CtVe-U0k.js";import Yt from"./circle-alert-CKMHzB01.js";import{u as Ya}from"./usePricingRegionLock-T0xQyqhB.js";import Ma from"./rotate-cw-DhHHiWQu.js";import Va from"./globe-DrdQD8tE.js";import{P as za,a as Ga}from"./ProductReviewStep-B9k_nszR.js";import{T as Ha,P as Ka,o as Ja,r as Qa,w as Xa,q as Za,p as en}from"./legalUrls-DzmJ67mO.js";import{B as tn}from"./BrandKitPreview-CauWc7rT.js";import ts from"./external-link-DmZvQgPN.js";import{P as rn}from"./PasswordFieldsWithPolicy-DUGV27xV.js";import{l as sn}from"./index-Bld3dpmC.js";import{h as an}from"./useSampleSpaces-5SjIij2h.js";import{b as nn,c as on}from"./useOrgAccessRequest-8sQ6Bjhn.js";import{O as ln}from"./OnboardingStoreReadyChip-BJutcceP.js";import{c as dn}from"./sampleSwatchColour-BJ_KsAoL.js";import cn from"./clock-D74tcQH2.js";import un from"./info-BeJEYKx9.js";import"./vendor-charts-DeiE-oVq.js";import"./vendor-pdf-BBBLYw70.js";import"./authPasswordReset-BgMWz8i7.js";import"./BrandLogo-BUMSbVI7.js";import"./useOrganizationCredits-BDkTnsiO.js";
1import"./useMarketingSolutionPages-Bb02qdJc.js";import"./shield-check-C4jHCW7j.js";import"./shield-BhXickTl.js";import"./layers-CsHVCt3b.js";import"./book-open-BK2Z3OAa.js";import"./externalSession-xsoAoX7A.js";import"./minus-CGicv69e.js";import"./CategoryIcon-BmB8uSVB.js";import"./CustomTypeRequestDialog-BjcZz5Tm.js";import"./chevron-left-Kshq3_WD.js";import"./useBrandFonts-DReE0kM3.js";import"./imageryRoles-6EHBayve.js";import"./eye-B88PWiyW.js";import"./eye-off-CFO5Lmng.js";function rs(n){try{const l=new URL(n.startsWith("http")?n:`https://${n}`);return`${l.protocol}//${l.hostname}`}catch{return}}function mn(n){return n.seed_kind==="url"?{kind:"url",value:n.seed_value}:n.seed_kind==="org_url"?{kind:"org_url",value:n.seed_value}:{kind:"image",value:n.seed_value,fileName:n.file_name??void 0}}function gn(n){const{user:l}=Mt(),[u,c]=a.useState(!1),[m,y]=a.useState(null),[v,x]=a.useState(null),[p,b]=a.useState(!n),[A,T]=a.useState(null);return a.useEffect(()=>{if(!n){b(!0);return}let S=!1;(async()=>{let j=await Hs();if(j&&l&&!j.user_id){const N=await Ks(l.id);N&&(j=N)}if(S)return;if(!j){const N=Js();if(!N){b(!0);return}if(y(N),N.kind==="image"){x({imageDataUrl:N.value,imageFileName:N.fileName}),b(!0),Mr();return}await I(N.value,null);return}if(T(j.id),y(mn(j)),j.seed_kind==="image"){x({imageDataUrl:j.seed_value,imageFileName:j.file_name??void 0}),b(!0);return}if(j.seed_kind==="org_url"){x({websiteUrl:j.seed_value}),b(!0);return}const R=j.scraped_data;if(R&&(R.brand||R.category||R.name)){x({websiteUrl:R.websiteUrl??rs(j.seed_value),brandName:R.brand,productCategory:R.category,productName:R.name}),b(!0);return}await I(j.seed_value,j.id)})();async function I(j,R){const N=rs(j);x({websiteUrl:N}),c(!0);try{const{data:k,error:P}=await L.functions.invoke("scrape-product-page",{body:{url:j}});if(S)return;if(P){console.warn("[B2BSeedPrefill] scrape failed",P);return}const C=k?.data??k??{},U={websiteUrl:N,brandName:typeof C?.brand=="string"?C.brand:void 0,productCategory:typeof C?.category=="string"?C.category:void 0,productName:typeof C?.name=="string"?C.name:void 0};x(se=>({...se??{},...U})),R&&await Qs(R,{websiteUrl:U.websiteUrl,brand:U.brandName,category:U.productCategory,name:U.productName})}catch(k){console.warn("[B2BSeedPrefill] unexpected error",k)}finally{S||(c(!1),b(!0),R||Mr())}}return()=>{S=!0}},[n,l?.id]),{loading:u,seed:m,data:v,ready:p,seedRowId:A}}const gt=[{key:"reach",name:"Reading your homepage"},{key:"logo",name:"Finding your logo"},{key:"colours",name:"Picking up brand colours"},{key:"details",name:"Reading company details"},{key:"fonts",name:"Identifying your fonts"}],ss=({children:n})=>e.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-[0.1em] text-muted-foreground",children:n});function pn(n){const{domain:l,reading:u,orgName:c,onOrgNameChange:m,onWebsiteBlur:y,websiteNotice:v,displayName:x,onDisplayNameChange:p,description:b,onDescriptionChange:A,descriptionFromSite:T,pageAddress:S,logoUrl:I,candidates:j=[],deadUrls:R=[],uploading:N,primaryColor:k,accentColor:P,palette:C,onSelectCandidate:U,onLogoError:se,onUploadClick:ae,onColourChange:B,fileInput:fe,footnote:Q,productsFound:H}=n,[ne,V]=a.useState(0),Ce=a.useRef({});a.useEffect(()=>{if(!u)return;const i=window.setInterval(()=>{V(q=>q>=gt.length-1?q:q+1)},1600);return()=>window.clearInterval(i)},[u]);const Re=u?ne:gt.length,Te=u?Math.min(92,Math.round((ne+.5)/gt.length*100)):100,ie=!u&&!I,Se=Array.from(new Set([I,...j].filter(i=>i&&!R.includes(i)))),ue=(i,q,K)=>e.jsxs("div",{children:[e.jsx(W,{className:"text-[11px]",children:i}),e.jsxs("div",{className:"mt-1 flex items-stretch gap-0 overflow-hidden rounded-md border border-input",children:[e.jsx("button",{type:"button",onClick:()=>Ce.current[q]?.click(),"aria-label":`Choose ${i.toLowerCase()}`,className:"h-8 w-8 shrink-0 border-r border-input",style:{backgroundColor:K??"hsl(var(--muted))"}}),e.jsx(J,{value:K?K.toUpperCase():"",placeholder:"Not detected",onChange:Y=>B(q,Y.target.value),className:"h-8 rounded-none border-0 px-2 font-mono text-[11px] focus-visible:ring-0 focus-visible:ring-offset-0"}),e.jsx("input",{ref:Y=>{Ce.current[q]=Y},type:"color",value:K??"#000000",onChange:Y=>B(q,Y.target.value),className:"sr-only","aria-label":`${i} brand colour`,tabIndex:-1})]})]});return u?e.jsxs("div",{className:"grid items-start gap-8 lg:grid-cols-2",children:[fe,e.jsxs("div",{className:"space-y-3",children:[e.jsx(ss,{children:"What we are pulling"}),e.jsx("div",{children:gt.map((i,q)=>{const K=q<Re,Y=q===Re;return e.jsxs("div",{className:"flex items-center gap-3 border-b border-border/60 py-2.5 last:border-b-0",children:[e.jsx("span",{className:`grid h-[18px] w-[18px] shrink-0 place-items-center rounded-full border ${K?"border-primary bg-primary text-primary-foreground":Y?"border-primary text-primary":"border-border text-muted-foreground"}`,children:K?e.jsx(ce,{className:"h-2.5 w-2.5"}):Y?e.jsx(re,{className:"h-2.5 w-2.5 animate-spin"}):null}),e.jsx("span",{className:`flex-1 text-xs ${K||Y?"font-medium text-foreground":"text-muted-foreground"}`,children:i.name}),e.jsx("span",{className:"font-mono text-[10px] text-muted-foreground",children:K?"done":Y?"reading":"queued"})]},i.key)})}),e.jsx("div",{className:"h-1.5 rounded-full bg-muted",children:e.jsx("div",{className:"h-1.5 rounded-full bg-platform-accent transition-all duration-700",style:{width:`${Te}%`}})}),e.jsx("p",{className:"rounded-lg border border-border bg-muted/30 p-3 text-[11px] leading-relaxed text-muted-foreground",children:"Nothing is saved yet. Your organisation is created when you make your account."})]}),e.jsxs("div",{className:"space-y-3.5",children:[e.jsx(ss,{children:"Your organisation"}),e.jsxs("div",{className:"rounded-lg border border-border bg-background p-3.5",children:[e.jsxs("p",{className:"text-[11px] text-muted-foreground",children:["Reading ",l]}),e.jsxs("div",{className:"mt-3 flex gap-5",children:[e.jsx("div",{className:"h-12 w-12 animate-pulse rounded-lg bg-muted"}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx("div",{className:"h-4 w-2/3 animate-pulse rounded bg-muted"}),e.jsx("div",{className:"h-4 w-1/2 animate-pulse rounded bg-muted"})]})]})]}),e.jsx("div",{className:"h-10 animate-pulse rounded-md bg-muted"}),e.jsx("div",{className:"h-10 animate-pulse rounded-md bg-muted"}),e.jsx("div",{className:"h-20 animate-pulse rounded-md bg-muted"})]})]}):e.jsxs("div",{className:"grid items-start gap-6 lg:grid-cols-[minmax(0,1fr)_360px]",children:[fe,e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(W,{htmlFor:"org_name",className:"text-[12.5px]",children:"Organisation name"}),e.jsx(J,{id:"org_name",value:c,onChange:i=>m(i.target.value),placeholder:"Enter your organisation name",className:"mt-1"}),v]}),e.jsxs("div",{children:[e.jsx(W,{htmlFor:"display_name",className:"text-[12.5px]",children:"Visualiser name"}),e.jsx(J,{id:"display_name",value:x,onChange:i=>p(i.target.value),onBlur:y,placeholder:c?`${c} Visualiser`:"Your Visualiser name",className:"mt-1"})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[e.jsx(W,{htmlFor:"org_description",className:"text-[12.5px]",children:"Short description"}),T&&e.jsx("span",{className:"text-[11px] text-muted-foreground",children:"from your about page"})]}),e.jsx(is,{id:"org_description",value:b,onChange:i=>A(i.target.value),rows:2,maxLength:400,placeholder:"One or two lines about what you sell and who you sell to.",className:"mt-1 resize-none"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-[11px] font-medium text-foreground",children:"Brand colours"}),e.jsxs("div",{className:"mt-1.5 grid grid-cols-2 gap-2 sm:grid-cols-4",children:[ue("Primary","primary",C?.primary??k),ue("Accent","accent",C?.accent??P),C?.background?ue("Backgroun
1d","background",C.background):null,C?.text?ue("Text","text",C.text):null]})]}),S&&e.jsxs("div",{children:[e.jsx(W,{className:"text-[12.5px]",children:"Your page address"}),e.jsx("div",{className:"mt-1 rounded-md border border-input bg-muted/30 px-3 py-2 text-xs font-mono text-foreground truncate",children:S}),e.jsx("p",{className:"mt-1 text-[11px] font-medium text-primary",children:"Reserved for you when you create your account"})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-lg border border-border bg-card p-3 space-y-2",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[e.jsx("span",{className:"text-[11.5px] font-semibold text-foreground",children:"Logo"}),e.jsx("span",{className:"text-[10.5px] text-muted-foreground",children:Se.length>0?`${Se.length} found · pick one`:"None found · upload one"})]}),ie&&e.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-amber-400/50 bg-amber-50 p-2 dark:bg-amber-950/20",children:[e.jsx(Yt,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-amber-600"}),e.jsx("p",{className:"text-[10.5px] leading-relaxed text-muted-foreground",children:"We could not find a logo on your site. Upload one now or add it later."})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[Se.slice(0,5).map(i=>{const q=i===I;return e.jsxs("button",{type:"button",onClick:()=>U?.(i),className:`relative grid aspect-[4/3] place-items-center rounded-lg border p-1.5 transition-colors ${q?"border-platform-accent bg-background":"border-border bg-muted/30 hover:border-foreground
1/30"}`,children:[e.jsx("img",{src:i,alt:"",onError:q?se:void 0,className:"max-h-full max-w-full object-contain"}),q&&e.jsx("span",{className:"absolute -right-1 -top-1 grid h-4 w-4 place-items-center rounded-full bg-platform-accent text-white",children:e.jsx(ce,{className:"h-2.5 w-2.5"})})]},i)}),e.jsx("button",{type:"button",onClick:ae,disabled:N,className:"grid aspect-[4/3] place-items-center rounded-lg border border-dashed border-border text-muted-foreground transition-colors hover:border-foreground/30 hover:text-foreground",children:e.jsxs("span",{className:"flex flex-col items-center gap-0.5",children:[N?e.jsx(re,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Xs,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"text-[10px] font-medium",children:"Upload"})]})})]})]}),e.jsxs("div",{className:"rounded-lg border border-border bg-background p-2.5 shadow-xs",children:[e.jsx("p",{className:"mb-1.5 text-[11px] font-semibold text-foreground",children:"Visualiser Preview"}),e.jsx(Wa,{colors:{primary:C?.primary||k||"#1f2933",accent:C?.accent||P||"#c2703f",background:C?.background||"#faf8f5",text:C?.text||"#1f2933"},logoUrl:I,name:x||c||"Your organisation"})]}),H&&H.count>0&&e.jsxs("div",{className:"rounded-lg border border-border p-2.5",children:[e.jsxs("p",{className:"text-[11px] font-semibold text-foreground",children:["We also found ",H.count," products"]}),H.chips&&H.chips.length>0&&e.jsx("div",{className:"mt-1 flex flex-wrap gap-1",children:H.chips.map(i=>e.jsxs("span",{className:"rounded-full border border-border px-2 py-0.5 text-[9px] font-medium text-muted-foreground",children:[i.label,typeof i.count=="number"?` · ${i.count}`:""]},i.label))})]})]}),Q]})}const fn=["Your public profile on the platform","Your whole catalogue, no product limit","Shoppers visualise your products in their own room","Enquiries come straight back to you"],hn=["Visualisation built into your own website","Your own branded Visualiser store","Image Studio for marketing imagery","Analytics and credit reporting"];function xn({websiteUrl:n,reading:l,readComplete:u=!1,duplicateBlocked:c=!1,onWebsiteChange:m,onWebsiteBlur:y,onRead:v,onRescan:x,websiteNotice:p,readError:b,footnote:A,platformName:T}){return e.jsxs("div",{className:"grid gap-8 md:grid-cols-[minmax(0,1fr)_260px]",children:[e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"website_url",children:"Your website"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(J,{id:"website_url",type:"text",inputMode:"url",value:n,onChange:S=>m(S.target.value),onBlur:y,placeholder:"yourcompany.com",disabled:l,autoFocus:!0}),!u&&e.jsx(F,{type:"button",variant:"signupCta",onClick:v,disabled:l||c||!n.trim(),children:l?e.jsx(re,{className:"h-4 w-4 animate-spin"}):c?"Organisation found":"Read my site"}),u&&!l&&x&&e.jsx(F,{type:"button",variant:"outline",size:"icon",onClick:x,title:"Read my site again",className:"shrink-0",children:e.jsx(Ma,{className:"h-4 w-4"})})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"We read your name, logo, colours and what you sell, so there is very little to type. You can correct anything on the next screen."}),b&&e.jsx("p",{className:"rounded-lg border border-destructive/30 bg-destructive/5 px-3 py-2 text-xs text-destructive",children:b}),p]}),l&&e.jsxs("div",{className:"flex items-start gap-3 rounded-lg border border-primary/30 bg-primary/5 p-4 text-sm",children:[e.jsx(re,{className:"mt-0.5 h-4 w-4 shrink-0 animate-spin text-primary"}),e.jsx("p",{className:"text-muted-foreground",children:"Reading your site. This takes a few seconds, then everything unlocks."})]}),!n.trim()&&!l&&e.jsxs("div",{className:"rounded-lg border border-border bg-muted/30 p-4 text-xs text-muted-foreground",children:[e.jsxs("p",{className:"flex items-center gap-2 text-foreground",children:[e.jsx(Va,{className:"h-3.5 w-3.5"}),"No website yet?"]}),e.jsx("p",{className:"mt-1 leading-relaxed",children:"Carry on without one. Type your details by hand on the next screen and add products from links, a spreadsheet or your store once you are in."})]}),A]}),e.jsxs("aside",{className:"space-y-5 md:border-l md:pl-6",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-[0.1em] text-muted-foreground",children:"14-day free trial"}),e.jsx("ul",{className:"mt-2 space-y-2",children:fn.map(S=>e.jsxs("li",{className:"flex items-start gap-2 text-xs leading-relaxed text-foreground",children:[e.jsx(ce,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-primary"}),S]},S))})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-[0.1em] text-muted-foreground",children:"Later, if you want it"}),e.jsx("ul",{className:"mt-2 space-y-2",children:hn.map(S=>e.jsxs("li",{className:"flex items-start gap-2 text-xs leading-relaxed text-muted-foreground",children:[e.jsx(Zs,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),S]},S))}),e.jsxs("p",{className:"mt-3 text-[11px] leading-relaxed text-muted-foreground",children:["A payment card is required when starting your 14-day free trial after account creation",T?` inside ${T}`:"","."]})]})]})]})}function yn({urls:n,onChange:l,max:u=10}){const c=n.filter(m=>m.trim().length>0).length;return e.jsxs("div",{className:"grid gap-8 lg:grid-cols-[minmax(0,1fr)_260px]",children:[e.jsx("div",{className:"space-y-6",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[e.jsx(W,{children:"Product page links"}),e.jsxs("span",{className:"text-[11px] text-muted-foreground",children:[c," added · up to ",u," during sign-up"]})]}),e.jsx(za,{value:n,onChange:l,max:u}),e.jsx("p",{className:"text-xs text-muted-foreground",children:c>0?"We read each page for the name, category and images once your organisation is built.":`Paste up to ${u} links to start with, or skip this and add products from your dashboard.`})]})}),e.jsxs("aside",{className:"space-y-4 lg:border-l lg:pl-6",children:[e.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-[0.14em] text-muted-foreground",children:"Coming in so far"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-serif text-3xl font-semibold text-foreground",children:c}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["product",c===1?"":"s"," ready"]})]}),e.jsx("p",{className:"text-[11px] leading-relaxed text-muted-foreground",children:"Most organisations start with a range or two and add the rest from the dashboard."}),e.jsx("p",{className:"text-[11px] leading-relaxed text-muted-foreground",children:"Adding products is free forever — it is how shoppers find you. Paid packages are about putting visualisation on your own site, not about your catalogue."})]})]})}function bn(n){return n.filter(l=>l.status!=="failed"&&l.status!=="reading").map(l=>({name:(l.name||"").trim()||"Untitled product",imageUrl:l.imageUrl||null}))}function _n(n,l=[],u=[],c){const m=c&&c.length>0?[c]:[],y=Array.from(new Set(u.filter(p=>p.length>0)));if(m.length)return Array.from(new Set([...m,...y])).slice(0,8);if(y.length)return y.slice(0,8);const x=(Array.isArray(n?.imagery)?n.imagery:[]).map(p=>typeof p=="string"?p:p?.url).filter(p=>typeof p=="string"&&p.length>0);return Array.from(new Set(x.length?x:l)).slice(0,8)}function wn({orgName:n,websiteUrl:l,logoUrl:u,primaryColor:c,accentColor:m,palette:y,tagline:v,storeName:x,scrapedKit:p,loading:b=!1,fallbackVisualiserImages:A=[],catalogueProducts:T=[],heroRoomUrl:S=null,heroProcessing:I=!1}){const j=a.useMemo(()=>{const N=p??{};return{...N,website:l,tagline:v||N.tagline,colors:{...N.colors,...y,primary:c||N.colors?.primary,accent:m||N.colors?.accent},logo_variants_purpose:{...N.logo_variants_purpose,primary:u||N.logo_variants_purpose?.primary}}},[m,u,y,c,p,v,l]),R=a.useMemo(()=>_n(p,A,T.map(N=>N.imageUrl||""),S),[A,p,T,S]);return e.jsx("div",{children:e.jsx("div",{className:"[&>div>div:first-child]:py-3 [&>div>div:last-child]:min-h-0 [&>div>div:last-child]:p-4",children:e.jsx(tn,{kit:j,entityName:n||"Your organisation",masterLogoUrl:u,defaultOpen:!0,defaultView:"kit",storageKey:"org-signup-brandkit",hideEmptyLogoRoles:!0,compactPopulatedOnly:!0,loading:b,storeName:x||n,storeLogoUrl:u,storeTheme:{primaryColor:c||null,accentColor:m||null},visualiserImages:R,catalogueProducts:T,productsContext:"signup"})})})}const vn=[{key:"organisation",label:"Creating your organisation",done:"Organisation created"},{key:"brand",label:"Saving your brand",done:"Brand saved"},{key:"products",label:"Preparing your products for visualisation",done:"Products prepared"},{key:"profile",label:"Finalising your setup",done:"Setup finalised"}];
1function jn({orgName:n,productCount:l,emailVerified:u,building:c,completed:m,statusText:y,finished:v,pageUrl:x,storePath:p,accountEmail:b,platformName:A,onBuild:T,onGoToDashboard:S,onViewPage:I,onViewStore:j,recoveryPending:R=!1}){const N=m.length;if(v){const k=[{label:"Your store",value:x?`${x} · ready to preview`:p?"Ready for you to preview":"Live — add a store from your dashboard when you want one"},{label:"Products",value:l>0?p?`${l} in your store · private until you go live`:`${l} · add more any time, free`:"Add your first products any time, free"},{label:"Plan",value:"14-day free trial"}];return e.jsxs("div",{className:"grid gap-8 lg:grid-cols-[minmax(0,1fr)_280px]",children:[e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-start gap-3 rounded-xl border border-primary/30 bg-primary/5 p-4",children:[e.jsx("span",{className:"mt-0.5 grid h-6 w-6 flex-none place-items-center rounded-full bg-primary/15 text-primary",children:e.jsx(ce,{className:"h-3.5 w-3.5"})}),e.jsxs("p",{className:"text-sm leading-relaxed text-foreground",children:[n||"Your organisation"," is live",A?` on ${A}`:"",". Your dashboard is where you add the rest and decide whether you want a trial."]})]}),e.jsx("dl",{className:"divide-y divide-border rounded-xl border border-border",children:k.map(P=>e.jsxs("div",{className:"flex items-baseline justify-between gap-4 px-4 py-3",children:[e.jsx("dt",{className:"text-xs font-semibold text-foreground",children:P.label}),e.jsx("dd",{className:"text-right text-xs text-muted-foreground",children:P.value})]},P.label))}),e.jsxs("div",{className:"flex flex-wrap gap-3",children:[e.jsx(F,{onClick:S,children:"Go to my dashboard"}),j&&e.jsxs(F,{variant:"outline",onClick:j,className:"gap-2",children:[p?"View my store":"Open the Visualiser",e.jsx(ts,{className:"h-3.5 w-3.5"})]}),I&&!j&&e.jsxs(F,{variant:"outline",onClick:I,className:"gap-2",children:["View my page",e.jsx(ts,{className:"h-3.5 w-3.5"})]})]})]}),e.jsxs("aside",{className:"space-y-3 lg:border-l lg:pl-6",children:[e.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-[0.14em] text-muted-foreground",children:"What happens next"}),e.jsx("p",{className:"text-xs leading-relaxed text-muted-foreground",children:l>0&&p?"Your products are in your store for you to preview. Shoppers will not see them until you go live.":"Adding products is free, forever. Putting visualisation on your own site comes with a package."}),e.jsx("p",{className:"text-xs leading-relaxed text-muted-foreground",children:"Putting visualisation on your own site, a branded Visualiser store and Image Studio come with a package. Start a trial from your dashboard when you are ready."})]})]})}return e.jsxs("div",{className:"grid gap-8 lg:grid-cols-[minmax(0,1fr)_280px]",children:[e.jsxs("div",{className:"space-y-6",children:[e.jsxs("ol",{className:"space-y-2.5",children:[b&&e.jsxs("li",{className:"flex items-center gap-3 rounded-lg border border-border bg-muted/25 px-4 py-3 text-sm",children:[e.jsx("span",{className:"grid h-6 w-6 flex-none place-items-center rounded-full bg-primary/15 text-primary",children:e.jsx(ce,{className:"h-3.5 w-3.5"})}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block text-foreground",children:"Account created"}),e.jsx("span",{className:"block truncate text-xs text-muted-foreground",children:b})]})]}),vn.map((k,P)=>{const C=m.includes(k.key),U=c&&P===N;return e.jsxs("li",{className:"flex items-center gap-3 rounded-lg border border-border bg-muted/25 px-4 py-3 text-sm",children:[e.jsx("span",{className:`grid h-6 w-6 flex-none place-items-center rounded-full ${C?"bg-primary/15 text-primary":"bg-muted text-muted-foreground"}`,children:C?e.jsx(ce,{className:"h-3.5 w-3.5"}):U?e.jsx(re,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx("span",{className:"text-[11px]",children:P+1})}),e.jsx("span",{className:C?"text-foreground":"text-muted-foreground",children:C?k.done:k.key==="products"&&l>0?`Preparing your ${l} product${l===1?"":"s"} for visualisation`:k.label})]},k.key)})]}),!c&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(F,{className:"w-full",onClick:T,disabled:!u,children:R?"Check setup again":"Create my organisation"}),!u&&e.jsx("p",{className:"text-center text-xs text-muted-foreground",children:"Confirm your email address above and the build starts by itself."})]}),c&&y&&e.jsx("p",{className:"text-xs text-muted-foreground",role:"status",children:y}),!c&&R&&y&&e.jsx("p",{className:"text-center text-xs text-muted-foreground",role:"status",children:y})]}),e.jsxs("aside",{className:"space-y-3 lg:border-l lg:pl-6",children:[e.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-[0.14em] text-muted-foreground",children:"While you wait"}),e.jsx("p",{className:"text-xs leading-relaxed text-muted-foreground",children:"Everything you checked is being written now. You can close this window — the build carries on and we will email you when it is done."}),e.jsx("p",{className:"text-xs leading-relaxed text-muted-foreground",children:"Free plan. No card, no trial clock, nothing expires."})]})]})}const Nn=a.forwardRef(function({orgName:l,logoUrl:u,productsFound:c,brandsCount:m,storesCount:y,planLabel:v,payLine:x,fullName:p,email:b,onFullNameChange:A,onEmailChange:T,onCreateAccount:S,onGoogle:I,onOpenSignIn:j,signedInEmail:R,onContinue:N,submitting:k,googleLoading:P},C){const U=a.useRef(null),[se,ae]=a.useState(""),[B,fe]=a.useState(""),[Q,H]=a.use
1State(null);a.useImperativeHandle(C,()=>({submit:()=>U.current?.requestSubmit()}));const ne=b.trim().toLowerCase(),V=B.trim().toLowerCase(),Ce=V.length>0&&V===ne,Re=V.length>0&&V!==ne,Te=(l||"").trim().charAt(0).toUpperCase()||"?",ie=[typeof c=="number"&&c>0?`${c} products ready to import`:null,typeof m=="number"&&m>0?`${m} brand`:null,typeof y=="number"&&y>0?`${y} store`:null].filter(Boolean),Se=[{name:"Your brand identity",detail:"Logo, colours and description read from your website."},{name:"Your catalogue setup",detail:"Your brand and the products you added, ready to visualise."},{name:"Your organisation and store",detail:"Your organisation, brand, products and store are saved together."},{name:"Your dashboard",detail:"Review your products, start visualising and begin a trial whenever you want."}],ue=async i=>{if(i.preventDefault(),H(null),!p.trim()){H("Please enter your name.");return}if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(b.trim())){H("Please enter a valid work email address.");return}if(!Ce){H("Please confirm your email address. The two entries must match.");return}const q=ea.safeParse(se);if(!q.success){H(q.error.issues[0]?.message??"Please choose a stronger password.");return}await S(se)};return e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 border-b border-border bg-primary/5 px-5 py-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"grid h-9 w-9 place-items-center overflow-hidden rounded-lg border border-border bg-background text-sm font-semibold text-foreground",children:u?e.jsx("img",{src:u,alt:`${l} logo`,className:"h-full w-full object-contain"}):Te}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-sm font-semibold text-foreground",children:l||"Your organisation"}),ie.length>0&&e.jsx("p",{className:"truncate text-xs text-muted-foreground",children:ie.join(" · ")})]})]}),(v||x)&&e.jsxs("div",{className:"text-right",children:[v&&e.jsx("p",{className:"text-[11px] text-muted-foreground",children:v}),x&&e.jsx("p",{className:"text-base font-semibold text-foreground",children:x})]})]}),e.jsxs("div",{className:"grid gap-0 md:grid-cols-[1fr_250px]",children:[e.jsx("div",{className:"border-b border-border px-5 py-4 md:border-b-0 md:border-r",children:R?e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-semibold text-foreground",children:"You are signed in"}),e.jsxs("p",{className:"mt-1 text-sm text-muted-foreground",children:["Continuing as ",e.jsx("span",{className:"font-medium text-foreground",children:R}),". Your setup will be saved to this account."]})]})}):e.jsxs("form",{ref:U,onSubmit:ue,className:"space-y-3",children:[e.jsxs(F,{type:"button",variant:"outline",size:"sm",className:"w-full",onClick:I,disabled:P||k,children:[P?e.jsx(re,{className:"mr-2 h-4 w-4 animate-spin"}):null,"Continue with Google"]}),e.jsxs("div",{className:"flex items-center gap-3 text-[11px] uppercase tracking-wide text-muted-foreground",children:[e.jsx("span",{className:"h-px flex-1 bg-border"}),"or",e.jsx("span",{className:"h-px flex-1 bg-border"})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(W,{htmlFor:"account-name",className:"text-xs",children:"Full name"}),e.jsx(J,{id:"account-name",value:p,onChange:i=>A(i.target.value),autoComplete:"name",disabled:k})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(W,{htmlFor:"account-email",className:"text-xs",children:"Work email"}),e.jsx(J,{id:"account-email",type:"email",value:b,onChange:i=>T(i.target.value),autoComplete:"email",disabled:k})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(W,{htmlFor:"account-email-confirm",className:"text-xs",children:"Confirm email"}),e.jsx(J,{id:"account-email-confirm",type:"email",value:B,onChange:i=>fe(i.target.value),autoComplete:"off",disabled:k,"aria-invalid":Re}),Re&&e.jsx("p",{className:"text-xs text-destructive",children:"The two email addresses do not match."}),Ce&&e.jsxs("p",{className:"flex items-center gap-1 text-xs text-primary",children:[e.jsx(ce,{className:"h-3 w-3"})," Addresses match."]})]}),e.jsx(rn,{password:se,onPasswordChange:ae,showConfirmField:!1,showPolicySummary:!1,passwordId:"account-password",disabled:k}),Q&&e.jsx("p",{className:"text-sm text-destructive",children:Q}),e.jsxs("p",{className:"text-[11px] leading-relaxed text-muted-foreground",children:["By continuing you agree to our"," ",e.jsx("a",{href:Ha,className:"underline",target:"_blank",rel:"noreferrer",children:"Terms and Conditions"})," ","and"," ",e.jsx("a",{href:Ka,className:"underline",target:"_blank",rel:"noreferrer",children:"Privacy Policy"}),". We will email a verification link, and a code you can type in here instead."]})]})}),e.jsxs("aside",{className:"px-4 py-4",children:[e.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-widest text-muted-foreground",children:"What gets saved"}),e.jsx("ul",{className:"mt-2.5 space-y-2.5",children:Se.map(i=>e.jsxs("li",{className:"flex gap-2",children:[e.jsx(ce,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-primary"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold text-foreground",children:i.name}),e.jsx("p",{className:"text-[11px] leading-relaxed text-muted-foreground",children:i.detail})]})]},i.name))}),e.jsx("p",{className:"mt-3 rounded-lg border border-border bg-muted/50 p-3 text-[11px] leading-relaxed text-muted-foreground",children:"Putting the visualiser on your own site, a branded store and Image Studio come with a package. You can start a 14-day trial from your dashboard whenever you are ready."})]})]})]})});function Cn({open:n,onOpenChange:l,defaultEmail:u,onSignedIn:c,onGoogle:m,googleLoading:y}
1){const[v,x]=a.useState("signin"),[p,b]=a.useState(u??""),[A,T]=a.useState(""),[S,I]=a.useState(!1),[j,R]=a.useState(null),N=async P=>{P.preventDefault(),R(null),I(!0);try{const{error:C}=await L.auth.signInWithPassword({email:p.trim(),password:A});if(C){R(C.message);return}O.success("Welcome back"),l(!1),c()}finally{I(!1)}},k=async P=>{P.preventDefault(),R(null),I(!0);try{const{error:C}=await L.auth.resetPasswordForEmail(p.trim(),{redirectTo:`${window.location.origin}/reset-password`});if(C){R(C.message);return}O.success("Reset link sent",{description:"Check your inbox for a link to set a new password."}),x("signin")}finally{I(!1)}};return e.jsx($t,{open:n,onOpenChange:l,children:e.jsx(Wt,{className:"sm:max-w-[420px]",children:v==="signin"?e.jsxs(e.Fragment,{children:[e.jsxs(pt,{children:[e.jsx(ft,{children:"Welcome back"}),e.jsx(ht,{children:"Sign in and we will keep everything you have set up so far."})]}),e.jsxs(F,{type:"button",variant:"outline",className:"w-full",onClick:m,disabled:y||S,children:[y?e.jsx(re,{className:"mr-2 h-4 w-4 animate-spin"}):null,"Continue with Google"]}),e.jsxs("div",{className:"flex items-center gap-3 text-[11px] uppercase tracking-wide text-muted-foreground",children:[e.jsx("span",{className:"h-px flex-1 bg-border"}),"or",e.jsx("span",{className:"h-px flex-1 bg-border"})]}),e.jsxs("form",{onSubmit:N,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"wizard-signin-email",children:"Email"}),e.jsx(J,{id:"wizard-signin-email",type:"email",value:p,onChange:P=>b(P.target.value),autoComplete:"email",disabled:S})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-baseline justify-between",children:[e.jsx(W,{htmlFor:"wizard-signin-password",children:"Password"}),e.jsx("button",{type:"button",className:"text-xs text-primary underline",onClick:()=>{R(null),x("forgot")},children:"Forgot your password?"})]}),e.jsx(J,{id:"wizard-signin-password",type:"password",value:A,onChange:P=>T(P.target.value),autoComplete:"current-password",disabled:S})]}),j&&e.jsx("p",{className:"text-sm text-destructive",children:j}),e.jsxs(F,{type:"submit",className:"w-full",disabled:S,children:[S?e.jsx(re,{className:"mr-2 h-4 w-4 animate-spin"}):null,"Log in"]})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs(pt,{children:[e.jsx(ft,{children:"Reset your password"}),e.jsx(ht,{children:"We will email you a link to set a new password. Your setup stays on this page."})]}),e.jsxs("form",{onSubmit:k,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"wizard-reset-email",children:"Email"}),e.jsx(J,{id:"wizard-reset-email",type:"email",value:p,onChange:P=>b(P.target.value),autoComplete:"email",disabled:S})]}),j&&e.jsx("p",{className:"text-sm text-destructive",children:j}),e.jsxs(F,{type:"submit",className:"w-full",disabled:S,children:[S?e.jsx(re,{className:"mr-2 h-4 w-4 animate-spin"}):null,"Send reset link"]}),e.jsx("button",{type:"button",className:"w-full text-xs text-muted-foreground underline",onClick:()=>{R(null),x("signin")},children:"Back to log in"})]})]})})})}function Sn({email:n,verificationRedirectTo:l,verified:u,onVerified:c}){const[m,y]=a.useState(""),[v,x]=a.useState(!1),[p,b]=a.useState(!1),[A,T]=a.useState(null);if(u)return e.jsxs("div",{className:"flex items-center gap-3 border-b border-border bg-primary/5 px-6 py-3",children:[e.jsx(ta,{className:"h-4 w-4 text-primary"}),e.jsx("p",{className:"text-sm text-foreground",children:"Email verified. Everything you set up has been saved to your account."})]});const S=async j=>{j.preventDefault(),T(null),x(!0);try{const{error:R}=await aa(n,m);if(R){T(R.message||"That code did not work. Try again or resend it.");return}O.success("Email verified"),c()}finally{x(!1)}},I=async()=>{T(null),b(!0);try{const{error:j}=await na(n,l);if(j){T(j.message);return}oa()}finally{b(!1)}};return e.jsx("div",{className:"border-b border-border bg-muted/40 px-6 py-4",children:e.jsxs("div",{className:"flex flex-wrap items-start gap-3",children:[e.jsx(ra,{className:"mt-0.5 h-4 w-4 shrink-0 text-primary"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:"Enter your verification code"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["We emailed a code to ",e.jsx("span",{className:"font-medium text-foreground",children:n}),". Type it here to finish without leaving this page."]}),e.jsxs("form",{onSubmit:S,className:"mt-3 flex flex-wrap items-center gap-2",children:[e.jsx(J,{value:m,onChange:j=>y(sa(j.target.value)),inputMode:"numeric",autoFocus:!0,autoComplete:"one-time-code",placeholder:"Verification code",className:"w-44",disabled:v}),e.jsxs(F,{type:"submit",size:"sm",disabled:v||m.trim().length<4,children:[v?e.jsx(re,{className:"mr-2 h-3.5 w-3.5 animate-spin"}):null,"Verify"]}),e.jsx(F,{type:"button",size:"sm",variant:"ghost",onClick:I,disabled:p,children:p?"Sending...":"Resend email"})]}),e.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:"Prefer a link? The same email has one, it opens this page already verified."}),A&&e.jsx("p",{className:"mt-2 text-xs text-destructive",children:A})]})]})})}async function kn(n){const l=`${window.location.origin}${n}`,u=!window.location.hostname.includes("lovable.app")&&!window.location.hostname.includes("lovableproject.com");try{if(u){const{data:m,error:y}=await L.auth.signInWithOAuth({provider:"google",options:{redirectTo:l,skipBrowserRedirect:!0}});if(y)return{error:new Error(y.message)};if(!m?.url)return{error:new Error("Could not start Google sign in.")};const v=new URL(m.url);return v.protocol!=="https:"?{error:new Error("Invalid OAuth redirect URL")}:(window.location.href=v.toString(),{error:null})}const{error:c}=await sn.auth.signInWithOAuth("google",{redirect_uri:l});return c?{error:new Error(c.message||"Could not sign in with Google.")}:{error:null}}catch(c){return{error:c instanceof Error?c:new Error("Could not sign in with Google.")}}}async function as(n,l,u){try{await L.functions.invoke("save-onboarding-draft",{body:{userId:n,email:l,payload:u}})}catch{}}async function Rn(n,l){try{await L.from("onboarding_drafts").upsert({user_id:n,payload:l,updated_at:new Date().toISOString()},{onConflict:"user_id"})}catch{}}async function Pn(){try{const{data:n,error:l}=await L.from("onboarding_drafts").select("payload").maybeSingle();return l||!n?.payload?null:n.payload}catch{return null}}async function En(n){try{await L.from("onboarding_drafts").delete().eq("user_id",n)}catch{}}async function An(n){try{const{data:l,error:u}=await L.functions.invoke("check-email-verified",{body:{email:n}});return u?!1:!!l?.verified}catch{return!1}}function qn({steps:n,currentStep:l,title:u,subject:c,badge:m,onClose:y,railFootnote:v,heading:x,subheading:p,footerLabel:b,footer
1:A,children:T,onStepClick:S}){const{platformName:I,platformLogo:j}=ls(),R=a.useRef({});return a.useEffect(()=>{typeof window>"u"||window.innerWidth>=1024||R.current[l]?.scrollIntoView({inline:"center",block:"nearest",behavior:"smooth"})},[l]),e.jsx("div",{className:"min-h-screen bg-muted/40 px-4 py-6 md:px-6 md:py-10",children:e.jsxs("div",{className:"mx-auto flex w-full max-w-[1240px] flex-col overflow-hidden rounded-2xl border border-border bg-card shadow-xl lg:h-[812px]",children:[e.jsxs("header",{className:"flex flex-none items-center gap-3 border-b border-border px-5 py-4 md:px-6",children:[j?e.jsx("img",{src:j,alt:I,className:"h-6 w-auto max-w-[132px] object-contain",onError:N=>{N.currentTarget.style.display="none"}}):e.jsxs("span",{className:"flex items-center gap-2 font-serif text-base font-semibold text-platform-accent",children:[e.jsx(ia,{className:"h-4 w-4"}),I]}),e.jsx("span",{className:"hidden h-5 w-px bg-border sm:block"}),e.jsx("span",{className:"truncate text-sm text-foreground md:text-[15px]",children:u}),c&&e.jsx("span",{className:"hidden truncate rounded-full bg-muted px-2.5 py-1 text-[11px] font-semibold text-foreground sm:block",children:c}),e.jsx("div",{className:"flex-1"}),m&&e.jsx("span",{className:"hidden text-xs text-muted-foreground md:block",children:m}),y&&e.jsx("button",{type:"button",onClick:y,"aria-label":"Leave setup",className:"rounded-md p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:e.jsx(la,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col lg:flex-row",children:[e.jsxs("nav",{className:"flex-none border-b border-border bg-muted/40 px-5 py-4 lg:w-[262px] lg:overflow-y-auto lg:border-b-0 lg:border-r lg:px-5 lg:py-6",children:[e.jsx("p",{className:"mb-3 text-[10px] font-semibold uppercase tracking-[0.14em] text-muted-foreground",children:"Set up your organisation"}),e.jsx("ol",{className:"flex gap-2 overflow-x-auto lg:block lg:space-y-1 lg:overflow-visible",children:n.map(N=>{const k=l>N.number,P=l===N.number,C=P?N.caption:k?N.doneCaption:null,U=k&&S;return e.jsxs("li",{ref:se=>{R.current[N.number]=se},className:`group flex flex-none items-start gap-3 rounded-lg px-3 py-2.5 lg:w-full transition-all duration-150 ${P?"bg-card shadow-sm":""} ${U?"cursor-pointer hover:bg-primary/10 hover:border-primary/30 hover:shadow-xs active:scale-[0.99]":""}`,onClick:()=>{U&&S(N.number)},children:[e.jsx("span",{className:`mt-0.5 grid h-6 w-6 flex-none place-items-center rounded-full text-[11px] font-semibold ${P?"bg-platform-accent text-white":k?"bg-primary/15 text-primary":"border border-border text-muted-foreground"}`,children:k?e.jsx(ce,{className:"h-3 w-3"}):N.number}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:`block text-[12.5px] font-semibold ${P||k?"text-foreground":"text-muted-foreground"}`,children:N.label}),C&&e.jsx("span",{className:"mt-0.5 hidden truncate text-[10.5px] leading-snug text-muted-foreground lg:block",children:C})]})]},N.number)})}),v&&e.jsx("p",{className:"mt-5 hidden border-t border-border pt-4 text-[11px] leading-relaxed text-muted-foreground lg:block",children:v})]}),e.jsxs("main",{className:"min-h-0 flex-1 overflow-y-auto px-5 py-6 md:px-8 md:py-7",children:[e.jsx("h1",{className:"font-serif text-xl font-semibold tracking-tight text-foreground md:text-2xl",children:x}),p&&e.jsx("p",{className:"mt-2 max-w-2xl text-sm leading-relaxed text-muted-foreground",children:p}),e.jsx("div",{className:"mt-6",children:T})]})]}),e.jsxs("footer",{className:"flex flex-none flex-col gap-3 border-t border-border bg-muted/30 px-5 py-4 sm:flex-row sm:items-center sm:justify-between md:px-6",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:b}),e.jsx("div",{className:"flex items-center justify-end gap-3",children:A})]})]})})}async function Tn(n){if(!n)return"";let l=n;for(let u=1;u<100;u+=1){const{data:c,error:m}=await L.from("stores").select("id").eq("slug",l).is("deleted_at",null).maybeSingle();if(m)return n;if(!c)return l;l=`${n}-${u}`}return`${n}-${Date.now().toString().slice(-4)}`}async function In(n,l){const{data:u,error:c}=await L.from("organization_requests").select("status, org_name, created_at").eq("id",n).eq("requested_by",l).maybeSingle(),m=u;if(c||m?.status!=="approved")return null;const{data:y,error:v}=await L.from("organization_members").select("organizations(id, slug, name, created_at, onboarding_source)").eq("user_id",l).order("created_at",{ascending:!1}),x=y;if(v)return null;const p=Date.parse(m.created_at??""),b=(x??[]).map(A=>A.organizations).flat().find(A=>{if(!A?.id||A.onboarding_source!=="self_serve")return!1;const T=Date.parse(A.created_at??"");return(!Number.isFinite(p)||!Number.isFinite(T)||T>=p-6e4)&&A.name===m.org_name});return b?{id:b.id,slug:b.slug??null}:null}function On({open:n,onOpenChange:l,organizationId:u,organizationName:c,organizationDomain:m,resumePath:y,onSubmitted:v}){const x=ds(),{user:p}=Mt(),{profile:b}=da(),A=nn(),[T,S]=a.useState(""),[I,j]=a.useState(""),[R,N]=a.useState("member"),[k,P]=a.useState("");
1if(a.useEffect(()=>{n&&(b?.full_name&&!T&&S(b.full_name),p?.email&&!I&&j(p.email))},[n,b?.full_name,p?.email]),!p)return e.jsx($t,{open:n,onOpenChange:l,children:e.jsxs(Wt,{children:[e.jsxs(pt,{children:[e.jsx(ft,{children:"Sign in to request access"}),e.jsxs(ht,{children:["You need a ","",c," account to request access. Sign up or sign in, then we'll bring you back to finish your request."]})]}),e.jsxs(Vr,{children:[e.jsx(F,{variant:"outline",onClick:()=>l(!1),children:"Cancel"}),e.jsx(F,{onClick:()=>{const B=y??window.location.pathname+window.location.search;x(`/auth?intent=brand&returnUrl=${encodeURIComponent(B)}`)},children:"Continue to sign in"})]})]})});const C=I.split("@")[1]?.toLowerCase().trim(),U=m?.toLowerCase().trim(),se=!!C&&!!U&&!C.endsWith(U),ae=async B=>{B.preventDefault();const fe=T.trim(),Q=I.trim();if(fe.length<1||fe.length>100){O.error("Please enter your name (1–100 characters).");return}if(!/^[^@\s]+@[^@\s]+\.[^@\s]+$/.test(Q)){O.error("Please enter a valid work email.");return}if(k.length>1e3){O.error("Message is too long (max 1000 characters).");return}try{(await A.mutateAsync({organizationId:u,name:fe,email:Q,role:R,message:k.trim()||void 0}))?.duplicate?O.info(`You already have a pending request to join ${c}.`):O.success(`Request sent. The team at ${c} will review it and you'll be notified.`),v?.(),l(!1)}catch(H){const ne=H?.message??"",V=ne.includes("already_member")?"You're already a member of this organisation.":ne.includes("invalid_email")?"That email address is invalid.":ne.includes("invalid_name")?"Please enter a valid name.":ne.includes("org_not_found")?"That organisation no longer exists.":ne.includes("auth_required")?"Please sign in to continue.":"Couldn't send your request. Please try again.";O.error(V)}};return e.jsx($t,{open:n,onOpenChange:l,children:e.jsxs(Wt,{className:"max-w-md",children:[e.jsxs(pt,{children:[e.jsxs(ft,{children:["Request access to ",c]}),e.jsxs(ht,{children:["We'll send your request to the team at ",c,". They'll approve or decline it and you'll be notified by email and in your inbox."]})]}),e.jsxs("form",{onSubmit:ae,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"ra-name",children:"Your name"}),e.jsx(J,{id:"ra-name",value:T,onChange:B=>S(B.target.value),required:!0,maxLength:100})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"ra-email",children:"Work email"}),e.jsx(J,{id:"ra-email",type:"email",value:I,onChange:B=>j(B.target.value),required:!0,maxLength:255}),se&&e.jsxs("p",{className:"text-xs text-amber-600",children:["This email isn't on the ",e.jsx("span",{className:"font-medium",children:U})," domain. The team may decline if they can't verify you."]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{children:"Role you're requesting"}),e.jsxs(ca,{value:R,onValueChange:B=>N(B),className:"flex gap-4",children:[e.jsxs("label",{className:"flex items-center gap-2 text-sm cursor-pointer",children:[e.jsx(zr,{value:"member"})," Member"]}),e.jsxs("label",{className:"flex items-center gap-2 text-sm cursor-pointer",children:[e.jsx(zr,{value:"admin"})," Admin"]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(W,{htmlFor:"ra-message",children:["Message ",e.jsx("span",{className:"text-muted-foreground text-xs",children:"(optional)"})]}),e.jsx(is,{id:"ra-message",value:k,onChange:B=>P(B.target.value),placeholder:"Tell them who you are and why you need access (e.g. 'I'm the marketing manager — please add me').",rows:4,maxLength:1e3}),e.jsxs("p",{className:"text-xs text-muted-foreground text-right",children:[k.length,"/1000"]})]}),e.jsxs(Vr,{children:[e.jsx(F,{type:"button",variant:"outline",onClick:()=>l(!1),children:"Cancel"}),e.jsxs(F,{type:"submit",disabled:A.isPending,children:[A.isPending&&e.jsx(re,{className:"mr-2 h-4 w-4 animate-spin"}),"Send request"]})]})]})]})})}const Dn=[{slot:"reversed",tokens:["reverse","reversed","white","light","mono","inverted","inverse","dark-bg","onblack"]},{slot:"icon",tokens:["icon","mark","favicon","symbol","glyph","badge","avatar","apple-touch"]},{slot:"horizontal",tokens:["horizontal","landscape","wide","lockup-
1h","inline"]},{slot:"stacked",tokens:["stacked","vertical","portrait","lockup-v"]}];function Ln(n){try{return decodeURIComponent(new URL(n).pathname).toLowerCase()}catch{return n.toLowerCase()}}function Fn(n){const l=Ln(n);for(const u of Dn)if(u.tokens.some(c=>l.includes(c)))return u.slot;return null}function ns(n,l={}){const u={},c=new Set;return n.forEach(m=>{const y=(l[m]??"").toLowerCase(),v=Fn(m)??(y.includes("icon")?"icon":null);v&&!c.has(v)&&(u[m]=v,c.add(v))}),u}function os(n,l,u,c=[]){const m={...n},y=new Set(Object.values(m));u&&y.add("master");for(const[v,x]of Object.entries(l))!v||!x||v===u||c.includes(v)||m[v]||y.has(x)||x==="master"||(m[v]=x,y.add(x));return m}function Un(n,l={}){const u=c=>{const m=(l[c]??"").toLowerCase(),y=c.toLowerCase();return m.includes("apple-touch")||m.includes("favicon")||m==="link-icon"||/apple-touch|favicon|pinned-tab|mstile/.test(y)};return n.find(c=>!u(c))??n[0]??""}const Bn="__new__";function $n(n){return n.toLowerCase().trim().replace(/&/g,"and").replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,48)}function Wn(n,l,u){const c=x=>typeof n?.[x]=="string"?n[x]:null,m=l?.primaryColor??c("primary")??u.primaryColor??null,y=[c("accent"),c("background"),c("text"),u.accentColor].filter(x=>!!x),v=y.find(x=>{const p=dn(m,x);return p===null||p>=45});return{primaryColor:m,accentColor:l?.accentColor??v??y[0]??null,backgroundColor:l?.backgroundColor??c("background"),textColor:l?.textColor??c("text")}}const Yn=[{number:1,label:"Website",caption:"Your web address"},{number:2,label:"Brand",caption:"Name, logo, colour",doneCaption:"Logo and colour set"},{number:3,label:"Products",caption:"Your catalogue"},{number:4,label:"Check products",caption:"Images, names, categories",doneCaption:"Checked"},{number:5,label:"Preview organisation",caption:"How your brand looks",doneCaption:"Seen"},{number:6,label:"Account",caption:"Email and password"},{number:7,label:"Build",caption:"Building organisation"}],Mn={1:"Your progress is kept in this browser for 24 hours, on this device. Nothing is saved to us until you create your account.",2:"Fonts, voice and imagery were read from your site and saved with your organisation. You can refine them later.",3:"Products stay yours. Remove or edit any of them from your dashboard at any time.",4:"What you choose here is what gets created. Anything left blank is filled in for you afterwards.",5:"This is a starting point. Every colour, logo and word can be changed from your dashboard.",6:"Your setup is saved to this account the moment it is created.",7:"This takes a few seconds. Stay here and we will open your dashboard for you."};function Wo(){const{user:n,loading:l}=Mt(),{currentOrg:u,loading:c,organizations:m}=ua(),{refreshRoles:y,applyRole:v,roles:x}=ma(),p=ds(),[b]=ga(),A=pa(b),[T,S]=a.useState(""),[I,j]=a.useState(0),[R,N]=a.useState(null),k=A.planSlug||T,P=A.extraCreditsPerMonth??I,C=A.billingFrequency??R,U=t=>k?ba(k,{extraCreditsPerMonth:P,billingFrequency:C}):t?.welcome?"/org/dashboard?welcome=1":"/org/dashboard",{categories:se}=fa(),{platformName:ae}=ls();Ba();const{trackEvent:B}=$a(),{data:fe=[]}=an(),Q=!0,H=a.useRef(!1),ne=a.useRef(!1),[V,Ce]=a.useState(!1),[Re,Te]=a.useState(null),[ie,Se]=a.useState(null),ue=async(t,o)=>{try{(await y()).includes("org_member")&&v("org_member")}catch{}p(t,o)};a.useEffect(()=>{if(V||!n||c)return;(u?.id||m&&m.length>0||x.includes("org_member"))&&(We(),Gr(),ue(U(),{replace:!0}))},[n,c,u?.id,m?.length,x,p,V,k,P,C]);const[i,q]=a.useState(1),K=a.useRef(""),[Y,Vt]=a.useState(""),[xt,ke]=a.useState(!1),[Ie,zt]=a.useState(!1),[Me,Gt]=a.useState(!1),[Ve,yt]=a.useState(!1),[Vn,cs]=a.useState(null),[us,me]=a.useState(null),[ms,bt]=a.useState([]),[gs,Oe]=a.useState(!1),[oe,_t]=a.useState([]),[we,wt]=a.useState(null),[Ht,Kt]=a.useState(!1),[Pe,Jt]=a.useState(null),[ps,vt]=a.useState(null),[Qt,Xt]=a.useState(null),[fs,hs]=a.useState(ka),jt=a.useRef([]),Zt=a.useRef(null),De=a.useRef(null),er=a.useRef(null),[ze,tr]=a.useState(""),[ee,Nt]=a.useState(""),[Ge,rr]=a.useState(!1),[sr,ar]=a.useState(!1),[xs,He]=a.useState(!1),[nr,or]=a.useState(!1),[ys,Ke]=a.useState(!1),Ct=a.useRef(null),ir=a.useRef(null),St=a.useRef(!1),[zn,Gn]=a.useState(!1),[lr,Hn]=a.use
1State(null),[bs,dr]=a.useState(!1),cr=a.useRef(null),kt=a.useRef(""),ur=a.useRef(!1);a.useEffect(()=>{ur.current||n&&c||u?.id||(ur.current=!0,B({event_name:"onboarding_started",event_params:{flow_version:"v2",source_url:window.location.href}}).catch(()=>{}))},[B,Q,n,c,u?.id]);const _s=async t=>{const o=t.target.files?.[0];if(t.target&&(t.target.value=""),!!o){if(!["image/png","image/jpeg","image/webp","image/svg+xml"].includes(o.type)){O.error("Please upload a PNG, JPG, WebP or SVG file");return}if(o.size>5*1024*1024){O.error("Logo must be smaller than 5MB");return}dr(!0);try{const s=(o.name.split(".").pop()||"png").toLowerCase(),d=`org-request-logos/${Date.now()}-${Math.random().toString(36).slice(2,8)}.${s}`,{error:f}=await L.storage.from("media").upload(`brand-products/${d}`,o,{contentType:o.type,upsert:!1});if(f)throw f;const{data:h}=L.storage.from("media").getPublicUrl(`brand-products/${d}`),M=kt.current;kt.current="",M===Bn?Xe($=>[...$,h.publicUrl]):M?(Xe($=>$.map(w=>w===M?h.publicUrl:w)),At($=>{if(!$[M])return $;const w={...$};return w[h.publicUrl]=w[M],delete w[M],w}),r.org_logo_url===M&&D($=>({...$,org_logo_url:h.publicUrl}))):D($=>({...$,org_logo_url:h.publicUrl})),O.success("Logo uploaded")}catch(s){console.error("[RequestOrganization] Logo upload failed",s),O.error("Failed to upload logo. Please try again.")}finally{dr(!1)}}},[r,D]=a.useState({org_name:"",org_description:"",org_logo_url:"",website_url:"",primary_category_id:null,primary_category_other:"",selected_category_ids:[],product_urls:[""],address_line_1:"",address_line_2:"",address_city:"",address_county:"",address_postcode:"",address_country_code:"",contact_phone:"",vat_number:"",business_type:"both",initial_brand_name:"",initial_store_name:"",requested_brands_count:1,products_count:25,requested_stores_count:1,requested_product_types:[],other_product_types_description:"",wants_configurator:!1,wants_image_studio:!1,wants_qr:!1,wants_shopify:!1}),{detectedCountry:mr,loading:gr}=Ya();a.useEffect(()=>{if(gr)return;const t=Ye(mr);t&&D(o=>o.address_country_code?o:{...o,address_country_code:t})},[gr,mr]),Ye(r.address_country_code);const X=r.business_type==="brand"||r.business_type==="both",Z=r.business_type==="retailer"||r.business_type==="both",pr=se.filter(t=>t.is_active&&t.name.toLowerCase()!=="other");a.useEffect(()=>{r.business_type==="retailer"?(D(t=>({...t,requested_brands_count:0,requested_product_types:[],products_count:25,other_product_types_description:"",initial_brand_name:"",requested_stores_count:t.requested_stores_count||1})),zt(!1)):r.business_type==="brand"?D(t=>({...t,requested_stores_count:0,requested_brands_count:t.requested_brands_count||1,initial_store_name:""})):r.business_type==="both"&&D(t=>({...t,requested_brands_count:t.requested_brands_count||1,requested_stores_count:t.requested_stores_count||1}))},[r.business_type]),a.useEffect(()=>{const t=r.org_name.trim();t&&D(o=>{const s={...o};if(!Me&&(X||o.business_type==="both")&&(!o.initial_brand_name||o.initial_brand_name===o.initial_store_name?.replace(/ Visualiser$/,""))&&(s.initial_brand_name=t),!Ve&&(Z||o.business_type==="both")){const d=`${t} Visualiser`;o.initial_store_name||(s.initial_store_name=d)}return s})},[r.org_name,r.business_type,Me,Ve]),a.useEffect(()=>{const t=$n(r.initial_store_name||r.org_name);if(!t){Vt("");return}let o=!0;const s=window.setTimeout(()=>{Tn(t).then(d=>{o&&Vt(d)})},250);return()=>{o=!1,window.clearTimeout(s)}},[r.initial_store_name,r.org_name]);const ws=()=>{D(t=>{const o=t.business_type==="brand"||t.business_type==="both",s=t.business_type==="retailer"||t.business_type==="both",d=!o;return!d&&!s?t:{...t,business_type:d&&s?"both":d?"brand":"retailer"}})},vs=()=>{D(t=>{const o=t.business_type==="brand"||t.business_type==="both",d=!(t.business_type==="retailer"||t.business_type==="both");return!d&&!o?t:{...t,business_type:o&&d?"both":d?"retailer":"brand"}})},Je=b.get("seed")==="session",{loading:fr,seed:Rt,data:le,ready:hr,seedRowId:xr}=gn(Je),[yr,js]=a.useState(!1);a.useEffect(()=>{!hr||!le||yr||(D(t=>{const o={...t};if(le.websiteUrl&&!t.website_url&&(o.website_url=le.websiteUrl),le.brandName&&(t.org_name||(o.org_name=le.brandName),t.initial_brand_name||(o.initial_brand_name=le.brandName)),le.productCategory&&t.selected_category_ids.length===0){const s=le.productCategory.toLowerCase().trim(),d=pr.find(f=>f.name.toLowerCase()===s||f.name.toLowerCase().includes(s)||s.includes(f.name.toLowerCase())||(f.types||[]).some(h=>h.name.toLowerCase().includes(s)));d&&(o.selected_category_ids=[d.id])}return o}
1),js(!0))},[hr,le,yr,pr]);const br=a.useMemo(()=>Rt?Rt.kind==="url"?"product URL":"product image":null,[Rt]);a.useEffect(()=>{Ie||D(t=>({...t,other_product_types_description:""}))},[Ie]);const[Qe,Pt]=a.useState(!1),[Ns,Et]=a.useState(null),[Cs,_r]=a.useState(!1),[ve,Xe]=a.useState([]),[Le,wr]=a.useState({}),[Fe,vr]=a.useState([]),[Ue,Ss]=a.useState([]),[Ze,At]=a.useState({}),ks=a.useMemo(()=>ns(ve,Le),[ve,Le]),[he,jr]=a.useState(null),[Rs,Nr]=a.useState(!1),[g,et]=a.useState(null),[z,Ee]=a.useState(null),[Ps,Cr]=a.useState(!1),[Es,Sr]=a.useState(!1),{data:tt,refetch:As}=on(z?.status==="live"?z.organizationId??null:null),rt=async t=>{const o=te(t);if(!o||!o.includes("."))return Ee(null),null;Cr(!0);try{const{data:s,error:d}=await L.rpc("check_organisation_url_taken",{_domain:o});if(d)return Ee(null),null;const f=s??{},h={status:f.status??"available",orgName:f.org_name,organizationId:f.organization_id,domain:o};return Ee(h),h}catch{return Ee(null),null}finally{Cr(!1)}},qt=z?.status==="live"||z?.status==="pending",st=async t=>{const o=Jr(t);if(!o){Et("That does not look like a web address. Try something like example.co.uk.");return}Et(null),Pt(!0),_r(!1);const s=await rt(o);if(s?.status==="live"||s?.status==="pending"){K.current=te(o),Pt(!1);return}try{const{data:d,error:f}=await L.functions.invoke("scrape-organisation-page",{body:{url:o}});if(f){Et("We could not read that site. Check the address, or carry on and fill your details in by hand.");return}K.current=te(o);const h=d??{},M=Jr(h.finalUrl??""),$=M&&te(M)!==te(o)?await rt(M):null,w=[s,$].find(_=>_?.status==="live"||_?.status==="pending");if(w){Ee(w);return}const ge=(h.logoCandidates??[]).map(_=>_?.url).filter(_=>typeof _=="string"&&/^https?:\/\//i.test(_)),_e=h.logoUrl&&/^https?:\/\//i.test(h.logoUrl)?h.logoUrl:ge[0]??null;vr([]);const Ae=Object.fromEntries((h.logoCandidates??[]).filter(_=>_?.url&&_?.source).map(_=>[_.url,_.source])),qe=Array.from(new Set([..._e?[_e]:[],...ge])),$e=Un(qe,Ae)||_e;Xe(qe),wr(Ae),At(_=>os(_,ns(qe,Ae),$e??""));const G=h.address??{},ut=Ye(G.countryCode??"");D(_=>({..._,org_name:_.org_name.trim()?_.org_name:h.name??_.org_name,org_description:_.org_description.trim()?_.org_description:h.description??_.org_description,org_logo_url:_.org_logo_url||($e??_e??""),address_line_1:_.address_line_1.trim()?_.address_line_1:G.line1??"",address_line_2:_.address_line_2.trim()?_.address_line_2:G.line2??"",address_city:_.address_city.trim()?_.address_city:G.city??"",address_county:_.address_county.trim()?_.address_county:G.county??"",address_postcode:_.address_postcode.trim()?_.address_postcode:G.postcode??"",address_country_code:H.current?_.address_country_code:ut||_.address_country_code,contact_phone:_.contact_phone.trim()?_.contact_phone:h.phone??""})),_r(!h.email&&!h.phone&&!G.line1),et({tagline:h.tagline||void 0,description:h.description||void 0,primaryColor:h.primaryColor??null,accentColor:h.accentColor??null,contactEmail:h.email||void 0,contactPhone:h.phone||void 0,address:G.line1||G.city||G.postcode?{line1:G.line1??null,line2:G.line2??null,city:G.city??null,county:G.county??null,postcode:G.postcode??null,countryCode:ut||null}:void 0}),(h.name||_e||h.primaryColor)&&!w&&(ne.current||(ne.current=!0,q(_=>_===1?2:_))),B({event_name:"onboarding_scraped",event_params:{flow_version:Q?"v2":"v1",website_url:o,scraped_name:h.name??"",scraped_logo:_e?"yes":"no",logo_candidates_count:ge.length,scraped_colours:h.primaryColor||h.accentColor?"yes":"no"}}).catch(()=>{});try{Nr(!0);const{data:_,error:mt}=await L.functions.invoke("brand-kit-from-url",{body:{url:o}});if(!mt&&_){const pe=_,de=pe.kit&&typeof pe.kit=="object"?{...pe.kit}:void 0,E=(pe.image_candidates??[]).map(ye=>ye.url).filter(ye=>typeof ye=="string").slice(0,8).map(ye=>({url:ye}));de&&E.length&&!Array.isArray(de.imagery)&&(de.imagery=E),jr({kit:de,design_md:typeof pe.design_md=="string"&&pe.design_md.trim()?pe.design_md:void 0});const xe=de?.colors&&typeof de.colors=="object"?de.colors:null;et(ye=>({...ye??{},...Wn(xe,ye,h)}))}}catch{}finally{Nr(!1)}}catch{}finally{Pt(!1)}},kr=()=>{const t=te(r.website_url);t&&t===K.current||(st(r.website_url),rt(r.website_url))},[Rr,qs]=a.useState(!1);a.useEffect(()=>{if(Rr)return;const t=b.get("url"),o=b.get("autoscrape")==="1";!t||!o||(qs(!0),D(s=>s.website_url?s:{...s,website_url:t}
1),st(t))},[b,Rr]);const Ts=()=>{if(!r.website_url.trim())return O.error("Please enter your website address"),!1;try{if(!new URL(r.website_url.startsWith("http")?r.website_url:`https://${r.website_url}`).hostname.includes("."))throw new Error("Invalid hostname")}catch{return O.error("Please enter a valid website address, for example yourcompany.com"),!1}return qt?(O.error(z?.status==="live"?`${z.orgName??"This organisation"} already has an account on ${ae}.`:"There's already an application in review for this website."),!1):!0},Is=()=>r.org_name.trim()?Ye(r.address_country_code)?!X&&!Z?(O.error("Please choose Brand, Retailer, or both"),!1):X&&!r.initial_brand_name.trim()?(O.error("Brand name is required"),!1):Z&&!r.initial_store_name.trim()?(O.error("Store name is required"),!1):!0:(O.error("Please choose the country your business is registered in"),!1):(O.error("Organisation name is required"),!1),Be=7,je=fr||Qe,at=r.product_urls.map(t=>t.trim()).filter(t=>t.length>0).slice(0,10),Ne=at.length,nt=t=>{const o=Qa(),s=es(oe).map(f=>({name:f.name||"Untitled product",imageUrl:f.imageUrl||null,categoryId:f.categoryId,typeId:f.typeId,externalUrl:f.url})),d=o?.products?.some(f=>f.id);Xa({storeName:r.initial_store_name||r.org_name||"Your store",logoUrl:r.org_logo_url||null,primaryColor:g?.primaryColor??null,accentColor:g?.accentColor??null,backgroundColor:g?.backgroundColor??null,headerTextColor:g?.textColor??null,products:t&&t.length>0?t:d?o.products:s})},Pr=t=>{const o=es(t);if(o.length===0)return;const s=_a();wt(s),Kt(!0),o[0].name&&vt(o[0].name),nt(),Za(t).then(d=>{d&&(d.sessionToken&&wt(d.sessionToken),d.productName&&vt(d.productName),d.aiImageStatus&&Xt(d.aiImageStatus),d.imagePhotoModeUrl&&Jt(d.imagePhotoModeUrl),d.products.length>0&&nt(d.products))})},Er=()=>{if(!(i===1&&!Ts())&&!(i===2&&!Is())){if(i===2&&B({event_name:"onboarding_reviewed",event_params:{flow_version:"v2",business_type:r.business_type||"",wants_brand:String(X),wants_store:String(Z)}}).catch(()=>{}),i===3&&Ne===0){_t([]),q(5),window.scrollTo({top:0,behavior:"smooth"});return}if(i===4){if(oe.some(t=>t.status==="reading"||t.status==="pending"))return;Pr(oe)}q(t=>Math.min(t+1,Be)),window.scrollTo({top:0,behavior:"smooth"})}},Os=()=>{q(t=>t===5&&Ne===0?3:Math.max(t-1,1)),window.scrollTo({top:0,behavior:"smooth"})};a.useEffect(()=>{const t=window.requestAnimationFrame(()=>{window.scrollTo({top:0,behavior:"auto"}),document.scrollingElement?.scrollTo?.({top:0,behavior:"auto"})});return()=>window.cancelAnimationFrame(t)},[i]);const Ds=(t,o)=>{try{Qr(JSON.stringify({formData:r,scrapedExtras:g,scrapedBrandKit:he,otherSelected:Ie,discoveryCallRequested:t,resumeStep:o,logoCandidates:ve,logoSources:Le,logoVariantAssignments:Ze,discardedLogoUrls:Ue,selectedPlanSlug:k||void 0,extraCreditsPerMonth:P||void 0,billingFrequency:C||void 0,savedAt:new Date().toISOString()}))}catch{}const s=new URLSearchParams({resume:"1"});Je&&s.set("seed","session"),Hr(s,{planSlug:k,extraCreditsPerMonth:P,billingFrequency:C});const d=`/request-organization?${s.toString()}`;p(`/auth?intent=brand&seed=org&returnUrl=${encodeURIComponent(d)}`)},Tt=new URLSearchParams({resume:"1",step:"7",verified:"1"});Je&&Tt.set("seed","session"),Hr(Tt,{planSlug:k,extraCreditsPerMonth:P,billingFrequency:C});const ot=`/request-organization?${Tt.toString()}`,Ar=t=>({formData:r,scrapedExtras:g,scrapedBrandKit:he,otherSelected:Ie,accountFullName:ze,accountEmail:ee,resumeStep:t,logoCandidates:ve,logoSources:Le,logoVariantAssignments:Ze,discardedLogoUrls:Ue,reviewedProducts:oe,earlySessionToken:we,createdRequestId:De.current,accountCreated:St.current,selectedPlanSlug:k||void 0,extraCreditsPerMonth:P||void 0,billingFrequency:C||void 0,savedAt:new Date().toISOString()}),It=t=>{const o=Ar(t);try{Qr(JSON.stringify(o))}catch{}n?.id?Rn(n.id,o):Ct.current&&ee.trim()&&as(Ct.current,ee,o)};a.useEffect(()=>{if(!Tr.current||!Ir.current&&i===1&&!r.website_url.trim()&&!r.org_name.trim())return;const o=window.setTimeout(()=>It(i),600);return()=>window.clearTimeout(o)},[Q,i,r,ze,ee,g,ve,Ze,Ue,oe,we]),a.useEffect(()=>{i<5||Ht||Pr(oe)},[i,Ht]),a.useEffect(()=>{if(!we||Pe)return;let t=!1;const o=async()=>{const d=await en(we);t||(d.productName&&vt(d.productName),d.aiImageStatus&&Xt(d.aiImageStatus),d.imagePhotoModeUrl&&Jt(d.imagePhotoModeUrl),d.products.length>0&&nt(d.products))};o();const s=window.setInterval(()=>{o()},4e3);return()=>{t=!0,window.clearInterval(s)}},[we,Pe]),a.useEffect(()=>{i<5||nt()},[i,r.initial_store_name,r.org_name,r.org_logo_url,g,oe]),a.useEffect(()=>{i===6&&!ee&&g?.contactEmail&&Nt(g.contactEmail)},[Q,i,g]);const Ls=async t=>{rr(!0);try{ir.current=t,It(7);const o=`${window.location.origin}${ot}`,{data:s,error:d}=await wa({email:ee,password:t,options:{emailRedirectTo:o,data:{full_name:ze,[ja]:"organisation",[va]:ot}}});if(d){if(/already/i.test(d.message??"")){const{error:f}=await L.auth.signInWithPassword({email:ee.trim(),password:t});if(!f){St.current=!0,or(!0),q(7),window.scrollTo({top:0,behavior:"smooth"});return}O.error("This email is already registered",{description:"Log in with that address instead and your setup will be saved to it."}),He(!0);return}O.error("Could not create your account",{description:d.message});return}if(St.current=!0,s.user?.id){Ct.current=s.user.id;const f=we||Ut();f&&L.rpc("attach_session_scoped_products_to_user",{_session_token:f,_user_id:s.user.id,_ttl_days:30}),as(s.user.id,ee,Ar(7))}or(!0),q(7),window.scrollTo({top:0,behavior:"smooth"}),O.success("Account created",{description:`Check ${ee.trim()} for the verification code, or click the link in the email.`})}finally{rr(!1)}},qr=async()=>{ar(!0),It(5);const{error:t}=await kn(ot);t&&(O.error("Sign in failed",{description:t.message}),ar(!1))}
1,[it,Fs]=a.useState(!1),Tr=a.useRef(!1),Ir=a.useRef(!1),[Us,lt]=a.useState(!1),[Ot,Bs]=a.useState(null),[Dt,Or]=a.useState(null),Dr=a.useRef(!1),[Lt,Ft]=a.useState(null),dt=(t,o)=>{const s=JSON.parse(t);if(Ir.current=!0,s.formData){const f={...s.formData};f.address_country_code&&(f.address_country_code=Ye(f.address_country_code)??f.address_country_code,H.current=!0),D(h=>({...h,...f}))}s.scrapedExtras&&et(s.scrapedExtras),s.scrapedBrandKit&&jr(s.scrapedBrandKit),typeof s.otherSelected=="boolean"&&zt(s.otherSelected),typeof s.discoveryCallRequested=="boolean"&&cs(s.discoveryCallRequested?"call":"self-service"),s.accountFullName&&tr(s.accountFullName),s.accountEmail&&Nt(s.accountEmail),Array.isArray(s.logoCandidates)&&Xe(s.logoCandidates),s.logoSources&&typeof s.logoSources=="object"&&wr(s.logoSources),s.logoVariantAssignments&&typeof s.logoVariantAssignments=="object"&&At(s.logoVariantAssignments),Array.isArray(s.discardedLogoUrls)&&Ss(s.discardedLogoUrls),Array.isArray(s.reviewedProducts)&&_t(s.reviewedProducts),typeof s.earlySessionToken=="string"&&s.earlySessionToken&&(wt(s.earlySessionToken),Kt(!0)),s.createdRequestId&&(De.current=s.createdRequestId),typeof s.selectedPlanSlug=="string"&&s.selectedPlanSlug.trim()&&S(s.selectedPlanSlug.trim()),typeof s.extraCreditsPerMonth=="number"&&j(s.extraCreditsPerMonth),(s.billingFrequency==="monthly"||s.billingFrequency==="yearly")&&N(s.billingFrequency);const d=Number(b.get("step"));o&&Number.isFinite(d)&&d>=1?q(Math.min(Math.max(d,1),Be)):typeof s.resumeStep=="number"?q(Math.min(Math.max(s.resumeStep,1),Be)):o&&(q(7),Or(s.discoveryCallRequested===!0))};a.useEffect(()=>{if(it||l)return;let t=!1;return(async()=>{try{const s=b.get("resume")==="1"||b.get("verified")==="1";if(!s&&(!!b.get("url")||b.get("autoscrape")==="1")){We();return}const f=Na();if(f){let h=!1;try{h=JSON.parse(f).accountCreated===!0}catch{}if(!s&&!h){Ft(f);return}dt(f,s);return}if(n?.id){const h=await Pn();if(t)return;if(h){if(Bs(h),b.get("verified")==="1"){lt(!0);return}dt(JSON.stringify(h),s);return}}b.get("verified")==="1"&&lt(!0)}catch{}finally{t||(Fs(!0),Tr.current=!0)}})(),()=>{t=!0}},[b,it,l,n?.id]);const Lr=async t=>{if(Zt.current){ke(!0);try{await ue(U({welcome:!0}))}finally{ke(!1),me(null)}return}if(De.current&&n?.id){const d=De.current;ke(!0),Oe(!1),me("Checking your setup…");let f=await ct(d,4);if(!f){me("Finishing your setup…");try{const{data:h,error:M}=await L.functions.invoke("approve-org-request",{body:{requestId:d,decision:"approve",mode:"self_approve",signupChoice:"save"}}),$=h;if(!M&&$&&$.success!==!1){const w=$.organization;f=w?.id&&w?.slug?{id:w.id,slug:w.slug}:await ct(d,4)}}catch(h){console.warn("[RequestOrganization] retry of self-approve failed",h)}f||(f=await ct(d,4))}f?await Fr(f):(Oe(!0),me("We could not confirm completion yet. Your setup is safe, check again in a moment.")),ke(!1);return}const o=r.org_name.trim()||te(r.website_url)||"";if(!o){ke(!1),me(null),O.error("We lost your setup details",{description:"Your organisation name is missing, so nothing has been saved. Start again from the website step."}),q(1);return}const s=await rt(r.website_url);if(s&&(s.status==="live"||s.status==="pending")){O.error(s.status==="live"?`${s.orgName??"This organisation"} already has an account on ${ae}.`:"There's already an application in review for this website.");return}if(!n){Ds(t);return}ke(!0),me("Creating your organisation…");try{const{data:d}=await L.from("user_profiles").select("full_name").eq("user_id",n.id).maybeSingle(),f=X?Math.max(0,r.products_count||0):0,h=f<=25?"1-25":f<=100?"26-100":f<=500?"101-500":"500+",M=Array.from(new Set(oe.map(E=>E.categoryId).filter(E=>!!E))),$=M.map(E=>se.find(xe=>xe.id===E)?.name).filter(E=>!!E),w={},ge=g?.contactPhone?.trim()||"";(r.contact_phone.trim()||ge)&&(w.contact_phone=r.contact_phone.trim()||ge),ge&&ge!==r.contact_phone.trim()&&(w.scraped_phone=ge),g?.address&&(g.address.line1||g.address.postcode)&&(w.scraped_address=g.address),r.vat_number.trim()&&(w.vat_number=r.vat_number.trim()),r.initial_brand_name.trim()&&(w.initial_brand_name=r.initial_brand_name.trim()),r.initial_store_name.trim()&&(w.initial_store_name=r.initial_store_name.trim()),r.org_logo_url.trim()&&(w.org_logo_url=r.org_logo_url.trim());const _e=ve.filter(E=>!Fe.includes(E)&&E!==r.org_logo_url.trim()).slice(0,5);_e.length&&(w.org_logo_candidates=_e),g?.tagline&&(w.org_tagline=g.tagline),r.org_description.trim()&&(w.org_description=r.org_description.trim()),g?.primaryColor&&(w.primary_color=g.primaryColor),g?.accentColor&&(w.accent_color=g.accentColor),g?.textColor&&(w.header_text_color=g.textColor),g?.contactEmail&&(w.scraped_contact_email=g.contactEmail),g?.contactPhone&&(w.scraped_phone=g.contactPhone,w.contact_phone||(w.contact_phone=g.contactPhone)),g?.address&&(w.scraped_address=g.address);const Ae=M[0]??r.primary_category_id;Ae&&(w.primary_category_id=Ae),r.primary_category_other.trim()&&(w.primary_category_other=r.primary_category_other.trim()),at.length&&(w.product_urls=at);const qe=oe.filter(E=>E.url.trim().length>0).slice(0,10).map(E=>({url:E.url.trim(),name:E.name.trim()||null,category_id:E.categoryId,type_id:E.typeId,image_url:E.imageUrl,product_dimensions:E.productDimensions,pattern_dimensions:E.patternDimensions}));qe.length&&(w.product_seeds=qe);const $e=we||Ut();$e&&(w.early_session_token=$e),he&&(he.kit&&(w.brand_kit={...he.kit,colors:{...he.kit.colors??{},...g?.primaryColor?{primary:g.primaryColor}:{},...g?.accentColor?{accent:g.accentColor}:{},...g?.backgroundColor?{background:g.backgroundColor}:{},...g?.textColor?{text:g.textColor}:{}}}),he.design_md&&(w.design_md=he.design_md));const G={}
1,ut=os(Ze,ks,r.org_logo_url.trim(),[...Ue,...Fe]);if(Object.entries(ut).forEach(([E,xe])=>{!Fe.includes(E)&&E!==r.org_logo_url.trim()&&(G[xe]=E)}),Object.keys(G).length){const E=w.brand_kit??{};w.brand_kit={...E,logo_variants_purpose:{...E.logo_variants_purpose??{},...G}}}w.agreed_to_terms_at=new Date().toISOString(),w.wizard_answers={additional_brands:X?Math.max(0,(r.requested_brands_count||1)-1):0,additional_stores:Z?Math.max(0,(r.requested_stores_count||1)-1):0,products_band:X?h:null,requested_products_count:f,seeded_products_qty:f,wants_configurator:X?r.wants_configurator:!1,wants_image_studio:r.wants_image_studio,wants_qr:r.wants_qr,wants_shopify:r.wants_shopify,onboarding_v2_choice:"save"};const{data:_,error:mt}=await L.from("organization_requests").insert({requested_by:n.id,requester_email:n.email,requester_name:d?.full_name||"Unknown",org_name:o,org_description:r.org_description||null,website_url:r.website_url,business_type:r.business_type,status:"pending",requested_brands_count:X?r.requested_brands_count:0,requested_stores_count:Z?r.requested_stores_count:0,requested_product_types:X?$:[],requested_products_count:f,other_product_types_description:Ie?r.other_product_types_description:null,discovery_call_requested:t,discovery_call_availability:null,address_line_1:r.address_line_1.trim()||g?.address?.line1||null,address_line_2:r.address_line_2.trim()||g?.address?.line2||null,address_city:r.address_city.trim()||g?.address?.city||null,address_county:r.address_county.trim()||g?.address?.county||null,address_postcode:r.address_postcode.trim()||g?.address?.postcode||null,address_country_code:r.address_country_code||g?.address?.countryCode||null,pre_approved_config:w}).select().maybeSingle();if(mt)throw mt;_?.id&&(De.current=_.id),xr&&_?.id&&await Ca(xr,_.id);try{const E=we||Ut();E&&await L.rpc("attach_session_scoped_products_to_user",{_session_token:E,_user_id:n.id,_ttl_days:30})}catch(E){console.warn("[RequestOrganization] attach_session_scoped_products_to_user failed",E)}try{localStorage.setItem("reydar_welcome_seen","true")}catch{}let pe=!1,de=null;try{const E=L.functions.invoke("approve-org-request",{body:{requestId:_.id,decision:"approve",mode:"self_approve",signupChoice:"save"}}),xe=new Promise((Kn,Gs)=>{window.setTimeout(()=>Gs(new Error("Organisation setup is taking longer than expected")),2e4)}),{data:ye,error:Yr}=await Promise.race([E,xe]);if(de=ye,Yr)throw Yr;de&&de.success!==!1&&(pe=!0)}catch(E){console.warn("[RequestOrganization] self-approve reply missing, checking for the organisation",E),me("Still setting things up. We are checking for completion…");const xe=await ct(_.id);xe&&(de={organization:xe},pe=!0)}if(pe){await Fr(de?.organization??null);return}Oe(!0),me("We could not confirm completion yet. Your setup is safe, check again in a moment.")}catch(d){console.error("Error submitting request:",d),me(null),O.error(d instanceof Error?d.message:"Failed to submit request")}finally{jt.current.forEach(d=>window.clearTimeout(d)),jt.current=[],ke(!1)}},$s=async()=>{if(!n?.id)return;const t=oe.flatMap(s=>[...s.requestedCategoryName?[{requestType:"category",name:s.requestedCategoryName}]:[],...s.requestedTypeName?[{requestType:"type",name:s.requestedTypeName,categoryId:s.categoryId??void 0}]:[]]),o=Array.from(new Map(t.map(s=>[`${s.requestType}:${s.categoryId??""}:${s.name.toLowerCase()}`,s])).values());await Promise.allSettled(o.map(s=>Sa(s.requestType,s.name,s.categoryId,n.id)))},Fr=async t=>{t?.id&&(Zt.current=t.id),Te(t?.slug??null),Se(t?.store_slug??(Z&&Y||null)),await $s(),We(),n?.id&&En(n.id),Gr();try{(await y()).includes("org_member")&&v("org_member")}catch{}Oe(!1),bt(["organisation","brand","products","profile"]),Ce(!0),O.success("Your organisation is ready")},ct=async(t,o=10)=>{if(!n?.id)return null;for(let s=0;s<o;s+=1){await new Promise(d=>window.setTimeout(d,3e3));try{const d=await In(t,n.id);if(d)return d}catch{}}return null},be=!!n?.email_confirmed_at||ys;a.useEffect(()=>{if(i!==7||be)return;let t=!1;const o=async()=>{const{data:h}=await L.auth.getUser();if(t)return;if(h.user?.email_confirmed_at){Ke(!0);return}const M=ee.trim();if(!M||!nr)return;const $=await An(M);if(t||!$)return;const w=ir.current;if(w){const{error:ge}=await L.auth.signInWithPassword({email:M,password:w});if(t)return;if(!ge){Ke(!0);return}}Ke(!0)},s=window.setInterval(o,5e3),d=()=>{document.visibilityState==="visible"&&o()},f=()=>{o()};return document.addEventListener("visibilitychange",d),window.addEventListener("storage",f),()=>{t=!0,window.clearInterval(s),document.removeEventListener("visibilitychange",d),window.removeEventListener("storage",f)}},[Q,i,be,ee,nr]);const Ur=()=>{if(!n||!be){O.error("Confirm your email to finish",{description:"Click the link we emailed you, or enter the code above."});return}B({event_name:"onboarding_saved",event_params:{business_type:r.business_type||"",products:String(Ne)}}).catch(()=>{}),bt([]),Oe(!1),me("Creating your organisation…"),[{at:200,steps:["organisation"],status:"Creating your organisation…"},{at:3500,steps:["organisation","brand"],status:"Saving your brand…"},{at:8e3,steps:["organisation","brand","products"],status:"Preparing your products…"},{at:12e3,steps:["organisation","brand","products"],status:"Finalising your setup…"}
1].forEach(({at:o,steps:s,status:d})=>{const f=window.setTimeout(()=>{bt(h=>h.length>=s.length?h:s),me(d)},o);jt.current.push(f)}),Lr(!1)},Br=a.useRef(!1);if(a.useEffect(()=>{i===7&&(!n||!be||!r.org_name.trim()&&!r.website_url.trim()||xt||V||Br.current||(Br.current=!0,Ur()))},[i,n,be,xt,V,r.org_name,r.website_url]),a.useEffect(()=>{if(Dt===null||!it||!n||!be||!r.org_name.trim()&&!r.website_url.trim()||Dr.current)return;Dr.current=!0;const t=Dt;Or(null),Lr(t)},[Dt,it,n,be,Q]),Us&&!u?.id){const t=(Ot?.formData?.org_name||"").trim();return e.jsx("div",{className:"flex min-h-screen items-center justify-center bg-background px-6",children:e.jsxs("div",{className:"w-full max-w-md rounded-xl border border-border bg-card p-8 text-center",children:[e.jsx("div",{className:"mx-auto grid h-12 w-12 place-items-center rounded-full bg-primary/10 text-primary",children:e.jsx(ce,{className:"h-6 w-6"})}),e.jsx("h1",{className:"mt-4 font-serif text-xl font-semibold text-foreground",children:"Your email is verified"}),Ot?e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"mt-2 text-sm leading-relaxed text-muted-foreground",children:[t?`Your setup for ${t} is saved to your account, so you can finish it here.`:"Your setup is saved to your account, so you can finish it here."," ","If the window you started in is still open, it is carrying on there too."]}),e.jsx("div",{className:"mt-6",children:e.jsx(F,{variant:"signupCta",className:"w-full",onClick:()=>{lt(!1),dt(JSON.stringify(Ot),!0)},children:"Carry on setting up here"})})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"mt-2 text-sm leading-relaxed text-muted-foreground",children:"Go back to the window where you were setting up your organisation, it carries on by itself within a few seconds. If you have closed it, you can start again here."}),e.jsx("div",{className:"mt-6",children:e.jsx(F,{variant:"outline",className:"w-full",onClick:()=>lt(!1),children:"Start again here"})})]})]})})}if(!V&&n&&(c||u?.id))return e.jsx("div",{className:"flex min-h-screen items-center justify-center bg-background",children:e.jsx(re,{className:"h-8 w-8 animate-spin text-primary"})});if(lr)return e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx(Ea,{}),e.jsx("div",{className:"container mx-auto p-6 max-w-2xl",children:e.jsx(ha,{children:e.jsxs(xa,{className:"pt-10 pb-8 text-center space-y-5",children:[e.jsx("div",{className:"mx-auto w-14 h-14 rounded-full bg-primary/10 text-primary flex items-center justify-center",children:e.jsx(ce,{className:"h-7 w-7"})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h1",{className:"text-2xl font-semibold",children:"Request submitted"}),e.jsxs("p",{className:"text-sm text-muted-foreground max-w-md mx-auto leading-relaxed",children:["Thanks — we've received your application for"," ",e.jsx("span",{className:"font-medium text-foreground",children:r.org_name}),". Our team typically reviews new organisations within"," ",e.jsx("span",{className:"font-medium text-foreground",children:"24–48 hours"}),"."]})]}),e.jsxs("div",{className:"text-left bg-muted/50 border border-border rounded-lg p-4 space-y-3 max-w-md mx-auto",children:[e.jsx("p",{className:"text-sm font-medium",children:"What happens next"}),e.jsxs("ol",{className:"text-xs text-muted-foreground space-y-2 list-decimal list-inside leading-relaxed",children:[e.jsx("li",{children:"We review your request and verify your business details."}),lr.discoveryCallRequested&&e.jsx("li",{children:"We'll email you to confirm your discovery call slot."}),e.jsxs("li",{children:["Once approved, your ",X&&Z?"organisation, brand and store are":Z?"organisation and store are":"organisation and brand are"," created and you'll be able to sign in as an organisation member."]}),e.jsx("li",{children:"From your org dashboard you can add products, configure stores, and invite team members."})]})]})]})})})]});const $r=e.jsxs(e.Fragment,{children:[Cs&&!Qe&&e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"We could not read contact details from your site, so please add them below."}),Ps&&!Qe&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-1 flex items-center gap-1.5",children:[e.jsx(re,{className:"h-3 w-3 animate-spin"}),"Checking if this organisation is already on ",ae,"…"]}),z?.status==="live"&&e.jsxs("div",{className:"mt-3 rounded-lg border border-destructive/40 bg-destructive/5 p-3 text-sm flex items-start gap-2",children:[e.jsx(Yt,{className:"h-4 w-4 text-destructive mt-0.5 shrink-0"}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsxs("p",{className:"text-foreground",children:[e.jsx("span",{className:"font-medium",children:z.orgName??"This organisation"})," ","already has a ",ae," account."]}),tt?.status==="pending"?e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx(cn,{className:"h-3.5 w-3.5"}),"Access request sent ",new Date(tt.created_at).toLocaleDateString()," — awaiting a decision from the team."]}):tt?.status==="approved"?e.jsx("p",{className:"text-xs text-muted-foreground",children:"Your request was approved. Sign in to access this organisation."}):e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(F,{type:"button",size:"sm",variant:"outline",onClick:()=>p("/auth"),children:"Sign in"}),e.jsx(F,{type:"button",size:"sm",variant:"ghost",disabled:!z.organizationId,onClick:()=>Sr(!0),children:"Request access"}),tt?.status==="rejected"&&e.jsx("span",{className:"text-xs text-muted-foreground self-center",children:"Previous request declined — you can try again."})]})]})]}),z?.status==="pending"&&e.jsxs("div",{className:"mt-3 rounded-lg border border-amber-400/40 bg-amber-50 dark:bg-amber-950/20 p-3 text-sm flex items-start gap-2",children:[e.jsx(Yt,{className:"h-4 w-4 text-amber-600 mt-0.5 shrink-0"}),e.jsx("div",{className:"flex-1 space-y-2",children:e.jsxs("p",{className:"text-foreground",children:["An application for"," ",e.jsx("span",{className:"font-medium",children:z.orgName??z.domain})," ","is already in review. We'll get back to whoever submitted it shortly."]})})]}),z?.status==="rejected"&&e.jsxs("div",{className:"mt-3 rounded-lg border border-border bg-muted/40 p-3 text-xs text-muted-foreground flex items-start gap-2",children:[e.jsx(un,{className:"h-3.5 w-3.5 mt-0.5 shrink-0"}),e.jsx("p",{children:"A previous application for this website was not approved. You can submit a fresh request below."})]})]}),Ws=e.jsx(e.Fragment,{children:Je&&br&&!fr&&!Qe&&!qt&&e.jsx("div",{className:"rounded-lg border border-primary/30 bg-primary/5 p-3 text-sm",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(ce,{className:"h-4 w-4 text-primary mt-0.5 shrink-0"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"font-medium text-foreground",children:le?.brandName||le?.websiteUrl?"We've pre-filled what we found":`We've saved your ${br}`}),e.jsx("p",{className:"text-muted-foreground text-xs",children:le?.brandName?`Detected brand: ${le.brandName}. Edit anything that doesn't look right.`:"You can add it to your catalogue after your organisation is approved."})]})]})})});e.Fragment,[{key:"brand",checked:X,onToggle:ws,label:"Brand: Add my products",description:"Your products are uploaded, verified, and made available for visualisation across Prevamp and on your store."},{key:"retailer",checked:Z,onToggle:vs,label:"Retailer: Get a visualiser store",description:"Get a branded embeddable visualiser for your website, product pages, or showroom."}].map(t=>e.jsxs("button",{type:"button",onClick:t.onToggle,className:`flex items-start gap-3 p-4 rounded-lg border-2 text-left transition-all duration-150 ${t.checked?"border-primary bg-primary/5":"border-border hover:border-primary/40"}`,children:[e.jsx(Ua,{checked:t.checked,tabIndex:-1,"aria-hidden":!0,
1className:"mt-0.5 shrink-0 pointer-events-none"}),e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-sm",children:t.label}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:t.description})]})]},t.key)),(X||Z)&&(()=>{const t=X&&Z,o=X&&!Z,s=t?"Brands & Stores":o?"Brand / Manufacturer":"Retailer";return t?Math.max(r.requested_brands_count||1,r.requested_stores_count||1):o?r.requested_brands_count:r.requested_stores_count,e.jsxs("div",{className:"rounded-xl border border-border bg-muted/30 p-4 space-y-4",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsx("h3",{className:"font-semibold text-sm",children:s})}),t?e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(W,{htmlFor:"initial_brand_name",children:"Brand Name *"}),e.jsx(J,{id:"initial_brand_name",value:r.initial_brand_name,onChange:d=>{Gt(!0),D({...r,initial_brand_name:d.target.value})},placeholder:"Enter your primary brand name",className:"mt-1"}),!Me&&r.initial_brand_name&&r.initial_brand_name===r.org_name.trim()&&e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Edit if needed"})]}),e.jsxs("div",{children:[e.jsx(W,{htmlFor:"initial_store_name",children:"Store Name *"}),e.jsx(J,{id:"initial_store_name",value:r.initial_store_name,onChange:d=>{yt(!0),D({...r,initial_store_name:d.target.value})},placeholder:"Enter your primary store name",className:"mt-1"}),!Ve&&r.initial_store_name&&r.initial_store_name===`${r.org_name.trim()} Visualiser`&&e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Edit if needed"})]})]}):o?e.jsxs("div",{children:[e.jsx(W,{htmlFor:"initial_brand_name",children:"Brand Name *"}),e.jsx(J,{id:"initial_brand_name",value:r.initial_brand_name,onChange:d=>{Gt(!0),D({...r,initial_brand_name:d.target.value})},placeholder:"Enter your primary brand name",className:"mt-1"}),!Me&&r.initial_brand_name&&r.initial_brand_name===r.org_name.trim()&&e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Edit if needed"})]}):e.jsxs("div",{children:[e.jsx(W,{htmlFor:"initial_store_name",children:"Store Name *"}),e.jsx(J,{id:"initial_store_name",value:r.initial_store_name,onChange:d=>{yt(!0),D({...r,initial_store_name:d.target.value})},placeholder:"Enter your primary store name",className:"mt-1"}),!Ve&&r.initial_store_name&&r.initial_store_name===`${r.org_name.trim()} Visualiser`&&e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Edit if needed"})]}),!Q,e.jsx("p",{className:"text-xs text-muted-foreground",children:"Both are editable now and any time later. Names are public only if you publish a store."})]})})();const Ys=qn,Ms=(()=>{if(i===1){if(je)return"Reading…";const t=te(r.website_url);return t&&K.current===t?"Preview my organisation":"Read my site"}return i===2?"Continue to products":i===3?Ne===0?"Add products later":"Check my products":i===4?"Preview my organisation":i===5?"Save and create my account":"Continue"})(),Vs=e.jsxs(e.Fragment,{children:[i>1?e.jsxs(F,{type:"button",variant:"outline",onClick:Os,className:"flex items-center gap-2",children:[e.jsx(ya,{className:"h-4 w-4"}),"Back"]}):e.jsx(F,{type:"button",variant:"outline",onClick:()=>{We(),window.history.length>1?p(-1):p("/")},children:"Cancel"}),i<Be&&i!==6&&e.jsxs(F,{type:"button",onClick:Er,variant:"signupCta",disabled:i===1&&je||i===2&&je||i===4&&oe.some(t=>t.status==="reading"||t.status==="pending"),className:"flex items-center justify-center gap-2",children:[Ms,e.jsx(Kr,{className:"h-4 w-4"})]}),i===6&&e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("button",{type:"button",onClick:()=>He(!0),className:"text-sm text-muted-foreground underline hover:text-foreground",children:"Already have an account? Log in"}),e.jsxs(F,{type:"button",variant:"signupCta",disabled:Ge,onClick:()=>{n?.email?(q(7),window.scrollTo({top:0,behavior:"smooth"})):er.current?.submit()},className:"flex items-center justify-center gap-2",children:[Ge?e.jsx(re,{className:"mr-2 h-4 w-4 animate-spin"}):null,Ge?"Creating your account":"Create my organisation",e.jsx(Kr,{className:"h-4 w-4"})]})]})]}),Wr={1:{title:je?`Reading ${te(r.website_url)||"your website"}`:"Let's start with your website.",subtitle:je?"This takes a few seconds. Everything unlocks when it finishes, so you can correct anything we get wrong.":`We read your site once and pull out your logo, colours and product pages, so you are not filling in forms. It takes about two minutes to get your organisation live on ${ae}.`},2:{title:"Building your brand kit.",subtitle:"We are bringing together the details from your site. Check what we found and edit anything that does not look right."}
1,3:{title:"Add your products.",subtitle:"Paste a product page link and we read the rest. Bulk import and store sync open up as soon as your account exists."},4:{title:"Check your products.",subtitle:"We read each page you pasted. Pick the right image and correct the name, category and type before anything is created."},5:{title:"Preview your organisation.",subtitle:"Built from your logo, colours and products. Have a look, then carry on — everything here can be changed later."},6:{title:"Create your organisation.",subtitle:"Start your 14-day free trial to save your organisation, brand, products and store. Your dashboard then opens so you can review your products and start visualising."},7:{title:V?`${r.org_name||"Your organisation"} is live on ${ae}.`:`Setting up ${r.org_name||"your organisation"}.`,subtitle:V?"Your organisation, brand and products are set up on your 14-day free trial. Shoppers can already find and visualise them.":"This takes a few seconds. We are creating your organisation, saving your brand and preparing your products for visualisation."}},zs=i===6?"Step 6 of 7 · 14-day free trial":i===7?V?"Setup complete":"Step 7 of 7 · almost there":`Step ${i} of ${Be}`;return e.jsxs(e.Fragment,{children:[e.jsx(Aa,{open:!!Lt,children:e.jsxs(qa,{children:[e.jsxs(Ta,{children:[e.jsx(Ia,{children:"Carry on where you left off"}),e.jsx(Oa,{children:"We saved the organisation set-up you started on this device. You can pick it back up, or clear it and start again."})]}),e.jsxs(Da,{children:[e.jsx(La,{onClick:()=>{We(),Ft(null)},children:"Start again"}),e.jsx(Fa,{onClick:()=>{try{Lt&&dt(Lt,!1)}catch{}Ft(null)},children:"Carry on"})]})]})}),e.jsxs(Ys,{steps:Yn,currentStep:i,title:"Create your organisation",subject:r.org_name||te(r.website_url)||null,badge:i===5&&Ne>0?"Preview only · not public yet":i===5||i===6?"Preview only · nothing saved yet":"14-day free trial",onClose:()=>{window.history.length>1?p(-1):p("/")},onStepClick:t=>{const o=je||i===4&&oe.some(s=>s.status==="reading"||s.status==="pending");t<i&&!o&&q(t)},railFootnote:Mn[i],heading:Wr[i]?.title??"",subheading:Wr[i]?.subtitle,footerLabel:zs,footer:Vs,children:[i===1&&e.jsx(xn,{websiteUrl:r.website_url,reading:je,readComplete:!!te(r.website_url)&&K.current===te(r.website_url),duplicateBlocked:qt,onWebsiteChange:t=>{D({...r,website_url:t}),Ee(null)},onWebsiteBlur:kr,onRead:()=>{te(r.website_url)&&K.current===te(r.website_url)?Er():st(r.website_url)},onRescan:()=>{K.current="",st(r.website_url)},websiteNotice:$r,readError:Ns,footnote:Ws,platformName:ae}),i===2&&e.jsx(pn,{domain:te(r.website_url)||r.website_url,reading:je,orgName:r.org_name,websiteUrl:r.website_url,onOrgNameChange:t=>D({...r,org_name:t}),onWebsiteChange:t=>D({...r,website_url:t}),onWebsiteBlur:kr,websiteNotice:$r,logoUrl:r.org_logo_url,logoSource:Le[r.org_logo_url],uploading:bs,primaryColor:g?.primaryColor??null,accentColor:g?.accentColor??null,palette:{primary:g?.primaryColor,accent:g?.accentColor,background:g?.backgroundColor,text:g?.textColor},onSelectCandidate:t=>D(o=>({...o,org_logo_url:t})),onLogoError:()=>{const t=[...Fe,r.org_logo_url];vr(t);const o=ve.find(s=>!t.includes(s));D(s=>({...s,org_logo_url:o??""}))},onUploadClick:()=>{kt.current="",cr.current?.click()},displayName:r.initial_store_name,onDisplayNameChange:t=>{yt(!0),D(o=>({...o,initial_store_name:t}))},description:r.org_description,onDescriptionChange:t=>D(o=>({...o,org_description:t})),descriptionFromSite:!!g?.description&&r.org_description===g.description,pageAddress:Y?`${window.location.host}/store/${Y}`:null,candidates:ve.filter(t=>!Ue.includes(t)),deadUrls:Fe,onRemoveLogo:()=>D({...r,org_logo_url:""}),onColourChange:(t,o)=>et(s=>({...s??{},[t==="primary"?"primaryColor":t==="accent"?"accentColor":t==="background"?"backgroundColor":"textColor"]:o})),fileInput:e.jsx("input",{ref:cr,type:"file",accept:"image/png,image/jpeg,image/webp,image/svg+xml",className:"hidden",onChange:_s})}),i===3&&e.jsx(yn,{urls:r.product_urls,onChange:t=>D(o=>({...o,product_urls:t})),max:10}),i===4&&e.jsx(Ga,{urls:at,value:oe,onChange:_t,allowUpload:!1,deferTaxonomyRequests:!0}),i===5&&e.jsxs("div",{className:"space-y-4",children:[e.jsx(wn,{orgName:r.org_name,websiteUrl:r.website_url,logoUrl:r.org_logo_url,primaryColor:g?.primaryColor??null,accentColor:g?.accentColor??null,palette:{primary:g?.primaryColor??void 0,accent:g?.accentColor??void 0,background:g?.backgroundColor??void 0,text:g?.textColor??void 0},tagline:g?.tagline??null,storeName:r.initial_store_name||r.org_name,scrapedKit:he?.kit??null,loading:Rs&&!he,fallbackVisualiserImages:fe.map(t=>t.image_url),catalogueProducts:bn(oe),heroRoomUrl:Pe,heroProcessing:Xr
1(Qt)}),Xr(Qt)&&!Pe&&e.jsxs("div",{className:"flex items-center gap-3 rounded-lg border border-primary/20 bg-primary/5 p-4 text-sm text-foreground",children:[e.jsx(re,{className:"h-4 w-4 animate-spin text-primary"}),e.jsxs("span",{children:["Generating a sample room visualisation from your first product — switch to the ",e.jsx("strong",{children:"Visualiser"})," tab to see it when it arrives."]})]}),Pe&&e.jsxs("div",{className:"flex items-center gap-3 rounded-lg border border-green-500/20 bg-green-500/5 p-4 text-sm text-foreground",children:[e.jsx(ce,{className:"h-4 w-4 text-green-600"}),e.jsxs("span",{children:["Your sample room visualisation is ready — switch to the ",e.jsx("strong",{children:"Visualiser"})," tab to preview it."]})]})]}),i===6&&e.jsx(Nn,{ref:er,orgName:r.org_name,logoUrl:r.org_logo_url,productsFound:Ne,brandsCount:X?1:0,storesCount:Z?1:0,fullName:ze,email:ee,onFullNameChange:tr,onEmailChange:Nt,onCreateAccount:Ls,onGoogle:qr,onOpenSignIn:()=>He(!0),signedInEmail:n?.email??null,onContinue:()=>{q(7),window.scrollTo({top:0,behavior:"smooth"})},submitting:Ge,googleLoading:sr}),i===7&&e.jsxs("div",{className:"space-y-6",children:[!V&&e.jsx(Sn,{email:n?.email??ee,verificationRedirectTo:`${window.location.origin}${ot}`,verified:be,onVerified:()=>Ke(!0)}),e.jsx(jn,{orgName:r.org_name,productCount:Ne,emailVerified:be,building:xt,completed:ms,statusText:us,finished:V,accountEmail:n?.email??ee,platformName:ae,pageUrl:ie||Y?`${window.location.host}/store/${ie||Y}`:null,storePath:ie||Z&&Y?Bt(ie||Y):null,onBuild:Ur,recoveryPending:gs,onGoToDashboard:()=>{ue(U({welcome:!0}))},onViewStore:Ne>0||ie||Z&&Y?()=>{Zr();const t=ie||Y;if(t){ue(Bt(t));return}ue("/visualiser")}:void 0})]})]}),i>=6&&e.jsx(e.Fragment,{children:!!Pe&&!fs&&!Ra()&&e.jsx(ln,{productName:ps,accentColor:g?.accentColor,onOpen:()=>{Zr(),p(ie?Bt(ie):Ja())},onDismiss:()=>{Pa(),hs(!0)}})}),e.jsx(Cn,{open:xs,onOpenChange:He,defaultEmail:ee,onSignedIn:()=>{q(7),window.scrollTo({top:0,behavior:"smooth"})},onGoogle:qr,googleLoading:sr}),z?.status==="live"&&z.organizationId&&e.jsx(On,{open:Es,onOpenChange:Sr,organizationId:z.organizationId,organizationName:z.orgName??z.domain,organizationDomain:z.domain,resumePath:`/request-organization?url=${encodeURIComponent(r.website_url)}&autoscrape=1`,onSubmitted:()=>As()})]})}export{Wo 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.