1import{r as t,m as A,j as m}from"./index-BK9u03Am.js";import{a as O,e as x,bn as w,bo as h,d as g,bp as D,aw as R,bq as j,br as _,bj as b,s as N,av as I}from"./App-CRqYhtM-.js";import{m as E,I as k}from"./IOSIntroOfferDialog-D-fuLme2.js";import{P as Y}from"./PostSignupOffer-D5kt7iy9.js";import"./nativeFeatures-8CAKl5G9.js";import"./dialog-BcfePVha.js";import"./use-toast-BtjjYtIt.js";import"./PayPalPayLaterMessage-C1uUUteg.js";import"./clock-B6eSEj5R.js";const z=()=>{const a=O(),{user:r,loading:c}=x(),s=A,[f,o]=t.useState(!1),[v,T]=t.useState(!1),[P,d]=t.useState(!1),S=t.useRef(!1),[l,y]=t.useState(!1),n=t.useRef(!1);t.useEffect(()=>{if(!s)return;let e=!1;const u=window.setTimeout(()=>{e||(w(),h(),g.error("The App Store offer couldn't open",{description:"You can retry from Plans when you're ready."}),a(r?"/pricing":"/auth",{replace:!0}))},8e3);return(async()=>{if(await D(),!e){try{await R()}catch(p){console.warn("[Trial] IAP warm-up failed",p)}e||(window.clearTimeout(u),T(!0))}})(),()=>{e=!0,window.clearTimeout(u)}},[s,a,r]),t.useEffect(()=>{let e=!1;try{e=sessionStorage.getItem("parsent_trial_armed")==="1"}catch{}if(!e){j();try{sessionStorage.setItem("parsent_trial_armed","1"),sessionStorage.removeItem("parsent_offer_dismissed")}catch{}}},[]),t.useEffect(()=>{if(!(!s||c||l||_())){if(!r){try{sessionStorage.setItem("parsent_pending_trial","1")}catch{}a("/auth",{replace:!0});return}if(v){if(b()){(async()=>{const{data:e}=await N.from("profiles").select("subscription_plan").eq("id",r.id).maybeSingle();if(((e==null?void 0:e.subscription_plan)??"free")==="free"){o(!0);return}w(),h(),n.current=!0,y(!0),o(!1),g.success("You're subscribed to Pro",{description:"Your Pro access is ready."}),a("/dashboard",{replace:!0})})();return}o(!0)}}},[s,c,r,a,l,v]),t.useEffect(()=>{if(s||S.current)return;S.current=!0;const e=navigator.userAgent||"";if(!/iPhone|iPad|iPod|Android/i.test(e))return;const p=Date.now();try{window.location.href="parsent://trial"}catch{}window.setTimeout(()=>{document.hidden||n.current||Date.now()-p<1200||d(!0)},1400)},[s]),t.useEffect(()=>{if(s||c||l||_())return;const e=navigator.userAgent||"";if(!/iPhone|iPad|iPod|Android/i.test(e)){if(!r){try{sessionStorage.setItem("parsent_pending_trial","1")}catch{}a("/auth",{replace:!0});return}d(!0)}},[s,c,r,a,l]),t.useEffect(()=>{if(r)try{sessionStorage.removeItem("parsent_pending_trial")}catch{}},[r]);const i=t.useCallback(()=>{if(!n.current){n.current=!0,y(!0),w(),h(),o(!1),d(!1),(b()||I())&&g.success("You're subscribed to Pro",{description:"Your Pro access is ready."});try{sessionStorage.removeItem("parsent_pending_trial"),sessionStorage.setItem("parsent_offer_dismissed","1")}catch{}a(r?"/dashboard":"/auth",{replace:!0}),window.setTimeout(()=>{window.location.pathname.startsWith("/trial")&&window.location.replace(r?"/dashboard":"/auth")},400)}},[a,r]);return t.useEffect(()=>{const e=()=>{E(),i()};return window.addEventListener("parsent:subscription-updated",e),()=>window.removeEventListener("parsent:subscription-updated",e)},[i]),t.useEffect(()=>{if(!s||!f)return;const e=window.setInterval(()=>{(b()||I())&&(E(),i())},300);return()=>window.clearInterval(e)},[s,f,i]),m.jsxs("div",{className:"min-h-screen bg-[hsl(var(--editorial-cream))]",children:[f&&m.jsx(k,{open:f,onOpenChange:e=>{e?n.current||o(!0):i()},onPurchased:i}),P&&m.jsx(Y,{open:P,onOpenChange:e=>{e?n.current||d(!0):i()}})]})};export{z 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.