1import{j as e}from"./vendor-motion-hRg_q8lq.js";import{r as _}from"./vendor-react-E98sgxjj.js";import{a as E}from"./vendor-query-bOUN_gKe.js";import{du as B}from"./vendor-fa-Bn2dnpnC.js";import{u as C,a1 as y,M as L,aj as M,A as U,d as w,ak as D,a6 as O,al as Q}from"./index-BKzE8EQ8.js";import{C as v,S as k}from"./SettingsRowCard--YUcmpPt.js";import"./plans-CbMJY2XS.js";import{B as q}from"./BillingStatusBanner-BNsUbBIW.js";import{S as z}from"./Switch-C7QMqTjZ.js";import{u as H,b as W,c as A,d as R,e as $}from"./organization-BuGhuc22.js";import{S as V}from"./SettingsPageShell-wmP4-RpH.js";import"./useLocaleNavigate-BNriJdRU.js";function me(){const{t:n}=C("company"),s=H(),i=s.data;return e.jsx(V,{title:n("billing.pageTitle"),heading:n("billing.heading"),subtitle:n("billing.subtitle"),children:i?e.jsx(G,{org:i}):s.isError?e.jsxs("div",{className:"flex items-center justify-between gap-4 rounded-md border border-border bg-card p-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:n("common.loadFailed")}),e.jsx(v,{tone:"quiet",onClick:()=>s.refetch(),children:n("common.retry")})]}):e.jsx("div",{className:"space-y-4","aria-hidden":!0,children:[0,1,2].map(t=>e.jsx("div",{className:"h-32 animate-pulse rounded-md border border-border bg-card"},t))})})}function G({org:n}){const{t:s,i18n:i}=C("company"),t=(n.billing.currency||"usd").toUpperCase(),l=p=>D(p,t,i.language),o=p=>p?new Date(p).toLocaleDateString(i.language,{year:"numeric",month:"long",day:"numeric"}):null,{status:u,seat_limit:h,price_per_seat_cents:c,current_period_end:m,cancel_at_period_end:a}=n.billing,r=n.billing.plan.charAt(0).toUpperCase()+n.billing.plan.slice(1),b=o(m),g=u!=="comped",x=u==="pending"?s("billing.statusPending"):u==="comped"?s("billing.statusComped"):u==="canceled"?s("billing.statusCanceled"):u==="past_due"?s("billing.statusPastDue"):a&&b?s("billing.endsOn",{date:b}):b?s("billing.renewsOn",{date:b}):s("billing.statusActive"),j=E({mutationFn:L.getBillingPortal,onSuccess:({url:p})=>void U(p),onError:p=>y.error(M(s,p,s("common.somethingWrong")))});return e.jsxs(e.Fragment,{children:[e.jsx(q,{org:n,isAdmin:!0,onBillingPage:!0,className:"mb-8"}),e.jsx("section",{className:"mb-8",children:e.jsx(k,{className:w(u==="past_due"&&"border-destructive/40"),title:s("billing.planTitle",{plan:r,seats:h}),description:x,children:g&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"my-4 h-px bg-border","aria-hidden":!0}),e.jsxs("dl",{className:"grid grid-cols-2 gap-3 sm:grid-cols-3",children:[e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:s("billing.pricePerSeat")}),e.jsx("dd",{className:"text-sm text-foreground",children:s("billing.perMonth",{price:l(c)})})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:s("billing.total")}),e.jsx("dd",{className:"text-sm text-foreground",children:s("billing.perMonth",{price:l(c*h)})})]}),n.billing.billing_email&&e.jsxs("div",{className:"col-span-2 min-w-0 sm:col-span-1",children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:s("billing.billingEmail")}),e.jsx("dd",{className:"truncate text-sm text-foreground",children:n.billing.billing_email})]})]})]})})}),e.jsxs("section",{className:"mb-8",children:[e.jsx("h2",{className:"mb-4 text-lg text-foreground",children:s("billing.seatsHeading")}),e.jsx(J,{org:n,money:l,renewal:b})]}),e.jsxs("section",{className:"mb-8",children:[e.jsx("h2",{className:"mb-4 text-lg text-foreground",children:s("billing.creditsHeading")}),e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx(K,{org:n,money:l}),n.wallet.auto_topup&&e.jsx(X,{autoTopUp:n.wallet.auto_topup,money:l,currency:t})]})]}),g&&e.jsxs("section",{children:[e.jsx("h2",{className:"mb-4 text-lg text-foreground",children:s("billing.paymentHeading")}),e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx(k,{title:s("billing.paymentMethod"),description:n.billing.has_payment_method?s("billing.paymentMethodOnFile"):s("billing.paymentMethodNone"),action:e.jsx(v,{tone:"quiet",onClick:()=>j.mutate(),disabled:j.isPending,children:j.isPending?s("common.opening"):s("billing.managePayment")})}),e.jsx(Y,{money:l})]})]})]})}function J({org:n,money:s,renewal:i}){const{t}=C("company"),{seat_limit:l,seats_used:o,pending_invites:u,status:h,pending_seat_limit:c,price_per_seat_cents:m}=n.billing,[a,r]=_.useState(c??l),[b,g]=_.useState(!1),x=W();_.useEffect(()=>{r(n.billing.pending_seat_limit??n.billing.seat_limit)},[n.billing.seat_limit,n.billing.pending_seat_limit]);const j=h==="active"||h==="past_due",p=Math.max(1,o),P=c??l,N=a!==P,d=a>l,f=a-l,F=()=>{x.mutate(a,{onSuccess:()=>{g(!1),y.success(d?t("seats.added",{seats:a}):t("seats.scheduled",{seats:a}))},onError:S=>{g(!1),y.error(M(t,S,t("common.somethingWrong"),{seats:p}))}})},T=j?N?d?t("seats.increaseNote",{price:s(m*f)}
1):i?t("seats.decreaseNote",{date:i}):t("seats.decreaseNoteNoDate"):c!=null&&i?t("seats.pendingDecrease",{seats:c,date:i}):t("seats.hint",{floor:p}):t(h==="comped"?"seats.comped":"seats.notActive");return e.jsxs(k,{title:t("seats.title",{used:o,limit:l}),description:u>0?t("overview.pendingInvites",{pending:u}):t("seats.description"),children:[e.jsx("div",{className:"my-4 h-px bg-border","aria-hidden":!0}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs("div",{className:"flex items-center rounded-md border border-border",role:"group","aria-label":t("seats.stepper"),children:[e.jsx("button",{type:"button","aria-label":t("seats.decrease"),disabled:!j||a<=p||x.isPending,onClick:()=>r(S=>Math.max(p,S-1)),className:"flex size-9 cursor-pointer items-center justify-center text-muted-foreground transition-colors hover:text-foreground disabled:cursor-not-allowed disabled:opacity-30",children:e.jsx(B,{icon:["far","minus"],className:"text-xs","aria-hidden":!0})}),e.jsx("output",{className:"w-12 text-center text-sm text-foreground","aria-live":"polite",children:a}),e.jsx("button",{type:"button","aria-label":t("seats.increase"),disabled:!j||x.isPending,onClick:()=>r(S=>S+1),className:"flex size-9 cursor-pointer items-center justify-center text-muted-foreground transition-colors hover:text-foreground disabled:cursor-not-allowed disabled:opacity-30",children:e.jsx(B,{icon:["far","plus"],className:"text-xs","aria-hidden":!0})})]}),e.jsx(v,{tone:"secondary",disabled:!j||!N||x.isPending,onClick:()=>d?g(!0):F(),children:x.isPending?t("common.saving"):t("seats.update")}),N&&e.jsx(v,{tone:"quiet",onClick:()=>r(P),disabled:x.isPending,children:t("common.cancel")})]}),e.jsx("p",{className:"mt-3 text-xs text-muted-foreground",children:T}),e.jsx(O,{open:b,onClose:()=>g(!1),locked:x.isPending,title:t("seats.confirmTitle",{delta:f,seats:a}),description:t("seats.confirmBody",{price:s(m*f)}),footer:e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:F,disabled:x.isPending,className:"h-10 cursor-pointer rounded-md bg-foreground px-4 text-sm text-background transition-opacity hover:opacity-85 disabled:opacity-40",children:x.isPending?t("common.saving"):t("seats.confirm",{delta:f})}),e.jsx("button",{type:"button",onClick:()=>g(!1),disabled:x.isPending,className:"h-10 cursor-pointer rounded-md bg-foreground
1/6 px-4 text-sm text-foreground transition-colors hover:bg-foreground/10",children:t("common.cancel")})]})})]})}function K({org:n,money:s}){const{t:i,i18n:t}=C("company"),l=A(),o=l.data??[],[u,h]=_.useState(null),c=o.find(r=>r.bundle_id===u)??o[0]??null,m=E({mutationFn:r=>L.createCreditsCheckout(r.bundle_id),onSuccess:({url:r})=>void U(r),onError:r=>y.error(M(i,r,i("common.somethingWrong")))}),a=n.billing.status!=="pending"&&n.billing.status!=="canceled";return e.jsxs(k,{title:i("credits.title"),description:i("credits.available",{value:n.wallet.total_available.toLocaleString(t.language)}),children:[e.jsx("div",{className:"my-4 h-px bg-border","aria-hidden":!0}),l.isLoading?e.jsx("div",{className:"h-16 animate-pulse rounded-md bg-foreground/10","aria-hidden":!0}):o.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:i("credits.none")}):e.jsxs(e.Fragment,{children:[e.jsx("div",{role:"radiogroup","aria-label":i("credits.title"),className:"grid grid-cols-2 gap-2 sm:grid-cols-4",children:o.map(r=>{const b=c?.bundle_id===r.bundle_id;return e.jsxs("button",{type:"button",role:"radio","aria-checked":b,onClick:()=>h(r.bundle_id),className:w("cursor-pointer rounded-md border p-3 text-left transition-colors",b?"border-accent bg-accent/8":"border-border hover:border-foreground
1/20"),children:[e.jsx("span",{className:"block text-sm text-foreground",children:i("common.creditsCount",{value:r.credits.toLocaleString(t.language)})}),e.jsx("span",{className:"block text-xs text-muted-foreground",children:s(r.amount_cents)})]},r.bundle_id)})}),e.jsxs("div",{className:"mt-4 flex flex-wrap items-center gap-3",children:[e.jsx(v,{tone:"primary",disabled:!c||!a||m.isPending,onClick:()=>c&&m.mutate(c),children:m.isPending?i("common.opening"):c?i("credits.buy",{price:s(c.amount_cents)}):i("credits.buyPlain")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:i(a?"credits.note":"credits.needsBilling")})]})]})]})}const I="h-9 w-full rounded-md border border-border bg-transparent px-3 text-sm text-foreground outline-none transition-colors focus:border-foreground/40 disabled:opacity-50";function X({autoTopUp:n,money:s,currency:i}){const{t,i18n:l}=C("company"),u=A().data??[],h=R(),c=Q(i),m=_.useMemo(()=>({enabled:n.enabled,threshold:String(n.threshold_credits),bundleId:n.bundle_id,limitMajor:String(Math.round(n.monthly_limit_cents/c))}),[n,c]),[a,r]=_.useState(m);_.useEffect(()=>r(m),[m]);const b=a.enabled!==m.enabled||a.threshold!==m.threshold||a.bundleId!==m.bundleId||a.limitMajor!==m.limitMajor,g=Number(a.threshold),x=Number(a.limitMajor),j=Number.isInteger(g)&&g>=0&&Number.isFinite(x)&&x>0&&!!a.bundleId,p=n.status==="paused_payment_failed"||n.status==="paused_cap_reached",P=()=>h.mutate({enabled:a.enabled,threshold_credits:g,bundle_id:a.bundleId,monthly_limit_cents:Math.round(x*c)},{onSuccess:()=>y.success(t("autoTopUp.saved")),onError:d=>y.error(M(t,d,t("common.saveFailed")))}),N=u.find(d=>d.bundle_id===a.bundleId);return e.jsxs(k,{title:e.jsxs("span",{className:"flex items-center gap-2",children:[t("autoTopUp.title"),p&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-xs text-amber-600",children:[e.jsx("span",{className:"size-1.5 rounded-full bg-amber-500","aria-hidden":!0})," ",t(`autoTopUp.${n.status}`)]})]}),description:a.enabled&&N?t("autoTopUp.summary",{credits:N.credits.toLocaleString(l.language),price:s(N.amount_cents),threshold:(Number.isFinite(g)?g:0).toLocaleString(l.language)}):t("autoTopUp.off"),action:e.jsx(z,{checked:a.enabled,onChange:d=>r(f=>({...f,enabled:d})),label:t("autoTopUp.title")}),children:[e.jsx("div",{className:"my-4 h-px bg-border","aria-hidden":!0}),e.jsxs("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-[1fr_1.4fr_1fr]",children:[e.jsxs("label",{className:"flex flex-col gap-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:t("autoTopUp.threshold")}),e.jsx("input",{type:"number",inputMode:"numeric",min:0,step:1e3,value:a.threshold,disabled:!a.enabled,onChange:d=>r(f=>({...f,threshold:d.target.value})),className:I})]}),e.jsxs("label",{className:"flex flex-col gap-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:t("autoTopUp.bundle")}),e.jsxs("span",{className:"relative block",children:[e.jsxs("select",{value:a.bundleId,disabled:!a.enabled||u.length===0,onChange:d=>r(f=>({...f,bundleId:d.target.value}
1)),className:w(I,"cursor-pointer appearance-none pr-9"),children:[u.length===0&&e.jsx("option",{value:a.bundleId,children:a.bundleId}),u.map(d=>e.jsx("option",{value:d.bundle_id,children:t("autoTopUp.bundleOption",{credits:d.credits.toLocaleString(l.language),price:s(d.amount_cents)})},d.bundle_id))]}),e.jsx(B,{icon:["far","chevron-down"],className:"pointer-events-none absolute right-3 top-1/2 -translate-y-1/2 text-xs text-muted-foreground","aria-hidden":!0})]})]}),e.jsxs("label",{className:"flex flex-col gap-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:t("autoTopUp.monthlyLimit",{currency:i})}),e.jsx("input",{type:"number",inputMode:"decimal",min:1,step:50,value:a.limitMajor,disabled:!a.enabled,onChange:d=>r(f=>({...f,limitMajor:d.target.value})),className:I})]})]}),e.jsx("p",{className:"mt-3 text-xs text-muted-foreground",children:t("autoTopUp.spent",{spent:s(n.spent_this_cycle_cents),limit:s(n.monthly_limit_cents)})}),n.last_error&&e.jsx("p",{role:"alert",className:"mt-3 rounded-md border border-amber-500/30 bg-amber-500/8 p-3 text-sm text-foreground",children:t("autoTopUp.lastError",{error:n.last_error})}),b&&e.jsxs("div",{className:"mt-4 flex items-center gap-2",children:[e.jsx(v,{tone:"primary",onClick:P,disabled:!j||h.isPending,children:h.isPending?t("common.saving"):t("common.save")}),e.jsx(v,{tone:"quiet",onClick:()=>r(m),disabled:h.isPending,children:t("common.cancel")}),a.enabled&&e.jsx("p",{className:"text-xs text-muted-foreground",children:t("autoTopUp.consent")})]})]})}function Y({money:n}){const{t:s,i18n:i}=C("company"),t=$(),l=t.data??[];return e.jsx("div",{className:"overflow-x-auto rounded-md border border-border bg-card",children:e.jsxs("table",{className:"w-full min-w-[480px] text-sm",children:[e.jsx("caption",{className:"sr-only",children:s("invoices.heading")}),e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-border text-left",children:[e.jsx("th",{className:"px-4 py-3 text-xs font-normal text-muted-foreground",children:s("invoices.colInvoice")}),e.jsx("th",{className:"px-4 py-3 text-xs font-normal text-muted-foreground",children:s("invoices.colDate")}),e.jsx("th",{className:"px-4 py-3 text-xs font-normal text-muted-foreground",children:s("invoices.colStatus")}),e.jsx("th",{className:"px-4 py-3 text-right text-xs font-normal text-muted-foreground",children:s("invoices.colAmount")}),e.jsx("th",{className:"px-4 py-3",children:e.jsx("span",{className:"sr-only",children:s("invoices.colLinks")})})]})}),e.jsxs("tbody",{children:[t.isLoading&&e.jsx("tr",{children:e.jsx("td",{colSpan:5,className:"p-4",children:e.jsx("div",{className:"h-10 animate-pulse rounded bg-foreground
1/10","aria-hidden":!0})})}),!t.isLoading&&l.length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:5,className:"p-6 text-center text-sm text-muted-foreground",children:s("invoices.none")})}),l.map(o=>e.jsxs("tr",{className:"border-b border-border last:border-0",children:[e.jsx("td",{className:"px-4 py-3 text-foreground",children:o.number??o.id}),e.jsx("td",{className:"whitespace-nowrap px-4 py-3 text-muted-foreground",children:new Date(o.created*1e3).toLocaleDateString(i.language,{year:"numeric",month:"short",day:"numeric"})}),e.jsx("td",{className:"px-4 py-3",children:e.jsx("span",{className:w("text-sm",o.status==="paid"?"text-success":o.status==="open"?"text-amber-500":"text-muted-foreground"),children:s(`invoices.status.${o.status}`,{defaultValue:o.status})})}),e.jsx("td",{className:"px-4 py-3 text-right text-foreground",children:n(o.status==="paid"?o.amount_paid:o.amount_due)}),e.jsxs("td",{className:"whitespace-nowrap px-4 py-3 text-right",children:[o.hosted_invoice_url&&e.jsx("a",{href:o.hosted_invoice_url,target:"_blank",rel:"noopener noreferrer",className:"text-xs text-muted-foreground hover:text-foreground",children:s("invoices.view")}),o.invoice_pdf&&e.jsx("a",{href:o.invoice_pdf,target:"_blank",rel:"noopener noreferrer",className:"ml-3 text-xs text-muted-foreground hover:text-foreground",children:s("invoices.pdf")})]})]},o.id))]})]})})}export{me 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.