1import{b as Ie,d as Ae,u as Le,e as Fe,al as De,r as d,B as y,t as V,aZ as ae,cW as re,cN as ce,j as e,n as Re,H as $,I as p,o as q,L as ue,c as F,Y as Te,cX as ie,W as A,v as Ue,a_ as Be,a$ as Me,b0 as Pe,ca as oe,cP as Oe,z as Ve,cY as ne,cZ as $e,cQ as qe,cO as ze}from"./main-DX7XzkoU.js";import{u as We}from"./useAuthFlow-FWX3SGoC.js";import{s as de}from"./subscriberService-DJIuIlbz.js";import{f as le,p as z,i as He}from"./phone-h24k5Ibv.js";import{a as Ye}from"./setPageMeta-BmXmCm3R.js";const Qe="starter-annual",Xe=12,Ze="62.363.484/0001-90",_="direct-checkout",Ge=/^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/,L=s=>new Intl.NumberFormat("pt-BR",{style:"currency",currency:"BRL"}).format(s/100),Ke=["address","addressNumber","province","city","state"],Je={height:"10px",backgroundImage:"radial-gradient(circle at 7px 10px, transparent 0 6px, hsl(var(--card)) 6.5px)",backgroundSize:"14px 10px",backgroundRepeat:"repeat-x"};function it(){const{t:s}=Ie(),[b]=Ae(),{user:o}=Le(),{signUp:g}=We();Fe();const{plans:f,plansLoading:C,loadPlans:D,subscription:R,error:me}
1=De(),T=b.get("plano")||Qe,[r,U]=d.useState({name:"",email:"",phone:"",cpf:"",password:"",cep:"",address:"",addressNumber:"",complement:"",province:"",city:"",state:""}),[he,B]=d.useState(""),[H,M]=d.useState(!1),[pe,Y]=d.useState(!1),[n,E]=d.useState({}),[Q,k]=d.useState(null),[j,X]=d.useState(!1),[S,Z]=d.useState(!1),[l,G]=d.useState(null),[K,P]=d.useState(!1),J=d.useRef(!1),ee=d.useRef(null),te=d.useRef(""),[xe,fe]=d.useState(!1);d.useEffect(()=>{const t=ee.current;if(!t)return;const a=new IntersectionObserver(([c])=>fe(!c.isIntersecting),{rootMargin:"-16px"});return a.observe(t),()=>a.disconnect()},[]),d.useEffect(()=>{!f.length&&!C&&D()},[f.length,C,D]);const i=d.useMemo(()=>f.find(t=>t.plan_slug===T),[f,T]),ge=T.endsWith("-annual"),_e=f.length>0&&(!i||!ge),be=!C&&f.length===0&&!!me,O=(i==null?void 0:i.price_amount)??0,se=Math.round(O/Xe);d.useEffect(()=>{Ye({title:s("direct_checkout.page_title",{brand:y.name}),description:s("direct_checkout.meta_description",{brand:y.name})});const t=document.createElement("meta");return t.name="robots",t.content="noindex",document.head.appendChild(t),()=>t.remove()},[s]),d.useEffect(()=>{J.current||!i||(J.current=!0,V("page_view",{flow:_,plan_slug:i.plan_slug,price:i.price_amount},void 0,_))},[i]),d.useEffect(()=>{if(!(o!=null&&o.id)||!o.email){G(null),P(!1);return}let t=!1;return P(!0),ae.getSubscriberAsaasProfile(o.id,o.email).then(a=>{t||G(a)}).catch(a=>{console.error("[DirectCheckout] Falha ao ler os dados de cobrança salvos",a)}).finally(()=>{t||P(!1)}),()=>{t=!0}},[o==null?void 0:o.id,o==null?void 0:o.email]);const N=!o,w=!(l!=null&&l.phone),v=!(l!=null&&l.cpf),I=!(l!=null&&l.billingAddress);d.useEffect(()=>{if(!l)return;const t=l.billingAddress;U(a=>({...a,phone:a.phone||(l.phone?le(l.phone):""),cpf:a.cpf||(l.cpf?ce(l.cpf):""),cep:a.cep||(t?re(t.postalCode):""),address:a.address||(t==null?void 0:t.address)||"",addressNumber:a.addressNumber||(t==null?void 0:t.addressNumber)||"",complement:a.complement||(t==null?void 0:t.complement)||"",province:a.province||(t==null?void 0:t.province)||"",city:a.city||(t==null?void 0:t.city)||"",state:a.state||(t==null?void 0:t.state)||""})),t!=null&&t.cityCode&&B(a=>a||t.cityCode)},[l]);const ke=async t=>{const a=ne(t);te.current=a,Y(!0),B("");const c=await $e(t);if(te.current!==a)return;c&&(U(m=>({...m,address:c.address||m.address,province:c.province||m.province,city:c.city||m.city,state:c.state||m.state})),B(c.cityCode));const u=!!(c!=null&&c.address&&c.province&&c.city&&c.state);M(!u),Y(!1),setTimeout(()=>{var m;return(m=document.getElementById(u?"checkout-address-number":"checkout-address"))==null?void 0:m.focus()},100)},je=t=>{const a=re(t);h("cep",a),ie(a)?ke(a):M(!1)},h=(t,a)=>{U(c=>({...c,[t]:a})),E(c=>c[t]?{...c,[t]:void 0}:c),k(null),t==="email"&&Z(!1)},Ne=()=>{const t={};if(N&&(r.name.trim().length<2&&(t.name=s("direct_checkout.error_name")),Ge.test(r.email.trim())||(t.email=s("direct_checkout.error_email")),S&&!r.password&&(t.password=s("direct_checkout.error_password_required"))),w&&!He(r.phone)&&(t.phone=s("direct_checkout.error_phone")),v&&!qe(r.cpf)&&(t.cpf=s("direct_checkout.error_cpf")),I){ie(r.cep)||(t.cep=s("direct_checkout.error_cep"));for(const a of Ke)r[a].trim()||(t[a]=s("direct_checkout.error_required"))}return E(t),Object.keys(t).length===0},we=async()=>{if(o)return!0;const t=r.email.trim();if(S){const{error:u}=await A.auth.signInWithPassword({email:t,password:r.password});return u?(E(m=>({...m,password:s("direct_checkout.error_wrong_password")})),!1):(await de(z(r.phone)),!0)}const a=crypto.randomUUID(),c=await g({email:t,password:a,name:r.name.trim(),phone:z(r.phone),instagramUsername:"",signupFlow:_},{redirect:!1,showErrorToast:!1});if(c.ok){const{error:u}=await A.auth.resetPasswordForEmail(t,{redirectTo:`${window.location.origin}/update-password`});return u&&console.error("[DirectCheckout] Falha ao enviar o link de senha",u),!0}return c.emailInUse?(Z(!0),E(u=>({...u,password:s("direct_checkout.error_existing_account")})),!1):(k(s(c.errorKey??"auth.errors.generic_signup")),!1)},ve=async()=>{if(l!=null&&l.asaasCustomerId&&!v&&!I)return l.asaasCustomerId;const t={cpf:ze(r.cpf),postalCode:ne(r.cep),address:r.address.trim(),addressNumber:r.addressNumber.trim(),complement:r.complement.trim(),province:r.province.trim(),city:r.city.trim(),state:r.state.trim(),cityCode:he},{data:a,error:c}=await A.functions.invoke("create-asaas-customer",{body:t});if(c)throw await oe(c);if(!(a!=null&&a.customerId))throw new Error("create-asaas-customer não devolveu customerId");return a.customerId},ye=async t=>{var a;if(t.preventDefault(),!(j||!i)&&Ne()){X(!0),k(null);try{const c=!!o;if(!await we())return;const{data:u}=await A.auth.getUser(),m=(a=u.user)==null?void 0:a.id;!c&&m&&(await Ue(m),V("register_complete",{flow:_},m,_)),c&&w&&await de(z(r.phone));const Ee=await ve();V("checkout_start",{flow:_,plan_slug:i.plan_slug,price:i.price_amount,currency:"BRL",payment_method:"CREDIT_CARD"},m,_),Be(i.plan_slug,i.plan_name,i.price_amount,"BRL"),Me(i.plan_slug,i.plan_name,i.price_amount,"BRL"),Pe(i.plan_slug,i.plan_name,i.price_amount,"BRL");const Se=await ae.createAsaasCheckoutWithCustomer(i.plan_slug,Ee,"pt","CREDIT_CARD");window.location.href=Se.url}catch(c){const u=await oe(c);if(console.error("[DirectCheckout] Falha ao abrir o pagamento",u),Oe(u)){k(u.message);return}k(u.status?u.message:s("direct_checkout.error_generic"))}finally{X(!1)}}};if(_e)return e.jsx(W,{title:s("direct_checkout.plan_not_found_title"),description:s("direct_checkout.plan_not_found_desc"),actionLabel:s("direct_checkout.see_plans"),actionTo:"/pricing"});if(be)return e.jsx(W,{title:s("direct_checkout.load_error_title"),description:s("direct_checkout.load_error_desc"),actionLabel:s("direct_checkout.retry"),onAction:()=>void D()});if(R!=null&&R.subscribed)return e.jsx(W,{title:s("direct_checkout.already_subscribed_t
1itle"),description:s("direct_checkout.already_subscribed_desc"),actionLabel:s("direct_checkout.go_to_app"),actionTo:"/dashboard"});const Ce=[...i?[s("direct_checkout.included_posts",{posts:i.images_per_month})]:[],s("direct_checkout.included_schedule"),s("direct_checkout.included_scripts"),s("direct_checkout.included_bio")];return e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx("header",{className:"border-b border-border/60 bg-card/80 backdrop-blur-sm",children:e.jsxs("div",{className:"mx-auto flex h-14 w-full max-w-5xl items-center justify-between px-4",children:[e.jsx("span",{className:"text-base font-semibold tracking-tight",children:y.name}),e.jsxs("span",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[e.jsx(Re,{className:"h-3.5 w-3.5","aria-hidden":"true"}),s("direct_checkout.secure_badge")]})]})}),e.jsxs("main",{className:"mx-auto grid w-full max-w-5xl gap-6 px-4 pb-16 pt-6 lg:grid-cols-[minmax(0,1fr)_20rem] lg:items-start lg:gap-8 lg:pt-12",children:[e.jsxs("section",{"aria-labelledby":"order-summary-title",className:"motion-safe:animate-in motion-safe:fade-in lg:col-start-2 lg:row-start-1",children:[e.jsxs("div",{className:"rounded-t-2xl bg-card px-5 pb-5 pt-5 shadow-[var(--shadow-card)]",children:[e.jsx("h2",{id:"order-summary-title",className:"text-xs font-medium uppercase tracking-wider text-muted-foreground",children:s("direct_checkout.order_summary")}),e.jsx("p",{className:"mt-3 text-sm font-medium text-foreground",children:C||!i?e.jsx("span",{className:"inline-block h-4 w-32 animate-pulse rounded bg-muted"}):i.plan_name}),e.jsx("p",{className:"mt-1 bg-[image:var(--gradient-primary)] bg-clip-text text-3xl font-bold leading-tight text-transparent",children:i?s("direct_checkout.installments",{amount:L(se)}):"â"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:i?s("direct_checkout.total_note",{amount:L(O)}):s("direct_checkout.loading_plan")}),e.jsxs("ul",{className:"mt-4 space-y-2 border-t border-dashed border-border pt-4 text-sm text-muted-foreground",children:[e.jsxs("li",{className:"flex gap-2",children:[e.jsx($,{className:"mt-0.5 h-4 w-4 shrink-0 text-primary","aria-hidden":"true"}),s("direct_checkout.summary_access")]}),e.jsxs("li",{className:"flex gap-2",children:[e.jsx($,{className:"mt-0.5 h-4 w-4 shrink-0 text-primary","aria-hidden":"true"}),s("direct_checkout.summary_guarantee")]})]})]}),e.jsx("div",{style:Je,"aria-hidden":"true"})]}),e.jsxs("section",{"aria-labelledby":"checkout-form-title",className:"rounded-2xl bg-card p-5 shadow-[var(--shadow-card)] sm:p-6 lg:col-start-1 lg:row-start-1 lg:row-span-2",children:[e.jsx("h1",{id:"checkout-form-title",className:"text-xl font-semibold tracking-tight",children:s("direct_checkout.form_title")}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:o?s("direct_checkout.form_subtitle_logged",{email:o.email}):s("direct_checkout.form_subtitle")}),e.jsxs("form",{id:"direct-checkout-form",onSubmit:ye,noValidate:!0,className:"mt-6 space-y-4",children:[N&&e.jsx(x,{id:"checkout-name",label:s("direct_checkout.name_label"),error:n.name,children:e.jsx(p,{id:"checkout-name",value:r.name,onChange:t=>h("name",t.target.value),autoComplete:"name",className:"h-12 text-base","aria-invalid":!!n.name})}),N&&e.jsx(x,{id:"checkout-email",label:s("direct_checkout.email_label"),hint:S?void 0:s("direct_checkout.password_created_note"),error:n.email,children:e.jsx(p,{id:"checkout-email",type:"email",inputMode:"email",value:r.email,onChange:t=>h("email",t.target.value),autoComplete:"email",className:"h-12 text-base","aria-invalid":!!n.email})}),e.jsxs("div",{className:w&&v?"grid gap-4 sm:grid-cols-2":"space-y-4",children:[w&&e.jsx(x,{id:"checkout-phone",label:s("direct_checkout.phone_label"),error:n.phone,children:e.jsx(p,{id:"checkout-phone",type:"tel",inputMode:"tel",placeholder:"(11) 91234-5678",value:r.phone,onChange:t=>h("phone",le(t.target.value)),autoComplete:"tel-national",className:"h-12 text-base","aria-invalid":!!n.phone})}),v&&e.jsx(x,{id:"checkout-cpf",label:s("direct_checkout.cpf_label"),hint:s("direct_checkout.cpf_hint"),error:n.cpf,children:e.jsx(p,{id:"checkout-cpf",inputMode:"numeric",placeholder:"000.000.000-00",value:r.cpf,onChange:t=>h("cpf",ce(t.target.value)),className:"h-12 text-base","aria-invalid":!!n.cpf})})]}),I&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-[minmax(0,1fr)_6.5rem] gap-3 sm:gap-4",children:[e.jsx(x,{id:"checkout-cep",label:s("direct_checkout.cep_label"),hint:s("direct_checkout.cep_hint"),error:n.cep,children:e.jsxs("div",{className:"relative",children:[e.jsx(p,{id:"checkout-cep",inputMode:"numeric",placeholder:"00000-000",value:r.cep,onChange:t=>je(t.target.value),autoComplete:"postal-code",className:"h-12 text-base","aria-invalid":!!n.cep}),pe&&e.jsx(q,{className:"absolute right-3 top-1/2 h-4 w-4 -translate-y-1/2 animate-spin text-muted-foreground","aria-hidden":"true"})]})}),e.jsx(x,{id:"checkout-address-number",label:s("direct_checkout.address_number_label"),error:n.addressNumber,children:e.jsx(p,{id:"checkout-address-number",inputMode:"numeric",value:r.addressNumber,onChange:t=>h("addressNumber",t.target.value),className:"h-12 text-base","aria-invalid":!!n.addressNumber})})]}),!H&&r.address&&e.jsxs("p",{className:"-mt-1 text-sm text-muted-foreground",children:[`${r.address}, ${r.province} â ${r.city}/${r.state}`," ",e.jsx("button",{type:"button",onClick:()=>M(!0),className:"text-primary underline underline-offset-4",children:s("direct_checkout.edit_address")})]}),H&&e.jsxs("div",{className:"space-y-4 motion-safe:animate-in motion-safe:fade-in",children:[e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsx(x,{id:"checkout-address",label:s("direct_checkout.address_label"),error:n.address,children:e.jsx(p,{id:"checkout-address",value:r.address,onChange:t=>h("address",t.target.value),autoComplete:"address-line1",className:"h-12 text-base","aria-invalid":!!n.address})}),e.jsx(x,{id:"checkout-complement",label:s("direct_checkout.complement_label"),children:e.jsx(p,{id:"checkout-complement",value:r.complement,onChange:t=>h("complement",t.target.value),autoComplete:"address-line2",className:"h-12 text-base"})})]}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-[minmax(0,1fr)_minmax(0,1fr)_5.5rem]",children:[e.jsx(x,{id:"checkout-province",label:s("direct_checkout.province_label"),error:n.province,children:e.jsx(p,{id:"checkout-province",value:r.province,onChange:t=>h("province",t.target.value),className:"h-12 text-base","aria-invalid":!!n.province})}),e.jsx(x,{id:"checkout-city",label:s("direct_checkout.city_label"),error:n.city,children:e.jsx(p,{id:"checkout-city",value:r.city,onChange:t=>h("city",t.target.value),className:"h-12 text-base","aria-invalid":!!n.city})}),e.jsx(x,{id:"checkout-state",label:s("direct_checkout.state_label"),error:n.state,children:e.jsx(p,{id:"checkout-state",maxLength:2,value:r.state,onChange:t=>h("state",t.target.value.toUpperCase()),className:"h-12 text-base uppercase","aria-invalid":!!n.state})})]})]})]}),N&&S&&e.jsxs("div",{className:"space-y-2 motion-safe:animate-in motion-safe:fade-in",children:[e.jsx(x,{id:"checkout-password",label:s("direct_checkout.password_label"),error:n.password,children:e.jsx(p,{id:"checkout-password",type:"password",value:r.password,onChange:t=>h("password",t.target.value),autoComplete:"current-password",autoFocus:!0,className:"h-12 text-base","aria-invalid":!!n.password})}),e.jsx("p",{className:"text-sm",children:e.jsx(ue,{to:"/forgot-password",className:"text-primary underline underline-offset-4",children:s("direct_checkout.forgot_password")})})]}),!N&&!w&&!v&&!I&&!K&&e.jsx("p",{className:"rounded-lg bg-muted/60 p-3 text-sm text-muted-foreground",children:s("direct_checkout.billing_on_file")}),Q&&e.jsx("p",{role:"alert",className:"rounded-lg bg-destructive/10 p-3 text-sm text-destructive",children:Q}),e.jsx(F,{ref:ee,type:"submit",size:"lg",disabled:j||!i||K,className:"h-14 w-full bg-[image:var(--gradient-primary)] text-base font-semibold text-white",children:j?e.jsxs(e.Fragment,{children:[e.jsx(q,{className:"mr-2 h-4 w-4 animate-spin","aria-hidden":"true"}),s("direct_checkout.submitting")]}):s("direct_checkout.submit")}),e.jsx("p",{className:"text-center text-xs text-muted-foreground",children:s("direct_checkout.next_step_note")})]})]}),e.jsxs("section",{"aria-labelledby":"included-title",className:"rounded-2xl border border-border/60 p-5 lg:col-start-2 lg:row-start-2",children:[e.jsx("h2",{id:"included-title",className:"text-sm font-semibold",children:s("direct_checkout.included_title")}),e.jsx("ul",{className:"mt-3 space-y-2 text-sm text-muted-foreground",children:Ce.map(t=>e.jsxs("li",{className:"flex gap-2",children:[e.jsx($,{className:"mt-0.5 h-4 w-4 shrink-0 text-primary","aria-hidden":"true"}),t]},t))}),e.jsxs("div",{className:"mt-5 flex gap-3 border-t border-border/60 pt-4",children:[e.jsx(Te,{className:"mt-0.5 h-5 w-5 shrink-0 text-primary","aria-hidden":"true"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:s("direct_checkout.guarantee_title")}),e.jsx("p",{className:"mt-0.5 text-sm text-muted-foreground",children:s("direct_checkout.guarantee_desc")})]})]}),e.jsxs("figure",{className:"mt-5 border-t border-border/60 pt-4",children:[e.jsxs("blockquote",{className:"text-sm italic text-muted-foreground",children:["â",s("pricing.testimonial_text"),"â"]}
1),e.jsx("figcaption",{className:"mt-2 text-xs text-muted-foreground",children:s("pricing.testimonial_author")})]})]})]}),e.jsxs("footer",{className:"space-y-1 px-4 pb-28 text-center text-xs text-muted-foreground lg:pb-10",children:[e.jsx("p",{children:e.jsx("a",{href:`mailto:${y.supportEmail}`,className:"underline underline-offset-4",children:s("direct_checkout.support_link")})}),e.jsx("p",{children:s("direct_checkout.legal_line",{brand:y.name,taxId:Ze})})]}),i&&xe&&e.jsx("div",{className:"fixed inset-x-0 bottom-0 z-40 border-t border-border/60 bg-card/95 px-4 py-3 pb-[calc(0.75rem+env(safe-area-inset-bottom))] backdrop-blur motion-safe:animate-in motion-safe:slide-in-from-bottom-2 lg:hidden",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-sm font-semibold",children:s("direct_checkout.installments",{amount:L(se)})}),e.jsx("p",{className:"truncate text-xs text-muted-foreground",children:s("direct_checkout.total_note",{amount:L(O)})})]}),e.jsx(F,{type:"submit",form:"direct-checkout-form",disabled:j,className:"ml-auto h-12 shrink-0 bg-[image:var(--gradient-primary)] px-5 text-base font-semibold text-white",children:j?e.jsx(q,{className:"h-4 w-4 animate-spin","aria-hidden":"true"}):s("direct_checkout.submit_short")})]})})]})}const x=({id:s,label:b,hint:o,error:g,children:f})=>e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(Ve,{htmlFor:s,className:"text-sm",children:b}),f,g?e.jsx("p",{className:"text-sm text-destructive",children:g}):o?e.jsx("p",{className:"text-xs text-muted-foreground",children:o}):null]}),W=({title:s,description:b,actionLabel:o,actionTo:g,onAction:f})=>e.jsx("div",{className:"flex min-h-screen items-center justify-center bg-background px-4",children:e.jsxs("div",{className:"w-full max-w-sm rounded-2xl bg-card p-6 text-center shadow-[var(--shadow-card)]",children:[e.jsx("h1",{className:"text-lg font-semibold",children:s}),e.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:b}),g?e.jsx(F,{asChild:!0,className:"mt-5 w-full",children:e.jsx(ue,{to:g,children:o})}):e.jsx(F,{className:"mt-5 w-full",onClick:f,children:o})]})});export{it 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.