1import{f as R}from"./vendor-vue-BIDZeepx.js";import{A as ue}from"./AsyncState-C1wY1NSf.js";import{S as V}from"./SectionHeader-60mU8zeF.js";import{C as $}from"./ChromeCard-DkvfllPh.js";import{C as k}from"./ChromeButton-DmiFifbd.js";import{K as ce}from"./KeyValueGrid-NDsmIuoC.js";import{M as de}from"./MasterDataTable-PTWiW2Qq.js";import"./creatorFieldHelp-BrZsjpkG.js";import"./FieldLabel-DcFbp3Rs.js";import"./DataTable-DiOue6-9.js";import{o as Q,i as ve,k as g,t as pe,v as me,w as fe,_ as ge}from"./index-BNPflmqD.js";import{a as _e,b as H,o as ye,d as ke,s as he}from"./billingApi-ICFi1VZL.js";import{f as be}from"./format-W5H20hG1.js";import{u as we}from"./useAuth-ClVvOQEe.js";import{f as Ce,s as Se}from"./creatorMcpApi-BHO8QA4S.js";import{f as Pe,s as Me}from"./traceApi-BoQZsKq1.js";import{k as Te,r as s,c as B,_ as Be,C as b,D as u,y as t,K as l,Q as c,G as i,z as n,H as m,J as f,B as J,A as Ae,u as A,L as I}from"./vendor-misc-5pJBpqhN.js";import"./useBreakpoint-DOQrj9xp.js";import"./breakpoints-Cr7fi6TV.js";import"./arrow-up-8FIemuBW.js";import"./vendor-utils-CxkvrZ9U.js";import"./vendor-tanstack-B6ELLr_Q.js";import"./vendor-sentry-84cD2ryj.js";async function Ie(){const{data:w}=await Q.get("/usage");return w}async function Le(w){const{data:C}=await Q.post("/usage/overage",{allow_overage:w});return C}const Ee={class:"billing-tab"},xe={class:"card-head"},Ue={key:0,class:"tier-line"},De={key:1,class:"usage-meters"},Fe={class:"usage-meter"},Ne={class:"meter-header"},Oe={class:"meter-bar"},Re={class:"usage-meter"},Ve={class:"meter-header"},$e={class:"meter-bar"},We={key:2,class:"overage-toggle"},ze=["checked","disabled"],Ye={key:1,class:"hint"},Ke={key:2,class:"actions"},Ge={key:2,class:"hint"},He={key:0,class:"actions"},Je={key:1,class:"hint"},Qe={class:"hint",style:{"margin-top":"1rem"}},je={key:2,class:"actions"},qe={key:1,class:"hint"},Xe={key:2,class:"status error"},Ze=["href"],ea={key:1,class:"hint"},aa={key:1,class:"hint"},ta=Te({__name:"AccountBillingTab",setup(w){const{isAdmin:C}=we(),W=ve(),S=s(!0),L=s(null),r=s(null),o=s(null),P=s([]),v=s(""),E=s(!1),x=s(!1),U=s(!1),D=s(!1),d=s(""),p=s(!1),M=s(!1),F=s(!1),_=s(!1),T=s(!1),N=s(!1),j=B(()=>r.value&&["active","trialing","past_due"].includes(r.value.status)&&r.value.plan!=="free"),q=B(()=>r.value&&r.value.stripe_subscription_id&&["active","trialing","past_due"].includes(r.value.status)),X=B(()=>{const e=r.value;return e?[{label:"Plan",value:z(e.plan)},{label:"Status",value:e.status},{label:"Billing",value:fe(e.billing_interval)},{label:"Renews",value:e.current_period_end?Y(e.current_period_end):"â"}]:[]}),Z=[{key:"id",label:"Invoice",minWidth:"10rem"},{key:"status",label:"Status",minWidth:"6rem"},{key:"amount",label:"Amount",align:"right",minWidth:"7rem"},{key:"stripe_url",label:"",sortable:!1}],ee=B(()=>P.value.map(e=>({id:e.stripe_invoice_id,status:e.status,amount:be(Number(e.amount_paid||e.amount_due),e.currency),stripe_url:e.hosted_invoice_url??null})));function z(e){return pe[e]??e}function Y(e){return new Date(e).toLocaleDateString()}function K(e){return e<0?"Unlimited":String(e)}function G(e,a){return a<=0?"0%":a<0?"15%":`${Math.min(100,Math.round(e/a*100))}%`}function ae(e){return e==null?"0":e<10?e.toFixed(2):Math.round(e).toString()}async function te(){x.value=!0,d.value="",p.value=!1;try{const{portal_url:e}=await ye(`${window.location.origin}/account/billing`);window.location.href=e}catch(e){d.value=g(e,"Could not open billing portal"),p.value=!0,x.value=!1}}async function le(){F.value=!0,v.value="";try{const e=await Se();if(e.active){M.value=!0;return}if(e.checkout_url){window.location.href=e.checkout_url;return}v.value="Checkout is not available yet. Please try again shortly."}catch(e){v.value=g(e,"Could not start checkout.")}finally{F.value=!1}}async function ne(){N.value=!0,v.value="";try{const e=await Me();if(e.active){_.value=!0;return}if(e.checkout_url){window.location.href=e.checkout_url;return}v.value="Trace checkout is not available yet. Please try again shortly."}catch(e){v.value=g(e,"Could not start Trace checkout.")}finally{N.value=!1}}async function O(){S.value=!0,L.value=null;try{const[e,a,y]=await Promise.all([_e(),Ie(),H()]);if(r.value=e,o.value=a,P.value=y,W){try{const h=await Ce();M.value=h.active}catch{M.value=!1}try{const h=await Pe();_.value=!!(C.value||h.is_pro||h.active),T.value=h.billing_configured}catch{_.value=!!C.value,T.value=!1}}}catch(e){L.value=g(e,"Failed to load billing")}finally{S.value=!1}}async function se(){await me({title:"Cancel subscription?",message:"You will keep access until the end of the current billing period.",confirmLabel:"Cancel subscription",variant:"danger"})&&await ie()}async function ie(){E.value=!0,d.value="",p.value=!1;try{r.value=await ke(),d.value="Subscription will cancel at period end."}catch(e){d.value=g(e,"Cancel failed"),p.value=!0}finally{E.value=!1}}async function oe(e){const a=e.target.checked;U.value=!0;try{await Le(a),o.value&&(o.value.allow_overage=a)}catch(y){d.value=g(y,"Failed to update overage"),p.value=!0}finally{U.value=!1}}async function re(){D.value=!0;try{await he(),P.value=await H(),d.value="Invoices synced.",p.value=!1}catch(e){d.value=g(e,"Sync failed"),p.value=!0}finally{D.value=!1}}return Be(O),(e,a)=>(t(),b(ue,{loading:S.value,error:L.value,onRetry:O},{default:u(()=>
1[l("div",Ee,[c($,null,{default:u(()=>[l("div",xe,[c(V,{title:"Usage this month","hint-key":"section_billing_usage"}),c(k,{variant:"ghost",loading:S.value,onClick:O},{default:u(()=>[...a[0]||(a[0]=[i("Refresh",-1)])]),_:1},8,["loading"])]),o.value?(t(),n("p",Ue,[a[1]||(a[1]=i(" Tier: ",-1)),l("strong",null,m(z(o.value.tier)),1)])):f("",!0),o.value?(t(),n("div",De,[l("div",Fe,[l("div",Ne,[a[2]||(a[2]=l("span",null,"AI messages",-1)),l("span",null,m(o.value.ai_messages_used)+" / "+m(K(o.value.ai_messages_limit)),1)]),l("div",Oe,[l("div",{class:"meter-fill",style:J({width:G(o.value.ai_messages_used,o.value.ai_messages_limit)})},null,4)])]),l("div",Re,[l("div",Ve,[a[3]||(a[3]=l("span",null,"External data (MCP)",-1)),l("span",null,m(ae(o.value.mcp_credits_used))+" / "+m(K(o.value.mcp_credits_limit??0)),1)]),l("div",$e,[l("div",{class:"meter-fill mcp-fill",style:J({width:G(o.value.mcp_credits_used??0,o.value.mcp_credits_limit??0)})},null,4)]),a[4]||(a[4]=l("p",{class:"hint meter-hint"}," MCP lookups also draw from your AI message pool (3Ã vendor cost). ",-1))])])):f("",!0),o.value&&j.value?(t(),n("label",We,[l("input",{type:"checkbox",checked:o.value.allow_overage,disabled:U.value,onChange:oe},null,40,ze),a[5]||(a[5]=l("span",null,"Continue after limits reached (overage billed at cycle end)",-1))])):f("",!0)]),_:1}),c($,null,{default:u(()=>[c(V,{title:"Subscription","hint-key":"section_billing_subscription"}),r.value?(t(),b(ce,{key:0,items:X.value},null,8,["items"])):(t(),n("p",Ye,"No active paid subscription.")),r.value&&r.value.status!=="canceled"?(t(),n("div",Ke,[q.value?(t(),b(k,{key:0,variant:"primary",loading:x.value,onClick:te},{default:u(()=>[...a[6]||(a[6]=[i(" Manage billing in Stripe ",-1)])]),_:1},8,["loading"])):f("",!0),r.value.cancel_at_period_end?(t(),n("p",Ge," Cancels at period end "+m(r.value.current_period_end?`(${Y(r.value.current_period_end)})`:""),1)):(t(),b(k,{key:1,variant:"secondary",loading:E.value,onClick:se},{default:u(()=>[...a[7]||(a[7]=[i(" Cancel subscription ",-1)])]),_:1},8,["loading"]))])):f("",!0),d.value?(t(),n("p",{key:3,class:Ae(["status",{error:p.value}])},m(d.value),3)):f("",!0)]),_:1}),c($,null,{default:u(()=>[c(V,{title:"Plans","hint-key":"section_upgrade_plan"}),A(W)?(t(),n(I,{key:0},[a[17]||(a[17]=l("p",{class:"hint"},[l("strong",null,"Free"),i(" â platforms, profile, and 30-day revenue summary in Claude. "),l("strong",null,"Pro ($10/mo)"),i(" â tax set-aside, forecasts, audience, content intelligence, and higher MCP limits. ")],-1)),M.value?(t(),n("p",Je," You're on CreatorSense MCP Pro. Manage or cancel via Stripe above. ")):(t(),n("div",He,[c(k,{variant:"primary",loading:F.value,onClick:le},{default:u(()=>[...a[8]||(a[8]=[i(" Upgrade to Pro â $10/mo ",-1)])]),_:1},8,["loading"]),c(A(R),{class:"plan-link",to:"/pricing"},{default:u(()=>[...a[9]||(a[9]=[i("See plan details",-1)])]),_:1})])),l("p",Qe,[a[13]||(a[13]=l("strong",null,"Creator Trace",-1)),a[14]||(a[14]=i(" â Free includes unlimited leak checks, plus 3 accounts / 2 watermarked packages / 2 shares per month. Pro is $30/mo for unlimited watermarking â usually less than one lost PPV. Works alongside your takedown tools. ",-1)),T.value&&!_.value?(t(),n(I,{key:0},[a[11]||(a[11]=i(" Youâre on Free â upgrade from ",-1)),c(A(R),{class:"plan-link",to:"/trace?tab=overview"},{default:u(()=>[...a[10]||(a[10]=[i("Trace",-1)])]),_:1}),a[12]||(a[12]=i(" or below. ",-1))],64)):_.value?(t(),n(I,{key:1},[i(" Pro active on your account. ")],64)):(t(),n(I,{key:2},[i(" Open Trace anytime; Free unlocks when billing is configured. ")],64))]),T.value&&!_.value?(t(),n("div",je,[c(k,{variant:"secondary",loading:N.value,onClick:ne},{default:u(()=>[...a[15]||(a[15]=[i(" Upgrade Trace Pro â $30/mo ",-1)])]),_:1},8,["loading"]),c(A(R),{class:"plan-link",to:"/trace?tab=overview"},{default:u(()=>[...a[16]||(a[16]=[i("Open Trace",-1)])]),_:1})])):f("",!0)],64)):(t(),n("p",qe," Agency desk billing is managed from your organization settings. Creator-plan purchases for the old consumer product are closed. ")),v.value?(t(),n("p",Xe,m(v.value),1)):f("",!0)]),_:1}),P.value.length?(t(),b(de,{key:0,title:"Invoices",description:"Billing history â click column headers to sort","hint-key":"section_billing_invoices","count-label":"invoices",columns:Z,rows:ee.value,"default-sort-key":"id","default-sort-direction":"desc",layout:"table","pagination-item-label":"invoices"},{toolbar:u(()=>[c(k,{variant:"secondary",loading:D.value,onClick:re},{default:u(()=>[...a[18]||(a[18]=[i(" Sync from Stripe ",-1)])]),_:1},8,["loading"])]),"cell-stripe_url":u(({row:y})=>[y.stripe_url?(t(),n("a",{key:0,href:String(y.stripe_url),target:"_blank",rel:"noopener noreferrer",class:"invoice-link"}," View in Stripe â ",8,Ze)):(t(),n("span",ea,"â"))]),_:1},8,["rows"])):(t(),n("p",aa,"No invoices yet."))])]),_:1},8,["loading","error"]))}}),Ma=ge(ta,[["__scopeId","data-v-5f73eca8"]]);export{Ma 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.