1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[26566],{23439:(e,t,r)=>{r.d(t,{dbService:()=>i});let i=r(35475).u},26566:(e,t,r)=>{r.d(t,{Y:()=>u,c:()=>p});var i=r(95155),a=r(12115),s=r(56556),n=r(23439),o=r(34853),c=r(57872),l=r(60080);let d=(0,a.createContext)(void 0);function p(e){let{children:t}=e,{user:r}=(0,s.A)(),[p,u]=(0,a.useState)(null),[m,_]=(0,a.useState)(null),[h,f]=(0,a.useState)(!0),[y,w]=(0,a.useState)(null),[b,P]=(0,a.useState)(!1),[k,v]=(0,a.useState)(null),[g,I]=(0,a.useState)(null),[A,M]=(0,a.useState)(!1),[S,C]=(0,a.useState)(!1),[j,F]=(0,a.useState)(null),E=(0,a.useCallback)(async()=>{if(!r){u(null),f(!1),P(!1);return}if(j!==r.uid||!p)try{f(!0),w(null);let[e,t]=await Promise.all([fetch("/api/admin/check-superuser"),n.dbService.getUserUsage(r.uid)]),i=!1;if(i=e.ok?(await e.json()).isAdmin||!1:await o.AdminService.isUserAdmin(r.uid),P(i),u(t),t&&t.plan)try{let e=await fetch("/api/subscription-plans?include=".concat(encodeURIComponent(t.plan)));if(e.ok){let r=(await e.json()).plans||[],i=r.find(e=>e.plan_key===t.plan);i||(i=r.find(e=>{var r;return e.id===t.plan||(null==(r=e.name)?void 0:r.toLowerCase())===t.plan})),_(i)}}catch(e){console.error("Failed to fetch plan details:",e),_(null)}F(r.uid)}catch(e){w(e instanceof Error?e:Error("Failed to fetch usage"))}finally{f(!1)}},[r,j,p]),x=(0,a.useCallback)(async()=>{if(!r)return null;try{let e=await n.dbService.getUserUsage(r.uid);if(u(e),e&&e.plan)try{let t=await fetch("/api/subscription-plans?include=".concat(encodeURIComponent(e.plan)));if(t.ok){let r=(await t.json()).plans||[],i=r.find(t=>t.plan_key===e.plan);i||(i=r.find(t=>{var r;return t.id===e.plan||(null==(r=t.name)?void 0:r.toLowerCase())===e.plan})),_(i)}}catch(e){console.error("Failed to fetch plan details:",e),_(null)}return await n.dbService.syncUserProjectCount(r.uid),e}catch(e){return w(e instanceof Error?e:Error("Failed to refresh usage")),null}},[r]),R=(0,a.useCallback)(async e=>{if(r)try{await n.dbService.updateUserSubscription(r.uid,e),await x()}catch(e){throw e}},[r,x]),U=(0,a.useCallback)(async()=>{if(!r)return!1;try{let e=await fetch("/api/stripe/sync-subscription",{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer nextauth-session"}}),t=await e.json();if(t.synced&&t.plan){if((null==p?void 0:p.subscriptionOverride)&&(!p.overrideExpiresAt||new Date(p.overrideExpiresAt)>new Date))return!1;if(t.shouldCleanup)return await n.dbService.updateUserSubscription(r.uid,{plan:"free",subscriptionStatus:"canceled"}),await x(),!0;let e=p?p.plan!==t.plan:"free"!==t.plan,i=p?p.stripeCustomerId!==t.stripeCustomerId:!!t.stripeCustomerId,a=p?p.stripeSubscriptionId!==t.stripeSubscriptionId:!!t.stripeSubscriptionId,s=p?p.subscriptionStatus!==t.subscriptionStatus:"inactive"!==t.subscriptionStatus,o=(()=>{let e=null==p?void 0:p.paymentMethod,r=t.paymentMethod;return p?(!!e||!!r)&&(!e||!r||e.type!==r.type||(e.card&&r.card?e.card.brand!==r.card.brand||e.card.last4!==r.card.last4||e.card.exp_month!==r.card.exp_month||e.card.exp_year!==r.card.exp_year:!!e.card||!!r.card)):!!r})();if(!e&&!i&&!a&&!s&&!o)return!0;{await n.dbService.updateUserSubscription(r.uid,{plan:t.plan,stripeCustomerId:t.stripeCustomerId,stripeSubscriptionId:t.stripeSubscriptionId,subscriptionStatus:t.subscriptionStatus,currentPeriodStart:t.currentPeriodStart?new Date(t.currentPeriodStart):void 0,currentPeriodEnd:t.currentPeriodEnd?new Date(t.currentPeriodEnd):void 0,paymentMethod:t.paymentMethod});let e=(null==p?void 0:p.plan)||"free";if(e!==t.plan)if("free"!==e&&p||"free"===t.plan)"free"!==e&&"free"!==t.plan&&(0,l.$s)({type:"subscription_plan_changed",fromPlan:e,toPlan:t.plan});else{let e=Object.values(c.ND).find(e=>e.id===t.plan);(0,l.$s)({type:"subscription_started",plan:t.plan,value:(null==e?void 0:e.price)||0})}return await x(),!0}}return!1}catch(e){return!1}},[null==r?void 0:r.uid,null==p?void 0:p.plan,null==p?void 0:p.stripeCustomerId]),T=(0,a.useCallback)(async()=>{if(r&&null===k&&!A)try{M(!0);let e=await n.dbService.getUserProjects(r.uid);v(e)}catch(e){console.error("Failed to load projects:",e)}finally{M(!1)}},[r,k,A]),D=(0,a.useCallback)(async()=>
1{if(r&&null===g&&!S)try{C(!0);let e=await n.dbService.getUserArticles(r.uid);I(e)}catch(e){console.error("Failed to load articles:",e)}finally{C(!1)}},[r,g,S]),L=(0,a.useCallback)(async()=>{if(r)try{M(!0);let e=await n.dbService.getUserProjects(r.uid);v(e)}catch(e){console.error("Failed to refresh projects:",e)}finally{M(!1)}},[r]),q=(0,a.useCallback)(async()=>{if(r)try{C(!0);let e=await n.dbService.getUserArticles(r.uid);I(e)}catch(e){console.error("Failed to refresh articles:",e)}finally{C(!1)}},[r]);return(0,a.useEffect)(()=>{(null==r?void 0:r.uid)?E():(u(null),f(!1),P(!1),F(null),v(null),I(null))},[null==r?void 0:r.uid,E]),(0,i.jsx)(d.Provider,{value:{usage:p,planDetails:m,loading:h,error:y,isAdmin:b,projects:k,articles:g,projectsLoading:A,articlesLoading:S,refreshUsage:x,syncWithStripe:U,updateUserSubscription:R,loadProjects:T,loadArticles:D,refreshProjects:L,refreshArticles:q},children:t})}function u(){let e=(0,a.useContext)(d);if(void 0===e)throw Error("useUserUsage must be used within a UserUsageProvider");return e}},57872:(e,t,r)=>{r.d(t,{ND:()=>s}),null==(i=r(95704).env.ADMIN_UID)||i.split(",");var i,a=r(95704);let s={free:{name:"Free",price:0,priceId:"",features:{projects:1,articlesPerMonth:2,websiteAnalysisPerMonth:2,keywordsPerAnalysis:50,imagesPerMonth:5,aiCreditsPerMonth:100,unifiedAiCredits:0,seats:1,exportFormats:["text"],cmsIntegrations:!1,backlinkAnalysis:!1,support:"community"}},basic:{name:"Basic",price:19.99,priceFirst100:17.99,priceFirst1000:18.99,priceId:a.env.STRIPE_BASIC_PRICE_ID||"",features:{projects:1,articlesPerMonth:4,websiteAnalysisPerMonth:1,keywordsPerAnalysis:50,imagesPerMonth:4,aiCreditsPerMonth:80,unifiedAiCredits:100,seats:1,exportFormats:["text","markdown","html"],cmsIntegrations:["wordpress"],backlinkAnalysis:!1,support:"email"}},starter:{name:"Starter",price:49.99,priceFirst100:14.99,priceFirst1000:19.99,priceId:a.env.STRIPE_STARTER_PRICE_ID,features:{projects:1,articlesPerMonth:10,websiteAnalysisPerMonth:1,keywordsPerAnalysis:200,imagesPerMonth:10,aiCreditsPerMonth:1e3,unifiedAiCredits:250,seats:2,exportFormats:["text","markdown","html"],cmsIntegrations:["webflow","ghost","shopify","wordpress"],backlinkAnalysis:"basic",support:"email"}},pro:{name:"Pro",price:99.99,priceFirst100:39.99,priceFirst1000:49.99,priceId:a.env.STRIPE_PRO_PRICE_ID,features:{projects:3,articlesPerMonth:30,websiteAnalysisPerMonth:6,keywordsPerAnalysis:500,imagesPerMonth:40,aiCreditsPerMonth:500,unifiedAiCredits:750,seats:3,exportFormats:["text","markdown","html","json"],cmsIntegrations:["webflow","ghost","wordpress","shopify"],backlinkAnalysis:"advanced",apiAccess:!0,customModels:!0,support:"email"}},ultimate:{name:"Ultimate",price:189.99,priceFirst100:89.99,priceFirst1000:99.99,priceId:a.env.STRIPE_ULTIMATE_PRICE_ID,features:{projects:5,articlesPerMonth:70,websiteAnalysisPerMonth:10,keywordsPerAnalysis:1e3,imagesPerMonth:100,aiCreditsPerMonth:1e3,unifiedAiCredits:1800,seats:5,exportFormats:["text","markdown","html","json","api"],cmsIntegrations:["ghost","webflow","shopify","wordpress"],backlinkAnalysis:"enterprise",apiAccess:!0,customModels:!0,support:"priority"}},enterprise:{name:"Ultimate",price:189.99,priceFirst100:89.99,priceFirst1000:99.99,priceId:a.env.STRIPE_ULTIMATE_PRICE_ID||a.env.STRIPE_ENTERPRISE_PRICE_ID,features:{projects:5,articlesPerMonth:70,websiteAnalysisPerMonth:10,keywordsPerAnalysis:1e3,imagesPerMonth:100,aiCreditsPerMonth:1e3,unifiedAiCredits:1800,seats:5,exportFormats:["text","markdown","html","json","api"],cmsIntegrations:["ghost","webflow","shopify","wordpress"],backlinkAnalysis:"enterprise",apiAccess:!0,customModels:!0,support:"priority"}},enterprise_500:{name:"Enterprise 500",price:1299.99,priceFirst100:1299.99,priceFirst1000:1299.99,priceId:"price_1SvL2CRTVP5Eq4R40jxBPew5",features:{projects:-1,articlesPerMonth:500,websiteAnalysisPerMonth:100,keywordsPerAnalysis:1e4,imagesPerMonth:800,aiCreditsPerMonth:8e3,unifiedAiCredits:12750,seats:11,exportFormats:["text","markdown","html"],cmsIntegrations:["ghost","webflow","shopify","wordpress","all"],backlinkAnalysis:"enterprise",apiAccess:!0,customModels:!0,support:"dedicated"}},ultimate_plus:{name:"Ultimate+",price:299,priceFirst100:299,priceFirst1000:299,priceId:a.env.STRIPE_ULTIMATE_PLUS_PRICE_ID,features:{projects:-1,articlesPerMonth:120,websiteAnalysisPerMonth:20,keywordsPerAnalysis:2e3,imagesPerMonth:200,aiCreditsPerMonth:2e3,unifiedAiCredits:3050,seats:10,exportFormats:["text","markdown","html","json","api"],cmsIntegrations:["ghost","webflow","shopify","wordpress"],backlinkAnalysis:"enterprise",apiAccess:!0,customModels:!0,support:"priority"}},hbasic:{name:"Basic",price:49.99,priceFirst100:15.99,priceFirst1000:19.99,priceId:a.env.STRIPE_HBASIC_PRICE_ID||"",features:{projects:1,articlesPerMonth:4,websiteAnalysisPerMonth:1,keywordsPerAnalysis:50,imagesPerMonth:4,aiCreditsPerMonth:60,unifiedAiCredits:0,seats:1,exportFormats:["text","markdown","html"],cmsIntegrations:["wordpress"],backlinkAnalysis:!1,support:"email"}},hstarter:{name:"Starter",price:99.99,priceFirst100:39.99,priceFirst1000:49.99,priceId:"price_1SSh46RTVP5Eq4R4KoQ5HqJM",features:{projects:1,articlesPerMonth:10,websiteAnalysisPerMonth:1,keywordsPerAnalysis:200,imagesPerMonth:15,aiCreditsPerMonth:100,unifiedAiCredits:0,seats:2,exportFormats:["text","markdown","html"],cmsIntegrations:["ghost","webflow","wordpress"],backlinkAnalysis:!1,support:"email"}},hpro:{name:"Pro",price:199.99,priceFirst100:79.99,priceFirst1000:99.99,priceId:"price_1SSh4cRTVP5Eq4R4yTWT8EXp",features:{projects:3,articlesPerMonth:30,websiteAnalysisPerMonth:3,keywordsPerAnalysis:500,imagesPerMonth:40,aiCreditsPerMonth:500,unifiedAiCredits:0,seats:3,exportFormats:["text","markdown","html","json"],cmsIntegrations:["ghost","webflow","shopify","wordpress"],backlinkAnalysis:!1,apiAccess:!0,customModels:!0,support:"email"}},henterprise:{name:"Ultimate",price:299.99,priceFirst100:119.99,priceFirst1000:149.99,priceId:"price_1SSh4vRTVP5Eq4R4xkon2T8x",features:{projects:5,articlesPerMonth:70,websiteAnalysisPerMonth:10,keywordsPerAnalysis:1e3,imagesPerMonth:100,aiCreditsPerMonth:1e3,unifiedAiCredits:0,seats:5,exportFormats:["text","markdown","html","json","api"],cmsIntegrations:["ghost","webflow","shopify","wordpress"],backlinkAnalysis:!1,apiAccess:!0,customModels:!0,support:"priority"}},hultimate_plus:{name:"Ultimate+",price:1799.99,priceFirst100:1799.99,priceFirst1000:1799.99,priceId:a.env.STRIPE_HULTIMATE_PLUS_PRICE_ID||"",features:{projects:-1,articlesPerMonth:120,websiteAnalysisPerMonth:20,keywordsPerAnalysis:2e3,imagesPerMonth:200,aiCreditsPerMonth:2e3,unifiedAiCredits:0,seats:3,exportFormats:["text","markdown","html","json","api"],cmsIntegrations:["ghost","webflow","shopify","wordpress"],backlinkAnalysis:"enterprise",apiAccess:!0,customModels:!0,support:"priority"}}}},60080:(e,t,r)=>{function i(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];window.gtag&&window.gtag(...t)}function a(e){if("localhost"!==window.location.hostname&&"127.0.0.1"!==window.location.hostname&&window.gtag)try{switch(e.type){case"sign_up":i("event","sign_up",{method:e.method});break;case"login":i("event","login",{method:e.method});break;case"logout":i("event","logout");break;case"project_created":i("event","project_created",{url:e.url});break;case"analysis_completed":i("event","analysis_completed",{url:e.url,agent_count:e.agentCount,duration_seconds:e.duration});break;case"article_generated":i("event","article_generated",{word_count:e.wordCount,project_id:e.projectId});break;case"article_edited":i("event","article_edited",{article_id:e.articleId});break;case"article_exported":i("event","article_exported",{format:e.format});break;case"article_published":i("event","article_published",{platform:e.platform,article_id:e.articleId,post_id:e.postId});break;case"subscription_started":i("event","purchase",{currency:"USD",value:e.value,items:[{item_id:e.plan,item_name:"".concat(e.plan," subscription"),item_category:"subscription",price:e.value,quantity:1}]});break;case"payment_completed":i("event","payment_completed",{currency:"USD",value:e.amount,plan:e.plan});break;case"feature_used":i("event","feature_used",{feature_name:e.feature,details:e.details});break;case"dashboard_viewed":i("event","page_view",{page_title:"Dashboard",page_location:"/dashboard"});break;case"project_viewed":i("event","view_item",{item_id:e.projectId,item_category:"project"});break;case"pricing_viewed":i("event","view_item_list",{item_list_id:"pricing_plans",item_list_name:"Pricing Plans"});break;case"content_ideas_generated":i("event","feature_used",{feature_name:"generate_more_ideas",project_id:e.projectId,count:e.count});break;case"custom_idea_added":i("event","feature_used",{feature_name:"add_custom_idea",project_id:e.projectId});break;case"content_idea_edited":i("event","feature_used",{feature_name:"edit_content_idea",project_id:e.projectId});break;case"idea_manually_marked":i("event","feature_used",{feature_name:"mark_idea_generated",project_id:e.projectId,marked:e.marked});break;case"content_idea_deleted":i("event","feature_used",{feature_name:"delete_content_idea",project_id:e.projectId});break;case"content_idea_unmarked_as_generated":i("event","feature_used",{feature_name:"unmark_idea_as_generated",project_id:e.projectId,idea_id:e.ideaId});break;case"analysis_error":i("event","exception",{description:"Analysis error: ".concat(e.error),fatal:!1,url:e.url});break;case"api_error":i("event","exception",{description:"API error in ".concat(e.api,": ").concat(e.error),fatal:!1});break;case"page_load_time":i("event","timing_complete",{name:e.page,value:e.duration,event_category:"page_load"});break;case"free_analysis_started":i("event","begin_checkout",{url:e.url,items:[{item_id:"free_analysis",item_name:"Free Website Analysis",item_category:"analysis",price:0,quantity:1}]});break;case"signup_from_analysis":i("event","signup_from_analysis");break;case"subscription_plan_changed":i("event","subscription_plan_changed",{from_plan:e.fromPlan,to_plan:e.toPlan})}}catch(e){console.error("Analytics error:",e)}}function s(e){if("localhost"!==window.location.hostname&&"127.0.0.1"!==window.location.hostname)try{i("event","page_view",{page_path:e,page_title:document.title,page_location:window.location.href})}catch(e){console.error("Analytics page view error:",e)}}r.d(t,{$s:()=>a,oe:()=>s})}}]);
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.