1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[4386],{15598:(e,t,i)=>{i.d(t,{N:()=>s});var r=i(87358);function s(e,t={}){let i={event:e,at:new Date().toISOString(),...t};"true"===r.env.NEXT_PUBLIC_DEBUG_MODEL_SELECTION&&fetch("/api/debug/model-selection",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify(i)}).catch(()=>{})}},84386:(e,t,i)=>{i.d(t,{nz:()=>b,I:()=>g,Rs:()=>w});var r=i(95155),s=i(12115),n=i(33168),d=i(48151),c=i(56671),a=i(15598);let l="ffc4784b-883e-4dd5-a3b6-55ba8fcdf2a5",o=Date.parse("2026-09-08T15:00:00Z"),u=Date.parse("2026-09-15T15:00:00Z");function h(e){return e===l?u:null}var m=i(87399);let f="svgai_paid_access_cache";function _(){try{window.localStorage.removeItem(f)}catch{}}let p=(0,s.createContext)({creditInfo:null,loading:!0,refreshCredits:async()=>{}});function b({children:e}){let{user:t}=(0,d.A)(),[i,b]=(0,s.useState)(null),[g,w]=(0,s.useState)(!0),v=(0,n.i7)(),y=(0,s.useRef)(!1),S=(0,s.useRef)(null),I=(0,s.useRef)(""),C=(0,s.useRef)(0),A=(0,s.useCallback)(async()=>{if(!t?.id){b(null),w(!1);return}C.current=Date.now();try{if(S.current?.userId!==t.id){let e=function(e){try{let t=window.localStorage.getItem(f);if(!t)return null;let i=JSON.parse(t);if(i?.userId!==e||"boolean"!=typeof i?.value||"number"!=typeof i?.checkedAt||Date.now()-i.checkedAt>=3e5)return null;return{value:i.value,checkedAt:i.checkedAt}}catch{return null}}(t.id);e&&(S.current={userId:t.id,value:e.value,checkedAt:e.checkedAt})}let e=S.current,i=e?.userId===t.id&&null===h(t.id)&&Date.now()-e.checkedAt<3e5,r=i?Promise.resolve({hasPaidModelAccess:e.value}):fetch("/api/auth/user",{credentials:"include"}).then(e=>e.ok?e.json():null).then(e=>{if("boolean"==typeof e?.hasPaidModelAccess){S.current={userId:t.id,value:e.hasPaidModelAccess,checkedAt:Date.now()};var i=t.id,r=e.hasPaidModelAccess;try{window.localStorage.setItem(f,JSON.stringify({userId:i,value:r,checkedAt:Date.now()}))}catch{}}return e}).catch(()=>null),[s,n,d]=await Promise.all([v.from("profiles").select("subscription_tier, subscription_status, lifetime_credits_granted, lifetime_credits_used, monthly_credits, monthly_credits_used").eq("id",t.id).single(),v.from("payment_audit_log").select("id").eq("user_id",t.id).eq("event_type","credit_pack_purchased").limit(1),r]),c=s.data;if(c){let e,r,s,h="active"===c.subscription_status,m=h?Math.max(0,(c.monthly_credits??0)-(c.monthly_credits_used??0)):0,f=Math.max(0,(c.lifetime_credits_granted??0)-(c.lifetime_credits_used??0));h?(e=(c.monthly_credits??0)+(c.lifetime_credits_granted??0),r=(c.monthly_credits_used??0)+(c.lifetime_credits_used??0),s="combined"):(e=c.lifetime_credits_granted??0,r=c.lifetime_credits_used??0,s="lifetime");let _=!!n.data?.length,p=function(e,t=Date.now()){return e===l&&t>=o&&t<u}(t.id),g=!p&&!((c.monthly_credits??0)>0)&&!_,w=p||d?.hasPaidModelAccess===!0||h||(c.monthly_credits??0)>0||_,v=JSON.stringify({userId:t.id,hasOnlyFreeCredits:g,hasPaidModelAccess:w,hasCreditPackPurchase:_,serverPaidAccess:d?.hasPaidModelAccess===!0,isSubscribed:h,monthlyCredits:c.monthly_credits??0});I.current!==v&&(I.current=v,(0,a.N)("credit-context-status",{userId:t.id,hasOnlyFreeCredits:g,hasPaidModelAccess:w,hasCreditPackPurchase:_,purchaseRowsVisibleToClient:n.data?.length??0,serverPaidAccess:d?.hasPaidModelAccess===!0,usedPaidAccessCache:i,isSubscribed:h,monthlyCredits:c.monthly_credits??0,lifetimeCreditsGranted:c.lifetime_credits_granted??0,lifetimeCreditsUsed:c.lifetime_credits_used??0})),b({creditsUsed:r,creditLimit:e,isSubscribed:h,subscriptionTier:c.subscription_tier,creditType:s,creditsRemaining:m+f,monthlyCreditsRemaining:m,lifetimeCreditsRemaining:f,hasOnlyFreeCredits:g,hasPaidModelAccess:w})}}catch(e){console.error("Error fetching credits:",e),C.current=0}finally{w(!1)}},[t?.id,v]);return(0,s.useEffect)(()=>{if(!t?.id){b(null),w(!1),S.current=null;return}A();let e=v.channel(`credit-updates-${t.id}`).on("postgres_changes",{event:"*",schema:"public",table:"profiles",filter:`id=eq.${t.id}`},e=>{A()}).subscribe(),i=()=>{"visible"===document.visibilityState&&(Date.now()-C.current<6e4||A())},r=setInterval(i,3e5);
1return document.addEventListener("visibilitychange",i),()=>{e.unsubscribe(),clearInterval(r),document.removeEventListener("visibilitychange",i)}},[t?.id,A,v]),(0,s.useEffect)(()=>{let e=h(t?.id);if(null===e||e<=Date.now())return;let i=setTimeout(()=>{S.current=null,_(),b(null),A()},e-Date.now());return()=>clearTimeout(i)},[t?.id,A]),(0,s.useEffect)(()=>{let e=()=>{A()},t=()=>{S.current=null,_(),A(),setTimeout(A,1e3),setTimeout(A,3e3)};return window.addEventListener("creditUsed",e),window.addEventListener("creditPurchased",t),()=>{window.removeEventListener("creditUsed",e),window.removeEventListener("creditPurchased",t)}},[A]),(0,s.useEffect)(()=>{if(t?.id&&!g&&!y.current&&i&&!(i.creditLimit>0)&&!i.isSubscribed){if(t?.user_metadata?.signup_bonus_suppressed_reason===m.Tf){y.current=!0;return}!function(){try{return"true"===window.localStorage.getItem("svgai_i2s_wallet_pending_claim")||"true"===window.localStorage.getItem(m.J9)}catch{return!1}}()&&(y.current=!0,(async()=>{try{let e=await fetch("/api/auth/signup-bonus",{method:"POST"}),t=await e.json();if(t.success&&t.creditsGranted>0){await A(),"/"===window.location.pathname||window.location.pathname;let e=document.getElementById("prompt-input");try{let e=localStorage.getItem("svgai_pending_prompt");if(e){let t=JSON.parse(e);t?.prompt}}catch{}c.toast.success(`ð You got ${t.creditsGranted} free credits! Hit Generate to start creating.`,{id:"missed-bonus-toast",duration:8e3,style:{background:"#FFFFFF",color:"#1D1D1F",border:"1px solid rgba(255, 112, 67, 0.3)",borderLeft:"3px solid #FF7043",borderRadius:"10px",padding:"12px 16px",boxShadow:"0 4px 16px rgba(0, 0, 0, 0.08)",fontSize:"14px",fontWeight:"500"}}),e&&setTimeout(()=>{e.scrollIntoView({behavior:"smooth",block:"center"}),e.focus()},300)}}catch(e){console.error("[CreditContext] Failed to grant missed signup bonus:",e)}})())}},[t?.id,g,i,A]),(0,r.jsx)(p.Provider,{value:{creditInfo:i,loading:g,refreshCredits:A},children:e})}let g=()=>{let e=(0,s.useContext)(p);if(!e)throw Error("useCredits must be used within a CreditProvider");return e},w=()=>{let{creditInfo:e,loading:t}=g();return{tier:e?.isSubscribed?e?.subscriptionTier:null,isSubscribed:e?.isSubscribed??!1,loading:t}}}}]);
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.