PageSourceSearch

https://mhfrontend-production.up.railway.app/_next/static/chunks/c013280f3a68ccfa.js

js mhfrontend-production.up.railway.app collected 2026-10-03 12:13:28 UTC 61,680 bytes, 1 lines download raw bytes

1(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,83642,e=>{"use strict";e.i(47167);var t=e.i(43476),r=e.i(71645),n=e.i(30996),i=e.i(38036),o=e.i(34462),a=e.i(30374),s=e.i(67881),l=e.i(23750),c=e.i(10708),u=e.i(25959),d=e.i(31278),f=e.i(63488),m=e.i(70756),p=e.i(84614),h=e.i(95468),g=e.i(63209),v=e.i(83086),y=e.i(58249);function w({open:e,onOpenChange:n,defaultMode:o="login",onSuccess:w}){let[x,b]=(0,r.useState)(o),[k,E]=(0,r.useState)(!1),[j,S]=(0,r.useState)(null),[C,_]=(0,r.useState)(null),[N,T]=(0,r.useState)(""),[A,R]=(0,r.useState)(""),[O,I]=(0,r.useState)(""),[P,L]=(0,r.useState)(""),[D,$]=(0,r.useState)(""),[M,z]=(0,r.useState)(!1),[U,F]=(0,r.useState)(["","","","","",""]),[B,W]=(0,r.useState)(0),[H,J]=(0,r.useState)("signup"),V=(0,r.useRef)([]);(0,r.useEffect)(()=>{queueMicrotask(()=>{e?(b(o),S(null),_(null)):(b(o),T(""),R(""),I(""),L(""),$(""),z(!1),F(["","","","","",""]),J("signup"),S(null),_(null),W(0))})},[e,o]),(0,r.useEffect)(()=>{if(B>0){let e=setTimeout(()=>W(B-1),1e3);return()=>clearTimeout(e)}},[B]),(0,r.useEffect)(()=>{"otp"===x&&V.current[0]&&setTimeout(()=>V.current[0]?.focus(),100)},[x]);let q=()=>{if(S(null),!N||!/\S+@\S+\.\S+/.test(N))return S("Inserisci un'email valida"),!1;if("forgot"!==x&&"otp"!==x){if(!A)return S("Inserisci la password"),!1;if(A.length<6)return S("La password deve essere almeno 6 caratteri"),!1}if("signup"===x){if(!O)return S("Inserisci il nome"),!1;if(!P)return S("Inserisci il cognome"),!1;if(A!==D)return S("Le password non coincidono"),!1;if(!M)return S("Devi accettare i termini e la privacy policy per registrarti"),!1}return!("otp"===x&&U.some(e=>""===e))||(S("Inserisci il codice completo a 6 cifre"),!1)},K=async()=>{if(q()){E(!0),S(null),_(null);try{let e=await (0,i.loginDirect)(N,A);if((0,i.saveTokens)(e.access_token,e.refresh_token,e.user),!localStorage.getItem("flowstarter_access_token"))throw Error("Errore nel salvataggio del token");_("Accesso effettuato con successo!"),(0,y.trackEvent)("user_login",{source:"modal",page:window.location.pathname,email:N,email_domain:N.split("@")[1],user_label:N}),setTimeout(()=>{w?.(e.user),n(!1)},500)}catch(e){S(e instanceof Error?e.message:"Errore durante il login")}finally{E(!1)}}},X=async()=>{if(q()){E(!0),S(null),_(null);try{let e=`${window.location.origin}/auth/confirm`,t=await (0,i.signupDirect)(N,A,O,P,e),r=t.user||(t.id?t:null),o=t.access_token&&t.refresh_token;if(o&&r){if((0,i.saveTokens)(t.access_token,t.refresh_token,r),!localStorage.getItem("flowstarter_access_token"))throw Error("Errore nel salvataggio del token");_("Registrazione completata!");let e=`${O} ${P}`.trim();(0,y.trackEvent)("user_signup",{source:"modal",page:window.location.pathname,email:N,name:e||void 0,email_domain:N.split("@")[1],user_label:e||N}),setTimeout(()=>{w?.(r),n(!1)},500)}else if(r&&!o)b("otp"),J("signup"),W(60),_("📧 Ti abbiamo inviato un codice di verifica via email. Controlla la tua casella!");else throw console.error("[Auth] Risposta signup inattesa:",t),Error("Registrazione non completata. Riprova.")}catch(r){console.error("[Auth] Signup CATCH block:",r);let e=r instanceof Error?r.message:"Errore durante la registrazione",t=e.toLowerCase();t.includes("already")||t.includes("già registrata")||t.includes("already registered")||t.includes("user already exists")||t.includes("email already")?(S(e="Questa email è già registrata. Vuoi accedere invece?"),setTimeout(()=>{S(null),b("login")},3e3)):S(e)}finally{E(!1)}}},G=async()=>{if(q()){E(!0),S(null),_(null);try{let e=U.join(""),t=await (0,i.verifyOtpDirect)(N,e,H);(0,i.saveTokens)(t.access_token,t.refresh_token,t.user),_("✅ Email verificata! Accesso effettuato."),setTimeout(()=>{w?.(t.user),n(!1)},1e3)}catch(e){S(e instanceof Error?e.message:"Codice non valido o scaduto"),F(["","","","","",""]),setTimeout(()=>V.current[0]?.focus(),100)}finally{E(!1)}}},Y=async()=>{if(!(B>0)){E(!0),S(null);try{if("magiclink"===H){let e=`${window.location.origin}${window.location.pathname}`;await (0,i.sendMagicLinkDirect)(N,e)}else await (0,i.resendOtpDirect)(N,"signup");W(60),_("📧 Nuovo codice inviato!"),F(["","","","","",""])}catch(e){S(e instanceof Error?e.message:"Impossibile re-inviare il codice")}finally{E(!1)}}},Z=async()=>
1{if(q()){E(!0),S(null),_(null);try{let e=await (0,i.forgotPasswordDirect)(N);_(e.message||"Se l'email esiste, riceverai le istruzioni per reimpostare la password."),(0,y.trackEvent)("forgot_password_request",{source:"modal",page:window.location.pathname})}catch(e){_("Se l'email esiste, riceverai le istruzioni per reimpostare la password.")}finally{E(!1)}}},Q=async()=>{if(!N||!/\S+@\S+\.\S+/.test(N))return void S("Inserisci un'email valida");E(!0),S(null),_(null);try{let e=`${window.location.origin}${window.location.pathname}`;await (0,i.sendMagicLinkDirect)(N,e),_("📧 Ti abbiamo inviato un link magico e un codice! Puoi usare entrambi."),b("otp"),J("magiclink"),W(60),(0,y.trackEvent)("magic_link_request",{source:"modal",page:window.location.pathname,email_domain:N.split("@")[1]})}catch(e){S(e instanceof Error?e.message:"Errore durante l'invio del magic link")}finally{E(!1)}},ee=async e=>{e.preventDefault(),"login"===x?await K():"signup"===x?await X():"otp"===x?await G():"forgot"===x?await Z():"magic"===x&&await Q()};return(0,t.jsx)(a.Dialog,{open:e,onOpenChange:n,children:(0,t.jsxs)(a.DialogContent,{className:"sm:max-w-md",children:[(0,t.jsxs)(a.DialogHeader,{children:[(0,t.jsx)(a.DialogTitle,{children:(()=>{switch(x){case"login":return"Accedi";case"signup":return"Crea Account";case"forgot":return"Recupera Password";case"magic":return"Magic Link";case"otp":return"Verifica";default:return"Autenticazione"}})()}),(0,t.jsx)(a.DialogDescription,{children:(()=>{switch(x){case"login":return"Accedi al tuo account Marketing Hackers";case"signup":return"Crea un account gratuito per iniziare";case"forgot":return"Inserisci la tua email per reimpostare la password";case"magic":return"Accedi senza password con un link magico";case"otp":return`Abbiamo inviato un codice a ${N}`;default:return""}})()})]}),(0,t.jsxs)("form",{onSubmit:ee,className:"space-y-4",children:["otp"===x&&(0,t.jsxs)("div",{className:"space-y-4",children:[(0,t.jsx)("div",{className:"bg-muted/50 border border-border rounded-lg p-4",children:(0,t.jsxs)("p",{className:"text-sm text-muted-foreground",children:["✉️ Clicca il ",(0,t.jsx)("strong",{children:"link nell'email"})," oppure 🔢 inserisci il"," ",(0,t.jsx)("strong",{children:"codice a 6 cifre"})]})}),(0,t.jsx)("div",{className:"flex justify-center gap-2",children:U.map((e,r)=>(0,t.jsx)(l.Input,{ref:e=>V.current[r]=e,type:"text",inputMode:"numeric",maxLength:1,value:e,onChange:e=>((e,t)=>{if(t&&!/^\d$/.test(t))return;let r=[...U];r[e]=t,F(r),t&&e<5&&V.current[e+1]?.focus()})(r,e.target.value),onKeyDown:e=>{"Backspace"===e.key&&!U[r]&&r>0&&V.current[r-1]?.focus()},disabled:k,className:"w-12 h-12 text-center text-xl font-bold"},r))}),(0,t.jsx)(s.Button,{type:"button",onClick:G,disabled:k||U.some(e=>""===e),className:"w-full",children:k?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(d.Loader2,{className:"mr-2 h-4 w-4 animate-spin"}),"Verifica..."]}):"✅ Verifica Codice"}),(0,t.jsx)("div",{className:"text-center",children:(0,t.jsx)(s.Button,{type:"button",variant:"ghost",size:"sm",onClick:Y,disabled:k||B>0,children:B>0?`Riprova tra ${B}s`:"Invia nuovo codice"})}),(0,t.jsx)(s.Button,{type:"button",variant:"ghost",size:"sm",onClick:()=>{b("login"),F(["","","","","",""]),S(null),_(null)},className:"w-full",children:"← Torna indietro"})]}),"magic"===x&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("div",{className:"bg-muted/50 border border-border rounded-lg p-4",children:(0,t.jsx)("p",{className:"text-sm text-muted-foreground text-center",children:"✨ Inserisci la tua email e riceverai un link magico o un codice per accedere senza password"})}),(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(c.Label,{htmlFor:"email-magic",children:"Email"}),(0,t.jsxs)("div",{className:"relative",children:[(0,t.jsx)(f.Mail,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 text-muted-foreground h-4 w-4"}),(0,t.jsx)(l.Input,{id:"email-magic",type:"email",placeholder:"[email protected]",value:N,onChange:e=>T(e.target.value),className:"pl-10",required:!0})]})]}),(0,t.jsx)(s.Button,{type:"submit",disabled:k,className:"w-full",children:k?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(d.Loader2,{className:"mr-2 h-4 w-4 animate-spin"}),"Invio..."]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(v.Sparkles,{className:"mr-2 h-4 w-4"}),"Invia Magic Link"]})})]}),"otp"!==x&&"magic"!==x&&(0,t.jsxs)(t.Fragment,{children:["signup"===x&&(0,t.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(c.Label,{htmlFor:"firstName",children:"Nome"}),(0,t.jsxs)("div",{className:"relative",children:[(0,t.jsx)(p.User,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 text-muted-foreground h-4 w-4"}),(0,t.jsx)(l.Input,{id:"firstName",type:"text",placeholder:"Mario",value:O,onChange:e=>I(e.target.value),className:"pl-10",required:!0})]})]}),(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(c.Label,{htmlFor:"lastName",children:"Cognome"}),(0,t.jsx)(l.Input,{id:"lastName",type:"text",placeholder:"Rossi",value:P,onChange:e=>L(e.target.value),required:!0})]})]}),(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(c.Label,{htmlFor:"email",children:"Email"}),(0,t.jsxs)("div",{className:"relative",children:[(0,t.jsx)(f.Mail,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 text-muted-foreground h-4 w-4"}),(0,t.jsx)(l.Input,{id:"email",type:"email",placeholder:"[email protected]",value:N,onChange:e=>T(e.target.value),className:"pl-10",required:!0})]})]}),"forgot"!==x&&(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(c.Label,{htmlFor:"password",children:"Password"}),(0,t.jsxs)("div",{className:"relative",children:[(0,t.jsx)(m.Lock,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 text-muted-foreground h-4 w-4"}),(0,t.jsx)(l.Input,{id:"password",type:"password",placeholder:"••••••••",value:A,onChange:e=>R(e.target.value),className:"pl-10",required:!0})]})]}),"signup"===x&&(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(c.Label,{htmlFor:"confirmPassword",children:"Conferma Password"}),(0,t.jsxs)("div",{className:"relative",children:[(0,t.jsx)(m.Lock,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 text-muted-foreground h-4 w-4"}),(0,t.jsx)(l.Input,{id:"confirmPassword",type:"password",placeholder:"••••••••",value:D,onChange:e=>$(e.target.value),className:"pl-10",required:!0})]})]}),"signup"===x&&(0,t.jsxs)("div",{className:"flex items-start space-x-3 pt-2",children:[(0,t.jsx)(u.Checkbox,{id:"acceptTerms",checked:M,onCheckedChange:e=>z(!0===e),className:"mt-0.5"}),(0,t.jsxs)("label",{htmlFor:"acceptTerms",className:"text-xs text-muted-foreground leading-relaxed cursor-pointer",children:["Accetto i"," ",(0,t.jsx)("a",{href:"/terms",target:"_blank",className:"text-primary hover:underline font-medium",children:"termini e condizioni"})," ","e la"," ",(0,t.jsx)("a",{href:"/privacy",target:"_blank",className:"text-primary hover:underline font-medium",children:"privacy policy"}),". Acconsento al trattamento dei miei dati come descritto nell'informativa."]})]}),(0,t.jsx)(s.Button,{type:"submit",disabled:k,className:"w-full",children:k?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(d.Loader2,{className:"mr-2 h-4 w-4 animate-spin"}),"Caricamento..."]}):(0,t.jsxs)(t.Fragment,{children:["login"===x&&"🔑 Accedi","signup"===x&&"🎉 Crea Account Gratuito","forgot"===x&&"📧 Invia Email di Reset"]})}),("login"===x||"signup"===x)&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:"relative my-4",children:[(0,t.jsx)("div",{className:"absolute inset-0 flex items-center",children:(0,t.jsx)("span",{className:"w-full border-t"})}),(0,t.jsx)("div",{className:"relative flex justify-center text-xs uppercase",children:(0,t.jsx)("span",{className:"bg-background px-2 text-muted-foreground",children:"oppure continua con"})})]}),(0,t.jsxs)(s.Button,{type:"button",variant:"outline",disabled:k,onClick:()=>{let e=window.location.pathname;window.location.href=`/api/auth/oauth/google?redirect_to=${encodeURIComponent(e)}`},className:"w-full flex items-center justify-center gap-2",children:[(0,t.jsxs)("svg",{className:"h-4 w-4",viewBox:"0 0 24 24",children:[(0,t.jsx)("path",{d:"M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z",fill:"#4285F4"}),(0,t.jsx)("path",{d:"M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z",fill:"#34A853"}),(0,t.jsx)("path",{d:"M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z",fill:"#FBBC05"}),(0,t.jsx)("path",{d:"M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z",fill:"#EA4335"})]}),"Continua con Google"]})]})]}),j&&(0,t.jsxs)("div",{className:"flex items-center gap-2 p-3 bg-destructive/10 border border-destructive/20 rounded-lg text-sm text-destructive",children:[(0,t.jsx)(g.AlertCircle,{className:"h-4 w-4"}),(0,t.jsx)("span",{children:j})]}),C&&(0,t.jsxs)("div",{className:"flex items-center gap-2 p-3 bg-green-500/10 border border-green-500/20 rounded-lg text-sm text-green-600 dark:text-green-400",children:[(0,t.jsx)(h.CheckCircle2,{className:"h-4 w-4"}),(0,t.jsx)("span",{children:C})]}),"otp"!==x&&(0,t.jsxs)("div",{className:"text-center space-y-2 pt-2 border-t",children:["login"===x&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:(0,t.jsxs)("button",{type:"button",onClick:()=>b("magic"),className:"text-primary hover:underline inline-flex items-center gap-1",children:[(0,t.jsx)(v.Sparkles,{className:"h-3 w-3"}),"Accedi con Magic Link"]})}),(0,t.jsxs)("p",{className:"text-sm text-muted-foreground",children:["Non hai un account?"," ",(0,t.jsx)("button",{type:"button",onClick:()=>b("signup"),className:"text-primary hover:underline font-medium",children:"Crea account gratuito"})]}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:(0,t.jsx)("button",{type:"button",onClick:()=>b("forgot"),className:"text-primary hover:underline",children:"Password dimenticata?"})})]}),"magic"===x&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("p",{className:"text-sm text-muted-foreground",children:["Preferisci usare la password?"," ",(0,t.jsx)("button",{type:"button",onClick:()=>b("login"),className:"text-primary hover:underline font-medium",children:"Accedi con password"})]}),(0,t.jsxs)("p",{className:"text-sm text-muted-foreground",children:["Non hai un account?"," ",(0,t.jsx)("button",{type:"button",onClick:()=>b("signup"),className:"text-primary hover:underline font-medium",children:"Crea account gratuito"})]})]}),"signup"===x&&(0,t.jsxs)("p",{className:"text-sm text-muted-foreground",children:["Hai già un account?"," ",(0,t.jsx)("button",{type:"button",onClick:()=>b("login"),className:"text-primary hover:underline font-medium",children:"Accedi qui"})]}),"forgot"===x&&(0,t.jsxs)("p",{className:"text-sm text-muted-foreground",children:["Ricordi la password?"," ",(0,t.jsx)("button",{type:"button",onClick:()=>b("login"),className:"text-primary hover:underline font-medium",children:"Torna al login"})]})]})]})]})})}var x=e.i(29863);let b=(0,r.createContext)(void 0);function k(e){return(0,n.isTokenExpired)(e,3e5)}async function E(e){try{let t=await fetch("/api/auth/provision-oauth",{method:"POST",headers:{Authorization:`Bearer ${e}`,"Content-Type":"application/json"}});if(!t.ok){let e=await t.text();console.error("[OAuth] Provisioning HTTP error:",t.status,e);return}let r=await t.json();r.message,r.credits&&window.dispatchEvent(new CustomEvent("oauth-provisioned",{detail:{credits:r.credits}}))}catch(e){console.error("[OAuth] Errore chiamata provisioning:",e)}}function j({children:e}){let[n,a]=(0,r.useState)(null),[s,l]=(0,r.useState)(0),[c,u]=(0,r.useState)(!0),[d,f]=(0,r.useState)(!1),m=(0,r.useRef)(!1),p=(0,r.useRef)(!1),[h,g]=(0,r.useState)(!1),[v,j]=(0,r.useState)("login"),[,S]=(0,r.useTransition)(),C=(0,r.useCallback)(()=>{(0,x.clearAuthCookies)(),(0,i.clearAllTokens)(),S(()=>{a(null),f(!1),l(0)})},[]),_=(0,r.useCallback)(async()=>{try{if((0,x.migrateLocalStorageToCookies)(),function(){let e=window.location.hash;if(e&&e.includes("access_token="))try{let t=new URLSearchParams(e.substring(1)),r=t.get("access_token"),n=t.get("refresh_token");if(t.get("expires_at"),!r)return console.warn("[OAuth] access_token mancante nel hash"),!1;(0,x.setAuthCookies)(r,n||"");try{let e=r.split(".");if(3===e.length){let t=JSON.parse(atob(e[1])),r={id:t.sub,email:t.email,name:t.user_metadata?.full_name||t.user_metadata?.name||t.email?.split("@")[0],avatar_url:t.user_metadata?.avatar_url||t.user_metadata?.picture,email_verified:t.user_metadata?.email_verified||!1};(0,x.setUserCookie)(r)}}catch(e){console.error("[OAuth] Errore estrazione user dal JWT:",e)}let i=window.location.pathname+window.location.search;window.history.replaceState({},"",i),(0,o.initAuthRefresh)(r),E(r).catch(e=>{console.error("[OAuth] Provisioning fallito (non bloccante):",e)})}catch(e){return console.error("[OAuth] Errore parsing hash fragment:",e),!1}}(),function(){let e=new URLSearchParams(window.location.search),t=e.get("sso_token"),r=e.get("sso_refresh"),n=e.get("sso_user");if(t){if(r?(0,x.setAuthCookies)(t,r):(0,x.setAuthCookies)(t,""),(0,o.initAuthRefresh)(t),n)try{let e=decodeURIComponent(n),t=JSON.parse(e);(0,x.setUserCookie)(t)}catch(e){console.error("[SSO] Errore decodifica user:",e)}e.delete("sso_token"),e.delete("sso_refresh"),e.delete("sso_user");let i=e.toString()?`${window.location.pathname}?${e.toString()}`:window.location.pathname;return window.history.replaceState({},"",i)};}(),!(0,i.isAuthenticated)()){u(!1),a(null),f(!1);return}let e=(0,i.getAccessToken)();if(!e){u(!1),a(null),f(!1);return}if(k(e))if(await (0,o.tryRefreshToken)());else{C(),u(!1);return}let t=(0,i.getStoredUser)();t&&(a(t),f(!0),u(!1));try{if(p.current){(0,o.initAuthRefresh)(e);try{let t=await (0,i.getCreditsBalance)(e);l(t)}catch(e){console.warn("[Auth] ⚠️ Errore caricamento crediti:",e)}return}let t=await (0,i.verifyToken)(e);if(t){a(t),f(!0),(0,x.setUserCookie)(t),(0,o.initAuthRefresh)(e);let r=t.name||`${t.first_name||""} ${t.last_name||""}`.trim()||void 0;(0,y.identifyUser)({id:t.id,email:t.email,name:r,tier:t.tier||"free"}),m.current||((0,y.trackEvent)("user_authenticated",{source:"session_restore",page:window.location.pathname,email:t.email,name:r,tier:t.tier||"free",user_label:r||t.email}),m.current=!0);try{let t=await (0,i.getCreditsBalance)(e);l(t)}catch(e){console.warn("[Auth] ⚠️ Errore caricamento crediti:",e)}}else C()}catch(e){console.warn("[Auth] ⚠️ Errore rete verifica token:",e),t||C()}}catch(e){console.error("[AuthContext] ❌ Error initializing auth:",e),C()}finally{u(!1)}},[C]);(0,r.useEffect)(()=>{_();let e=setInterval(async()=>{let e=(0,i.getAccessToken)();e&&k(e)&&(await (0,o.tryRefreshToken)()||C())},3e5),t=e=>{e.key!==x.TOKEN_STORAGE_KEY&&e.key!==x.AUTH_TOKEN_COOKIE||e.newValue||queueMicrotask(()=>{a(null),f(!1),l(0)})};window.addEventListener("storage",t);let r=e=>{let t=e.detail;t?.source==="auth-refresh"&&S(()=>{a(null),f(!1),l(0),j("login"),g(!0)})};window.addEventListener("session-expired",r);let n=e=>{e.detail?.credits&&S(()=>{l(e.detail.credits)})};return window.addEventListener("oauth-provisioned",n),()=>{clearInterval(e),window.removeEventListener("storage",t),window.removeEventListener("session-expired",r),window.removeEventListener("oauth-provisioned",n)}},[_,C]);let N=(0,r.useCallback)(async()=>{u(!0),await _()},[_]),T=(0,r.useCallback)((e="login")=>{S(()=>{j(e),g(!0)})},[]),A=(0,r.useCallback)(()=>{S(()=>{g(!1)})},[]),R=(0,r.useCallback)(async e=>{p.current=!0,setTimeout(()=>{p.current=!1},1e4);let t=(0,i.getAccessToken)();if(!t){console.error("[Auth] ⚠️ Token non trovato dopo login! Ricarico da localStorage..."),setTimeout(async()=>{await _()},100);return}a(e),f(!0),u(!1),await new Promise(e=>setTimeout(e,100)),g(!1),(0,x.setUserCookie)(e),(0,y.identifyUser)({id:e.id,email:e.email,tier:e.tier||"free"}),(0,o.initAuthRefresh)(t),(0,i.getCreditsBalance)(t).then(e=>{S(()=>{l(e)})}).catch(e=>{console.warn("[Auth] Errore caricamento crediti:",e)})},[_]),O=(0,r.useCallback)(e=>{(0,i.clearA
1llTokens)();let t=e?e.startsWith("http")?e:`${window.location.origin}${e}`:window.location.href;(0,i.redirectToAuth)("login",t)},[]),I=(0,r.useCallback)(e=>{(0,i.clearAllTokens)();let t=e?e.startsWith("http")?e:`${window.location.origin}${e}`:window.location.href;(0,i.redirectToAuth)("signup",t)},[]),P=(0,r.useCallback)(()=>{C(),(0,i.logout)()},[C]),L=(0,r.useCallback)(()=>{(0,i.redirectToDashboard)()},[]);return(0,t.jsxs)(b.Provider,{value:{user:n,credits:s,loading:c,isAuthenticated:d,authModalOpen:h,authModalMode:v,openAuthModal:T,closeAuthModal:A,login:O,signup:I,logout:P,goToDashboard:L,refreshAuth:N},children:[e,(0,t.jsx)(w,{open:h,onOpenChange:g,defaultMode:v,onSuccess:R})]})}function S(){let e=(0,r.useContext)(b);if(void 0===e)throw Error("useAuth must be used within an AuthProvider");return e}e.s(["AuthProvider",()=>j,"default",0,b,"useAuth",()=>S],83642)},30374,e=>{"use strict";var t=e.i(43476),r=e.i(26999),n=e.i(95926),i=e.i(47163);function o({...e}){return(0,t.jsx)(r.Root,{"data-slot":"dialog",...e})}function a({...e}){return(0,t.jsx)(r.Trigger,{"data-slot":"dialog-trigger",...e})}function s({...e}){return(0,t.jsx)(r.Portal,{"data-slot":"dialog-portal",...e})}function l({className:e,...n}){return(0,t.jsx)(r.Overlay,{"data-slot":"dialog-overlay",className:(0,i.cn)("data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",e),...n})}function c({className:e,children:o,showCloseButton:a=!0,...c}){return(0,t.jsxs)(s,{"data-slot":"dialog-portal",children:[(0,t.jsx)(l,{}),(0,t.jsxs)(r.Content,{"data-slot":"dialog-content",className:(0,i.cn)("bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border p-6 shadow-lg duration-200 sm:max-w-lg",e),...c,children:[o,a&&(0,t.jsxs)(r.Close,{"data-slot":"dialog-close",className:"ring-offset-background focus:ring-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",children:[(0,t.jsx)(n.XIcon,{}),(0,t.jsx)("span",{className:"sr-only",children:"Close"})]})]})]})}function u({className:e,...r}){return(0,t.jsx)("div",{"data-slot":"dialog-header",className:(0,i.cn)("flex flex-col gap-2 text-center sm:text-left",e),...r})}function d({className:e,...n}){return(0,t.jsx)(r.Title,{"data-slot":"dialog-title",className:(0,i.cn)("text-lg leading-none font-semibold",e),...n})}function f({className:e,...n}){return(0,t.jsx)(r.Description,{"data-slot":"dialog-description",className:(0,i.cn)("text-muted-foreground text-sm",e),...n})}e.s(["Dialog",()=>o,"DialogContent",()=>c,"DialogDescription",()=>f,"DialogHeader",()=>u,"DialogTitle",()=>d,"DialogTrigger",()=>a])},58249,e=>{"use strict";let t="mh_attribution_first",r="mh_attribution_last";function n(e){try{let t=localStorage.getItem(e);return t?JSON.parse(t):null}catch{return null}}function i(e,t){localStorage.setItem(e,JSON.stringify(t))}function o(){let e=new URLSearchParams(window.location.search),o={utm_source:e.get("utm_source")||void 0,utm_medium:e.get("utm_medium")||void 0,utm_campaign:e.get("utm_campaign")||void 0,utm_term:e.get("utm_term")||void 0,utm_content:e.get("utm_content")||void 0},a=Object.values(o).some(Boolean),s=document.referrer&&new URL(document.referrer).host!==window.location.host?document.referrer:void 0,l=`${window.location.pathname}${window.location.search||""}`,c=Date.now();if(a||s){let e={...o,referrer:s,landing_path:l,timestamp:c};n(t)||i(t,e),i(r,e);return}n(t)||i(t,{referrer:s,landing_path:l,timestamp:c})}function a(){let e=n(t),i=n(r)||e;return{utm_source:i?.utm_source,utm_medium:i?.utm_medium,utm_campaign:i?.utm_campaign,utm_term:i?.utm_term,utm_content:i?.utm_content,referrer:i?.referrer,landing_path:e?.landing_path,first_utm_source:e?.utm_source,first_utm_medium:e?.utm_medium,first_utm_campaign:e?.utm_campaign,first_referrer:e?.referrer}}function s(e,t){if(window.umami){o();let r=a();window.umami.track(e,{...r,...t})}}function l(e){if(window.umami){o();let t=a();window.umami.identify({userId:e.email||e.id,tier:e.tier,...t,...e})}}function c(e,t){s("pageview",{page:e||window.location.pathname,...t})}function u(e,t){s("cta_click",{cta:e,page:t||window.location.pathname})}e.s(["captureAttribution",()=>o,"identifyUser",()=>l,"trackCTAClick",()=>u,"trackEvent",()=>s,"trackPageView",()=>c])},35804,e=>{"use strict";var t=e.i(71645),r=e.i(34620);function n(e){let[n,i]=t.useState(void 0);return(0,r.useLayoutEffect)(()=>
1{if(e){i({width:e.offsetWidth,height:e.offsetHeight});let t=new ResizeObserver(t=>{let r,n;if(!Array.isArray(t)||!t.length)return;let o=t[0];if("borderBoxSize"in o){let e=o.borderBoxSize,t=Array.isArray(e)?e[0]:e;r=t.inlineSize,n=t.blockSize}else r=e.offsetWidth,n=e.offsetHeight;i({width:r,height:n})});return t.observe(e,{box:"border-box"}),()=>t.unobserve(e)}i(void 0)},[e]),n}e.s(["useSize",()=>n])},23750,e=>{"use strict";var t=e.i(43476),r=e.i(47163);function n({className:e,type:n,...i}){return(0,t.jsx)("input",{type:n,"data-slot":"input",className:(0,r.cn)("file:text-foreground placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground dark:bg-input/30 border-input h-9 w-full min-w-0 rounded-md border bg-transparent px-3 py-1 text-base shadow-xs transition-[color,box-shadow] outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm","focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]","aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",e),...i})}e.s(["Input",()=>n])},10708,e=>{"use strict";var t=e.i(43476),r=e.i(71645);e.i(74080);var n=e.i(91918),i=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"].reduce((e,i)=>{let o=(0,n.createSlot)(`Primitive.${i}`),a=r.forwardRef((e,r)=>{let{asChild:n,...a}=e;return"undefined"!=typeof window&&(window[Symbol.for("radix-ui")]=!0),(0,t.jsx)(n?o:i,{...a,ref:r})});return a.displayName=`Primitive.${i}`,{...e,[i]:a}},{}),o=r.forwardRef((e,r)=>(0,t.jsx)(i.label,{...e,ref:r,onMouseDown:t=>{t.target.closest("button, input, select, textarea")||(e.onMouseDown?.(t),!t.defaultPrevented&&t.detail>1&&t.preventDefault())}}));o.displayName="Label";var a=e.i(25913),s=e.i(47163);let l=(0,a.cva)("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),c=r.forwardRef(({className:e,...r},n)=>(0,t.jsx)(o,{ref:n,className:(0,s.cn)(l(),e),...r}));c.displayName=o.displayName,e.s(["Label",()=>c],10708)},63488,e=>{"use strict";let t=(0,e.i(75254).default)("mail",[["path",{d:"m22 7-8.991 5.727a2 2 0 0 1-2.009 0L2 7",key:"132q7q"}],["rect",{x:"2",y:"4",width:"20",height:"16",rx:"2",key:"izxlao"}]]);e.s(["Mail",()=>t],63488)},26330,30207,74606,e=>{"use strict";var t,r=e.i(71645),n=e.i(81140),i=e.i(48425),o=e.i(20783);function a(e){let t=r.useRef(e);return r.useEffect(()=>{t.current=e}),r.useMemo(()=>(...e)=>t.current?.(...e),[])}e.s(["useCallbackRef",()=>a],30207);var s=e.i(43476),l="dismissableLayer.update",c=r.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),u=r.forwardRef((e,u)=>{let{disableOutsidePointerEvents:m=!1,onEscapeKeyDown:p,onPointerDownOutside:h,onFocusOutside:g,onInteractOutside:v,onDismiss:y,...w}=e,x=r.useContext(c),[b,k]=r.useState(null),E=b?.ownerDocument??globalThis?.document,[,j]=r.useState({}),S=(0,o.useComposedRefs)(u,e=>k(e)),C=Array.from(x.layers),[_]=[...x.layersWithOutsidePointerEventsDisabled].slice(-1),N=C.indexOf(_),T=b?C.indexOf(b):-1,A=x.layersWithOutsidePointerEventsDisabled.size>0,R=T>=N,O=function(e,t=globalThis?.document){let n=a(e),i=r.useRef(!1),o=r.useRef(()=>{});return r.useEffect(()=>{let e=e=>{if(e.target&&!i.current){let r=function(){f("dismissableLayer.pointerDownOutside",n,i,{discrete:!0})},i={originalEvent:e};"touch"===e.pointerType?(t.removeEventListener("click",o.current),o.current=r,t.addEventListener("click",o.current,{once:!0})):r()}else t.removeEventListener("click",o.current);i.current=!1},r=window.setTimeout(()=>{t.addEventListener("pointerdown",e)},0);return()=>{window.clearTimeout(r),t.removeEventListener("pointerdown",e),t.removeEventListener("click",o.current)}},[t,n]),{onPointerDownCapture:()=>i.current=!0}}(e=>{let t=e.target,r=[...x.branches].some(e=>e.contains(t));R&&!r&&(h?.(e),v?.(e),e.defaultPrevented||y?.())},E),I=function(e,t=globalThis?.document){let n=a(e),i=r.useRef(!1);return r.useEffect(()=>{let e=e=>{e.target&&!i.current&&f("dismissableLayer.focusOutside",n,{originalEvent:e},{discrete:!1})};return t.addEventListener("focusin",e),()=>t.removeEventListener("focusin",e)},[t,n]),{onFocusCapture:()=>i.current=!0,onBlurCapture:()=>i.current=!1}}(e=>{let t=e.target;![...x.branches].some(e=>e.contains(t))&&(g?.(e),v?.(e),e.defaultPrevented||y?.())},E);return!function(e,t=globalThis?.document){let n=a(e);r.useEffect(()=>{let e=e=>{"Escape"===e.key&&n(e)};return t.addEventListener("keydown",e,{capture:!0}),()=>t.removeEventListener("keydown",e,{capture:!0})},[n,t])}(e=>{T===x.layers.size-1&&(p?.(e),!e.defaultPrevented&&y&&(e.preventDefault(),y()))},E),r.useEffect(()=>{if(b)return m&&(0===x.layersWithOutsidePointerEventsDisabled.size&&(t=E.body.style.pointerEvents,E.body.style.pointerEvents="none"),x.layersWithOutsidePointerEventsDisabled.add(b)),x.layers.add(b),d(),()=>{m&&1===x.layersWithOutsidePointerEventsDisabled.size&&(E.body.style.pointerEvents=t)}},[b,E,m,x]),r.useEffect(()=>()=>{b&&(x.layers.delete(b),x.layersWithOutsidePointerEventsDisabled.delete(b),d())},[b,x]),r.useEffect(()=>{let e=()=>j({});return document.addEventListener(l,e),()=>document.removeEventListener(l,e)},[]),(0,s.jsx)(i.Primitive.div,{...w,ref:S,style:{pointerEvents:A?R?"auto":"none":void 0,...e.style},onFocusCapture:(0,n.composeEventHandlers)(e.onFocusCapture,I.onFocusCapture),onBlurCapture:(0,n.composeEventHandlers)(e.onBlurCapture,I.onBlurCapture),onPointerDownCapture:(0,n.composeEventHandlers)(e.onPointerDownCapture,O.onPointerDownCapture)})});function d(){let e=new CustomEvent(l);document.dispatchEvent(e)}function f(e,t,r,{discrete:n}){let o=r.originalEvent.target,a=new CustomEvent(e,{bubbles:!1,cancelable:!0,detail:r});t&&o.addEventListener(e,t,{once:!0}),n?(0,i.dispatchDiscreteCustomEvent)(o,a):o.dispatchEvent(a)}u.displayName="DismissableLayer",r.forwardRef((e,t)=>
1{let n=r.useContext(c),a=r.useRef(null),l=(0,o.useComposedRefs)(t,a);return r.useEffect(()=>{let e=a.current;if(e)return n.branches.add(e),()=>{n.branches.delete(e)}},[n.branches]),(0,s.jsx)(i.Primitive.div,{...e,ref:l})}).displayName="DismissableLayerBranch",e.s(["DismissableLayer",()=>u],26330);var m=e.i(74080),p=e.i(34620),h=r.forwardRef((e,t)=>{let{container:n,...o}=e,[a,l]=r.useState(!1);(0,p.useLayoutEffect)(()=>l(!0),[]);let c=n||a&&globalThis?.document?.body;return c?m.default.createPortal((0,s.jsx)(i.Primitive.div,{...o,ref:t}),c):null});h.displayName="Portal",e.s(["Portal",()=>h],74606)},41947,e=>{"use strict";let t=(0,e.i(75254).default)("x",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]);e.s(["default",()=>t])},81140,e=>{"use strict";function t(e,r,{checkForDefaultPrevented:n=!0}={}){return function(t){if(e?.(t),!1===n||!t.defaultPrevented)return r?.(t)}}"undefined"!=typeof window&&window.document&&window.document.createElement,e.s(["composeEventHandlers",()=>t])},30030,e=>{"use strict";var t=e.i(71645),r=e.i(43476);function n(e,n){let i=t.createContext(n),o=e=>{let{children:n,...o}=e,a=t.useMemo(()=>o,Object.values(o));return(0,r.jsx)(i.Provider,{value:a,children:n})};return o.displayName=e+"Provider",[o,function(r){let o=t.useContext(i);if(o)return o;if(void 0!==n)return n;throw Error(`\`${r}\` must be used within \`${e}\``)}]}function i(e,n=[]){let o=[],a=()=>{let r=o.map(e=>t.createContext(e));return function(n){let i=n?.[e]||r;return t.useMemo(()=>({[`__scope${e}`]:{...n,[e]:i}}),[n,i])}};return a.scopeName=e,[function(n,i){let a=t.createContext(i),s=o.length;o=[...o,i];let l=n=>{let{scope:i,children:o,...l}=n,c=i?.[e]?.[s]||a,u=t.useMemo(()=>l,Object.values(l));return(0,r.jsx)(c.Provider,{value:u,children:o})};return l.displayName=n+"Provider",[l,function(r,o){let l=o?.[e]?.[s]||a,c=t.useContext(l);if(c)return c;if(void 0!==i)return i;throw Error(`\`${r}\` must be used within \`${n}\``)}]},function(...e){let r=e[0];if(1===e.length)return r;let n=()=>{let n=e.map(e=>({useScope:e(),scopeName:e.scopeName}));return function(e){let i=n.reduce((t,{useScope:r,scopeName:n})=>{let i=r(e)[`__scope${n}`];return{...t,...i}},{});return t.useMemo(()=>({[`__scope${r.scopeName}`]:i}),[i])}};return n.scopeName=r.scopeName,n}(a,...n)]}e.s(["createContext",()=>n,"createContextScope",()=>i])},34620,e=>{"use strict";var t=e.i(71645),r=globalThis?.document?t.useLayoutEffect:()=>{};e.s(["useLayoutEffect",()=>r])},69340,e=>{"use strict";var t=e.i(71645),r=e.i(34620);t[" useEffectEvent ".trim().toString()],t[" useInsertionEffect ".trim().toString()];var n=t[" useInsertionEffect ".trim().toString()]||r.useLayoutEffect;function i({prop:e,defaultProp:r,onChange:i=()=>{},caller:o}){let[a,s,l]=function({defaultProp:e,onChange:r}){let[i,o]=t.useState(e),a=t.useRef(i),s=t.useRef(r);return n(()=>{s.current=r},[r]),t.useEffect(()=>{a.current!==i&&(s.current?.(i),a.current=i)},[i,a]),[i,o,s]}({defaultProp:r,onChange:i}),c=void 0!==e,u=c?e:a;{let r=t.useRef(void 0!==e);t.useEffect(()=>{let e=r.current;if(e!==c){let t=c?"controlled":"uncontrolled";console.warn(`${o} is changing from ${e?"controlled":"uncontrolled"} to ${t}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`)}r.current=c},[c,o])}return[u,t.useCallback(t=>{if(c){let r="function"==typeof t?t(e):t;r!==e&&l.current?.(r)}else s(t)},[c,e,s,l])]}Symbol("RADIX:SYNC_STATE"),e.s(["useControllableState",()=>i],69340)},48425,e=>{"use strict";var t=e.i(71645),r=e.i(74080),n=e.i(20783),i=e.i(43476),o=Symbol("radix.slottable");function a(e){return t.isValidElement(e)&&"function"==typeof e.type&&"__radixId"in e.type&&e.type.__radixId===o}var s=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"].reduce((e,r)=>{var o,s;let l,c,u,d=(s=o=`Primitive.${r}`,(l=t.forwardRef((e,r)=>{let{children:i,...o}=e;if(t.isValidElement(i)){var a;let e,s,l=(a=i,(s=(e=Object.getOwnPropertyDescriptor(a.props,"ref")?.get)&&"isReactWarning"in e&&e.
1isReactWarning)?a.ref:(s=(e=Object.getOwnPropertyDescriptor(a,"ref")?.get)&&"isReactWarning"in e&&e.isReactWarning)?a.props.ref:a.props.ref||a.ref),c=function(e,t){let r={...t};for(let n in t){let i=e[n],o=t[n];/^on[A-Z]/.test(n)?i&&o?r[n]=(...e)=>{let t=o(...e);return i(...e),t}:i&&(r[n]=i):"style"===n?r[n]={...i,...o}:"className"===n&&(r[n]=[i,o].filter(Boolean).join(" "))}return{...e,...r}}(o,i.props);return i.type!==t.Fragment&&(c.ref=r?(0,n.composeRefs)(r,l):l),t.cloneElement(i,c)}return t.Children.count(i)>1?t.Children.only(null):null})).displayName=`${s}.SlotClone`,c=l,(u=t.forwardRef((e,r)=>{let{children:n,...o}=e,s=t.Children.toArray(n),l=s.find(a);if(l){let e=l.props.children,n=s.map(r=>r!==l?r:t.Children.count(e)>1?t.Children.only(null):t.isValidElement(e)?e.props.children:null);return(0,i.jsx)(c,{...o,ref:r,children:t.isValidElement(e)?t.cloneElement(e,void 0,n):null})}return(0,i.jsx)(c,{...o,ref:r,children:n})})).displayName=`${o}.Slot`,u),f=t.forwardRef((e,t)=>{let{asChild:n,...o}=e;return"undefined"!=typeof window&&(window[Symbol.for("radix-ui")]=!0),(0,i.jsx)(n?d:r,{...o,ref:t})});return f.displayName=`Primitive.${r}`,{...e,[r]:f}},{});function l(e,t){e&&r.flushSync(()=>e.dispatchEvent(t))}e.s(["Primitive",()=>s,"dispatchDiscreteCustomEvent",()=>l],48425)},96626,e=>{"use strict";var t=e.i(71645),r=e.i(20783),n=e.i(34620),i=e=>{var i;let a,s,{present:l,children:c}=e,u=function(e){var r,i;let[a,s]=t.useState(),l=t.useRef(null),c=t.useRef(e),u=t.useRef("none"),[d,f]=(r=e?"mounted":"unmounted",i={mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}},t.useReducer((e,t)=>i[e][t]??e,r));return t.useEffect(()=>{let e=o(l.current);u.current="mounted"===d?e:"none"},[d]),(0,n.useLayoutEffect)(()=>{let t=l.current,r=c.current;if(r!==e){let n=u.current,i=o(t);e?f("MOUNT"):"none"===i||t?.display==="none"?f("UNMOUNT"):r&&n!==i?f("ANIMATION_OUT"):f("UNMOUNT"),c.current=e}},[e,f]),(0,n.useLayoutEffect)(()=>{if(a){let e,t=a.ownerDocument.defaultView??window,r=r=>{let n=o(l.current).includes(CSS.escape(r.animationName));if(r.target===a&&n&&(f("ANIMATION_END"),!c.current)){let r=a.style.animationFillMode;a.style.animationFillMode="forwards",e=t.setTimeout(()=>{"forwards"===a.style.animationFillMode&&(a.style.animationFillMode=r)})}},n=e=>{e.target===a&&(u.current=o(l.current))};return a.addEventListener("animationstart",n),a.addEventListener("animationcancel",r),a.addEventListener("animationend",r),()=>{t.clearTimeout(e),a.removeEventListener("animationstart",n),a.removeEventListener("animationcancel",r),a.removeEventListener("animationend",r)}}f("ANIMATION_END")},[a,f]),{isPresent:["mounted","unmountSuspended"].includes(d),ref:t.useCallback(e=>{l.current=e?getComputedStyle(e):null,s(e)},[])}}(l),d="function"==typeof c?c({present:u.isPresent}):t.Children.only(c),f=(0,r.useComposedRefs)(u.ref,(i=d,(s=(a=Object.getOwnPropertyDescriptor(i.props,"ref")?.get)&&"isReactWarning"in a&&a.isReactWarning)?i.ref:(s=(a=Object.getOwnPropertyDescriptor(i,"ref")?.get)&&"isReactWarning"in a&&a.isReactWarning)?i.props.ref:i.props.ref||i.ref));return"function"==typeof c||u.isPresent?t.cloneElement(d,{ref:f}):null};function o(e){return e?.animationName||"none"}i.displayName="Presence",e.s(["Presence",()=>i])},10772,e=>{"use strict";var t=e.i(71645),r=e.i(34620),n=t[" useId ".trim().toString()]||(()=>void 0),i=0;function o(e){let[o,a]=t.useState(n());return(0,r.useLayoutEffect)(()=>{e||a(e=>e??String(i++))},[e]),e||(o?`radix-${o}`:"")}e.s(["useId",()=>o])},43531,78745,e=>{"use strict";let t=(0,e.i(75254).default)("check",[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]]);e.s(["default",()=>t],78745),e.s(["Check",()=>t],43531)},83086,e=>{"use strict";let t=(0,e.i(75254).default)("sparkles",[["path",{d:"M11.017 2.814a1 1 0 0 1 1.966 0l1.051 5.558a2 2 0 0 0 1.594 1.594l5.558 1.051a1 1 0 0 1 0 1.966l-5.558 1.051a2 2 0 0 0-1.594 1.594l-1.051 5.558a1 1 0 0 1-1.966 0l-1.051-5.558a2 2 0 0 0-1.594-1.594l-5.558-1.051a1 1 0 0 1 0-1.966l5.558-1.051a2 2 0 0 0 1.594-1.594z",key:"1s2grr"}],["path",{d:"M20 2v4",key:"1rf3ol"}
1],["path",{d:"M22 4h-4",key:"gwowj6"}],["circle",{cx:"4",cy:"20",r:"2",key:"6kqj1y"}]]);e.s(["Sparkles",()=>t],83086)},84614,e=>{"use strict";let t=(0,e.i(75254).default)("user",[["path",{d:"M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2",key:"975kel"}],["circle",{cx:"12",cy:"7",r:"4",key:"17ys0d"}]]);e.s(["User",()=>t],84614)},67881,91918,25913,e=>{"use strict";var t=e.i(43476),r=e.i(71645),n=e.i(20783),i=Symbol.for("react.lazy"),o=r[" use ".trim().toString()];function a(e){var t;return null!=e&&"object"==typeof e&&"$$typeof"in e&&e.$$typeof===i&&"_payload"in e&&"object"==typeof(t=e._payload)&&null!==t&&"then"in t}function s(e){var i;let s,l=(i=e,(s=r.forwardRef((e,t)=>{let{children:i,...s}=e;if(a(i)&&"function"==typeof o&&(i=o(i._payload)),r.isValidElement(i)){var l;let e,o,a=(l=i,(o=(e=Object.getOwnPropertyDescriptor(l.props,"ref")?.get)&&"isReactWarning"in e&&e.isReactWarning)?l.ref:(o=(e=Object.getOwnPropertyDescriptor(l,"ref")?.get)&&"isReactWarning"in e&&e.isReactWarning)?l.props.ref:l.props.ref||l.ref),c=function(e,t){let r={...t};for(let n in t){let i=e[n],o=t[n];/^on[A-Z]/.test(n)?i&&o?r[n]=(...e)=>{let t=o(...e);return i(...e),t}:i&&(r[n]=i):"style"===n?r[n]={...i,...o}:"className"===n&&(r[n]=[i,o].filter(Boolean).join(" "))}return{...e,...r}}(s,i.props);return i.type!==r.Fragment&&(c.ref=t?(0,n.composeRefs)(t,a):a),r.cloneElement(i,c)}return r.Children.count(i)>1?r.Children.only(null):null})).displayName=`${i}.SlotClone`,s),c=r.forwardRef((e,n)=>{let{children:i,...s}=e;a(i)&&"function"==typeof o&&(i=o(i._payload));let c=r.Children.toArray(i),d=c.find(u);if(d){let e=d.props.children,i=c.map(t=>
1t!==d?t:r.Children.count(e)>1?r.Children.only(null):r.isValidElement(e)?e.props.children:null);return(0,t.jsx)(l,{...s,ref:n,children:r.isValidElement(e)?r.cloneElement(e,void 0,i):null})}return(0,t.jsx)(l,{...s,ref:n,children:i})});return c.displayName=`${e}.Slot`,c}var l=s("Slot"),c=Symbol("radix.slottable");function u(e){return r.isValidElement(e)&&"function"==typeof e.type&&"__radixId"in e.type&&e.type.__radixId===c}e.s(["Slot",()=>l,"createSlot",()=>s],91918);var d=e.i(7670);let f=e=>"boolean"==typeof e?`${e}`:0===e?"0":e,m=d.clsx,p=(e,t)=>r=>{var n;if((null==t?void 0:t.variants)==null)return m(e,null==r?void 0:r.class,null==r?void 0:r.className);let{variants:i,defaultVariants:o}=t,a=Object.keys(i).map(e=>{let t=null==r?void 0:r[e],n=null==o?void 0:o[e];if(null===t)return null;let a=f(t)||f(n);return i[e][a]}),s=r&&Object.entries(r).reduce((e,t)=>{let[r,n]=t;return void 0===n||(e[r]=n),e},{});return m(e,a,null==t||null==(n=t.compoundVariants)?void 0:n.reduce((e,t)=>{let{class:r,className:n,...i}=t;return Object.entries(i).every(e=>{let[t,r]=e;return Array.isArray(r)?r.includes({...o,...s}[t]):({...o,...s})[t]===r})?[...e,r,n]:e},[]),null==r?void 0:r.class,null==r?void 0:r.className)};e.s(["cva",0,p],25913);var h=e.i(47163);let g=p("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-full text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",outline:"border-2 border-foreground
1/20 bg-background hover:bg-primary hover:text-primary-foreground hover:border-primary",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-primary/10 hover:text-primary",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-9 px-4 py-2 has-[>svg]:px-3",sm:"h-8 px-3 has-[>svg]:px-2.5",lg:"h-10 px-6 has-[>svg]:px-4",xl:"h-14 px-10 text-lg font-bold has-[>svg]:px-8 shadow-lg hover:shadow-xl hover:-translate-y-0.5",icon:"size-9","icon-sm":"size-8","icon-lg":"size-10"}},defaultVariants:{variant:"default",size:"default"}});function v({className:e,variant:r,size:n,asChild:i=!1,...o}){return(0,t.jsx)(i?l:"button",{"data-slot":"button",className:(0,h.cn)(g({variant:r,size:n,className:e})),...o})}e.s(["Button",()=>v],67881)},31278,e=>{"use strict";let t=(0,e.i(75254).default)("loader-circle",[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]]);e.s(["Loader2",()=>t],31278)},95468,e=>{"use strict";let t=(0,e.i(75254).default)("circle-check",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]);e.s(["CheckCircle2",()=>t],95468)},30996,e=>{"use strict";var t="mh_access_token",r="mh_refresh_token";function n(){return"undefined"!=typeof document}function i(e){if(!n())return null;for(let t of document.cookie.split(";")){let r=t.trim(),n=r.indexOf("=");if(-1===n)continue;let i=r.substring(0,n),o=r.substring(n+1);if(i===e)try{return decodeURIComponent(o)}catch{return o}}return null}function o(e,t,r){if(!n())return;let i=`${e}=${encodeURIComponent(t)}; Path=/; Max-Age=${r}; SameSite=Lax`;"undefined"!=typeof window&&window.location.hostname.includes("marketinghackers.it")&&(i+="; Domain=.marketinghackers.it; Secure"),document.cookie=i}function a(e,t=0){let r=function(e){try{if(!e)return null;let t=e.split(".");if(3!==t.length)return null;let r=t[1].replace(/-/g,"+").replace(/_/g,"/"),n=r.length%4;2===n?r+="==":3===n&&(r+="=");let i=atob(r),o=JSON.parse(i);if("object"!=typeof o||null===o||"number"!=typeof o.exp)return null;return o}catch{return null}}(e);return!r||Date.now()>=1e3*r.exp-t}var s=null,l={};async function c(e){return s||(s=u(e||l))}async function u(e){try{let s=i(r)||null;if(!s)return null;let l=e.flowstarterUrl||"https://flowstarter-production-d8c9.up.railway.app",c=await fetch(`${l}/core/v1/auth/refresh`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({refresh_token:s})});if(!c.ok)return e.onRefreshError?.(Error(`Refresh failed: ${c.status}`)),null;let u=await c.json();if(u.access_token&&u.refresh_token){var n,a;return n=u.access_token,a=u.refresh_token,o(t,n,2592e3),o(r,a,7776e3),u.access_token,e.onTokenRefreshed?.(u.access_token),u.access_token}return null}catch(t){return e.onRefreshError?.(t instanceof Error?t:Error(String(t))),null}finally{s=null}}function d(e){return async(r,n)=>{let o=n||{},a=f(o.headers);if(!a.has("Authorization")){let e=i(t)||i("mh_auth_token")||null;e&&a.set("Authorization",`Bearer ${e}`)}let s=await fetch(r,{...o,headers:a});if(401===s.status||503===s.status){let t=await c(e);if(t){let e=f(o.headers);return e.set("Authorization",`Bearer ${t}`),fetch(r,{...o,headers:e})}}return s}}function f(e){return e instanceof Headers,new Headers(e)}e.s(["createAuthFetch",()=>d,"isTokenExpired",()=>a])},34462,29863,e=>{"use strict";e.i(47167);let t="mh_auth_token",r="mh_refresh_token",n="mh_user",i="flowstarter_access_token",o="flowstarter_refresh_token",a="flowstarter_user";function s(){return window.location.hostname.includes("marketinghackers.it")}function l(){if(s())return".marketinghackers.it"}function c(e,t,r){if("undefined"==typeof document)return;let n=l(),i=s(),o=`${e}=${encodeURIComponent(t)}; Path=/; Max-Age=${r}; SameSite=Lax`;n&&(o+=`; Domain=${n}`),i&&(o+="; Secure"),document.cookie=o}function u(e){if("undefined"==typeof document)return null;for(let t of document.cookie.split(";")){let r=t.trim(),n=r.indexOf("=");if(-1===n)continue;let i=r.substring(0,n),o=r.substring(n+1);if(i===e)return decodeURIComponent(o)}return null}function d(e){if("undefined"==typeof document)return;let t=l();t&&(document.cookie=`${e}=; Path=/; Domain=${t}; Max-Age=0`),document.cookie=`${e}=; Path=/; Max-Age=0`}function f(e,n){c(t,e,2592e3),c(r,n,7776e3),"undefined"!=typeof localStorage&&(localStorage.setItem(i,e),localStorage.setItem(o,n))}function m(e){let t=JSON.stringify(e);try{c(n,t,2592e3)}catch(e){console.warn("[Auth Cookies] User object troppo grande per cookie, uso solo localStorage")}"undefined"!=typeof localStorage&&localStorage.setItem(a,t)}function p(){let e=u(t);return e||("undefined"!=typeof localStorage?localStorage.getItem(i):null)}function h(){let e=u(r);return e||("undefined"!=typeof localStorage?localStorage.getItem(o):null)}function g(){let e=u(n);if(e)try{return JSON.parse(e)}catch(e){console.warn("[Auth Cookies] Errore parsing user da cookie")}if("undefined"!=typeof localStorage){let e=localStorage.getItem(a);if(e)try{return JSON.parse(e)}catch(e){console.warn("[Auth Cookies] Errore parsing user da localStorage")}}return null}function v(){d(t),d(r),d(n),"undefined"!=typeof localStorage&&(localStorage.removeItem(i),localStorage.removeItem(o),localStorage.removeItem(a))}function y(){if("undefined"==typeof localStorage)return;let e=localStorage.getItem(i),r=u(t);if(e&&!r){let t=localStorage.getItem(o),r=localStorage.getItem(a);if(t&&f(e,t),r)try{m(JSON.parse(r))}catch(e){}}}e.s(["AUTH_TOKEN_COOKIE",0,t,"TOKEN_STORAGE_KEY",0,i,"clearAuthCookies",()=>v,"getAuthToken",()=>p,"getRefreshToken",()=>h,"getStoredUserFromCookie",()=>g,"migrateLocalStorageToCookies",()=>y,"setAuthCookies",()=>f,"setUserCookie",()=>m],29863);let w="flowstarter_access_token",x="flowstarter_token_expiry",b="mh_refresh_lock",k=null,E=!1;function j(){localStorage.removeItem(b)}function S(e){let t=function(e){try{let t=e.split(".");if(3!==t.length)return null;return JSON.parse(atob(t[1]))}catch(e){return console.error("[Auth] Failed to decode JWT:",e),null}}(e);t?.exp&&localStorage.setItem(x,t.exp.toString())}async function C(e=3){let t,r;if(E)return!1;if(t=Date.now(),(r=localStorage.getItem(b))&&JSON.parse(r).timestamp>t-3e4||(localStorage.setItem(b,JSON.stringify({timestamp:t,tabId:Math.random().toString(36).substring(7)})),0)){await new Promise(e=>setTimeout(e,3e3));let e=p()||localStorage.getItem(w);if(e)return S(e),!0}let n=h()||localStorage.getItem("flowstarter_refresh_token");if(!n)return j(),!1;E=!0;let i=null;for(let t=1;t<=e;t++)try{let r=await fetch("/api/auth/refresh-token",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({refresh_token:n})});if(!r.ok){let n=await r.text();if(i=Error(`HTTP ${r.status}: ${n}`),console.error(`[Auth] Refresh failed (attempt ${t}/${e}):`,r.status),401===r.status||403===r.status)return console.error("[Auth] Refresh token invalido, no retry"),E=!1,j(),!1;if(t<e){let e=1e3*Math.pow(2,t-1);await new Promise(t=>setTimeout(t,e));continue}return E=!1,j(),!1}let o=await r.json();if(o.access_token&&o.refresh_token)return f(o.access_token,o.refresh_token),o.user&&m(o.user),S(o.access_token),E=!1,j(),!0;return console.error("[Auth] No tokens in response"),E=!1,j(),!1}catch(r){if(i=r,console.error(`[Auth] Refresh error (attempt ${t}/${e}):`,r.message),t<e){let e=1e3*Math.pow(2,t-1);await new Promise(t=>setTimeout(t,e))}}return console.error("[Auth] ❌ All refresh attempts failed:",i?.message||"Unknown error"),E=!1,j(),!1}async function _(){let e;p()||localStorage.getItem(w)?(e=localStorage.getItem(x))&&parseInt(e,10)<Math.floor(Date.now()/1e3)+1500&&(await C()||(console.error("[Auth] ❌ Token refresh failed, dispatching session-expired event"),v(),localStorage.removeItem(x),window.dispatchEvent(new CustomEvent("session-expired",{detail:{source:"auth-refresh",timestamp:Date.now()}})),N())):N()}function N(){k&&(clearInterval(k),k=null)}function T(e){e&&S(e),k||(_(),k=setInterval(_,12e5))}function A(){N(),localStorage.removeItem(x)}window.addEventListener("storage",e=>{e.key===w&&e.newValue&&S(e.newValue)}),e.s(["cleanupAuthRefresh",()=>A,"initAuthRefresh",()=>T,"tryRefreshToken",()=>C],34462)},38036,e=>{"use strict";var t=e.i(47167),r=e.i(34462),n=e.i(29863),i=e.i(30996);let o="flowstarter_access_token",a="flowstarter_refresh_token",s="flowstarter_user",l=t.default.env.NEXT_PUBLIC_AUTH_URL||"https://auth.marketinghackers.it",c=t.default.env.NEXT_PUBLIC_FLOWSTARTER_API_URL||"https://flowstarter-production-d8c9.up.railway.app/core/v1";function u(){(0,r.cleanupAuthRefresh)(),(0,n.clearAuthCookies)(),localStorage.removeItem(o),localStorage.removeItem(a),localStorage.removeItem(s)}function d(e="login",t){let r=t||window.location.href;window.location.href=`${l}${"signup"===e?"/auth/register":"/auth/login"}?redirect=${encodeURIComponent(r)}`}function f(){return!!(0,n.getAuthToken)()}function m(){return(0,n.getAuthToken)()}function p(){let e=(0,n.getStoredUserFromCookie)();if(e)return e;let t=localStorage.getItem(s);if(!t)return null;try{return JSON.parse(t)}catch{return null}}function h(e){let t=e||window.location.pathname,r=`${l}/auth/register?redirect=${encodeURIComponent(window.location.origin+t)}`;window.location.href=r}function g(){window.location.href=`${l}/auth/dashboard`}function v(){(0,r.cleanupAuthRefresh)(),(0,n.clearAuthCookies)(),localStorage.removeItem(o),localStorage.removeItem(a),localStorage.removeItem(s)}async function y(e){try{let t=await fetch("/api/auth/user",{headers:{Authorization:`Bearer ${e}`,"Content-Type":"application/json"}});if(!t.ok)return null;return await t.json()}catch(e){return console.error("[Auth] Error verifying token:",e),null}}async function w(e){try{let t=await fetch("/api/auth/credits/balance",{headers:{Authorization:`Bearer ${e}`,"Content-Type":"application/json"}});if(!t.ok)return 0;return(await t.json()).credits||0}catch(e){return console.error("[Auth] Error getting credits:",e),
10}}function x(e){return`${l}/auth/register?redirect=${encodeURIComponent(window.location.origin+(e||"/"))}`}async function b(e,t){try{let r=await fetch("/api/auth/login",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:e,password:t})});if(!r.ok){let e=await r.json();throw Error(e.error||"Errore durante il login")}return await r.json()}catch(e){if(e instanceof Error)throw e;throw Error("Errore durante il login")}}async function k(e,t,r,n,i){try{let o=await fetch("/api/auth/signup",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:e,password:t,firstName:r,lastName:n,redirectTo:i})});if(!o.ok){let e=await o.json();throw Error(e.error||"Errore durante la registrazione")}return await o.json()}catch(e){if(e instanceof Error)throw e;throw Error("Errore durante la registrazione")}}async function E(e,t,r="signup"){try{let n=await fetch("/api/auth/verify-otp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:e,token:t,type:r})});if(!n.ok){let e=await n.json();throw Error(e.error||"Errore durante la verifica OTP")}return await n.json()}catch(e){if(e instanceof Error)throw e;throw Error("Errore durante la verifica OTP")}}async function j(e,t="signup"){try{let r=await fetch("/api/auth/resend-otp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:e,type:t})});if(!r.ok){let e=await r.json();throw Error(e.error||"Errore durante il re-invio OTP")}return await r.json()}catch(e){if(e instanceof Error)throw e;throw Error("Errore durante il re-invio OTP")}}async function S(e){try{let t=await fetch("/api/auth/forgot-password",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:e})});return await t.json()}catch(e){if(e instanceof Error)throw e;throw Error("Errore durante la richiesta di reset password")}}async function C(e,t){try{let r=await fetch("/api/auth/reset-password",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({access_token:e,password:t})});if(!r.ok){let e=await r.json();throw Error(e.error||"Errore durante il reset della password")}return await r.json()}catch(e){if(e instanceof Error)throw e;throw Error("Errore durante il reset della password")}}async function _(e,t){try{let r=await fetch("/api/auth/magic-link",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:e,redirectTo:t})});if(!r.ok){let e=await r.json();throw Error(e.error||"Errore durante l'invio del magic link")}return await r.json()}catch(e){if(e instanceof Error)throw e;throw Error("Errore durante l'invio del magic link")}}function N(e,t,i){(0,n.setAuthCookies)(e,t),(0,n.setUserCookie)(i),localStorage.setItem(o,e),localStorage.setItem(a,t),localStorage.setItem(s,JSON.stringify(i));let l=(0,n.getAuthToken)(),c=(0,n.getStoredUserFromCookie)();l&&c||console.error("[Auth] ❌ ERRORE: Token o user non salvati correttamente!"),(0,r.initAuthRefresh)(e)}(0,i.createAuthFetch)({flowstarterUrl:c.replace(/\/core\/v1\/?$/,""),appId:"frontend"}),e.s(["clearAllTokens",()=>u,"forgotPasswordDirect",()=>S,"getAccessToken",()=>m,"getCreditsBalance",()=>w,"getSignupUrl",()=>x,"getStoredUser",()=>p,"isAuthenticated",()=>f,"loginDirect",()=>b,"logout",()=>v,"redirectToAuth",()=>d,"redirectToDashboard",()=>g,"redirectToSignup",()=>h,"resendOtpDirect",()=>j,"resetPasswordDirect",()=>C,"saveTokens",()=>N,"sendMagicLinkDirect",()=>_,"signupDirect",()=>k,"verifyOtpDirect",()=>E,"verifyToken",()=>y])},63209,e=>{"use strict";let t=(0,e.i(75254).default)("circle-alert",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"12",x2:"12",y1:"8",y2:"12",key:"1pkeuh"}],["line",{x1:"12",x2:"12.01",y1:"16",y2:"16",key:"4dfq90"}]]);e.s(["AlertCircle",()=>t],63209)},70756,e=>{"use strict";let t=(0,e.i(75254).default)("lock",[["rect",{width:"18",height:"11",x:"3",y:"11",rx:"2",ry:"2",key:"1w4ew1"}],["path",{d:"M7 11V7a5 5 0 0 1 10 0v4",key:"fwvmzm"}]]);e.s(["Lock",()=>t],70756)},25959,99682,e=>{"use strict";var t=e.i(43476),r=e.i(71645),n=e.i(20783),i=e.i(30030),o=e.i(81140),a=e.i(69340);function s(e){let t=r.useRef({value:e,previous:e});return r.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}e.s(["usePrevious",()=>s],99682);var l=e.i(35804),c=e.i(96626),u=e.i(48425),d="Checkbox",[f,m]=(0,i.createContextScope)(d),[p,h]=f(d);function g(e){let{__scopeCheckbox:n,checked:i,children:o,defaultChecked:s,disabled:l,form:c,name:u,onCheckedChange:f,required:m,value:h="on",internal_do_not_use_render:g}=e,[v,y]=(0,a.useControllableState)({prop:i,defaultProp:s??!1,onChange:f,caller:d}),[w,x]=r.useState(null),[b,k]=r.useState(null),E=r.useRef(!1),S=!w||!!c||!!w.closest("form"),C={checked:v,disabled:l,setChecked:y,control:w,setControl:x,name:u,form:c,value:h,hasConsumerStoppedPropagationRef:E,required:m,defaultChecked:!j(s)&&s,isFormControl:S,bubbleInput:b,setBubbleInput:k};return(0,t.jsx)(p,{scope:n,...C,children:"function"==typeof g?g(C):o})}var v="CheckboxTrigger",y=r.forwardRef(({__scopeCheckbox:e,onKeyDown:i,onClick:a,...s},l)=>{let{control:c,value:d,disabled:f,checked:m,required:p,setControl:g,setChecked:y,hasConsumerStoppedPropagationRef:w,isFormControl:x,bubbleInput:b}=h(v,e),k=(0,n.useComposedRefs)(l,g),E=r.useRef(m);return r.useEffect(()=>{let e=c?.form;if(e){let t=()=>y(E.current);return e.addEventListener("reset",t),()=>e.removeEventListener("reset",t)}},[c,y]),(0,t.jsx)(u.Primitive.button,{type:"button",role:"checkbox","aria-checked":j(m)?"mixed":m,"aria-required":p,"data-state":S(m),"data-disabled":f?"":void 0,disabled:f,value:d,...s,ref:k,onKeyDown:(0,o.composeEventHandlers)(i,e=>{"Enter"===e.key&&e.preventDefault()}),onClick:(0,o.composeEventHandlers)(a,e=>{y(e=>!!j(e)||!e),b&&x&&(w.current=e.isPropagationStopped(),w.current||e.stopPropagation())})})});y.displayName=v;var w=r.forwardRef((e,r)=>{let{__scopeCheckbox:n,name:i,checked:o,defaultChecked:a,required:s,disabled:l,value:c,onCheckedChange:u,form:d,...f}=e;return(0,t.jsx)(g,{__scopeCheckbox:n,checked:o,defaultChecked:a,disabled:l,required:s,onCheckedChange:u,name:i,form:d,value:c,internal_do_not_use_render:({isFormControl:e})=>(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(y,{...f,ref:r,__scopeCheckbox:n}),e&&(0,t.jsx)(E,{__scopeCheckbox:n})]})})});w.displayName=d;var x="CheckboxIndicator",b=r.forwardRef((e,r)=>{let{__scopeCheckbox:n,forceMount:i,...o}=e,a=h(x,n);return(0,t.jsx)(c.Presence,{present:i||j(a.checked)||!0===a.checked,children:(0,t.jsx)(u.Primitive.span,{"data-state":S(a.checked),"data-disabled":a.disabled?"":void 0,...o,ref:r,style:{pointerEvents:"none",...e.style}})})});b.displayName=x;var k="CheckboxBubbleInput",E=r.forwardRef(({__scopeCheckbox:e,...i},o)=>{let{control:a,hasConsumerStoppedPropagationRef:c,checked:d,defaultChecked:f,required:m,disabled:p,name:g,value:v,form:y,bubbleInput:w,setBubbleInput:x}=h(k,e),b=(0,n.useComposedRefs)(o,x),E=s(d),S=(0,l.useSize)(a);r.useEffect(()=>{if(!w)return;let e=Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype,"checked").set,t=!c.current;if(E!==d&&e){let r=new Event("click",{bubbles:t});w.indeterminate=j(d),e.call(w,!j(d)&&d),w.dispatchEvent(r)}},[w,E,d,c]);let C=r.useRef(!j(d)&&d);return(0,t.jsx)(u.Primitive.input,{type:"checkbox","aria-hidden":!0,defaultChecked:f??C.current,required:m,disabled:p,name:g,value:v,form:y,...i,tabIndex:-1,ref:b,style:{...i.style,...S,position:"absolute",pointerEvents:"none",opacity:0,margin:0,transform:"translateX(-100%)"}})});function j(e){return"indeterminate"===e}function S(e){return j(e)?"indeterminate":e?"checked":"unchecked"}E.displayName=k;var C=e.i(43531),_=e.i(47163);let N=r.forwardRef(({className:e,...r},n)=>(0,t.jsx)(w,{ref:n,className:(0,_.cn)("peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",e),...r,children:(0,t.jsx)(b,{className:(0,_.cn)("flex items-center justify-center text-current"),children:(0,t.jsx)(C.Check,{className:"h-4 w-4"})})}));N.displayName=w.displayName,e.s(["Checkbox",()=>N],25959)}]);

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.