1import{j as e,u as b,l as T,a as G,i as P,f as i,I as y,M as I,X as H,B as F,t as d,A as q,E as D,F as K,G as Q,H as w,a7 as L}from"./index-DSiTyxpv.js";import{u as A}from"./useMutation-BycBG2E3.js";import{A as U}from"./AdminShell-VqLKl44q.js";import{L as n}from"./label-DzUMiUcn.js";import{T as O}from"./textarea-BQIzAQg9.js";import{B as S}from"./badge-BKdawzle.js";import{l as V,u as X,d as Y,e as Z}from"./subscriptions.functions-CHdCHh64.js";import{g as z}from"./stripe-CBinWMKy.js";import{f as J,a as W,t as $}from"./currency-DmQQPc2J.js";import{S as ee}from"./save-DZcUCRIE.js";import{T as se}from"./trash-2-DCKu4tqb.js";import"./role-gate-DE48EPzw.js";import"./use-roles-CA1J5NUk.js";import"./use-dashboard-path-D9nru0DR.js";import"./signed-in-gate-BpL0bbTF.js";import"./utensils-BC8827JD.js";import"./user-plus-CXIXrPhd.js";import"./alert-dialog-BjFFe65d.js";import"./DashSidebar-BK7T9nIo.js";import"./log-out--d-8yuAz.js";import"./layout-dashboard-dwmy3Ypt.js";import"./shopping-bag-C4mcVzSF.js";import"./store-BWBtOHHL.js";import"./wallet-coqZuvaq.js";import"./bike-hcMpPwjx.js";import"./truck-B8xSk7jT.js";import"./users-CfWodDMd.js";import"./star-DC8NXup-.js";import"./briefcase-DoWVCsnR.js";import"./house-CwHeec2k.js";import"./settings-BUV7MxKC.js";import"./mail-Cyccx2YA.js";import"./credit-card-V5VKnqKS.js";import"./scroll-text-CiSoEymb.js";import"./crown-B0A422P9.js";import"./percent-DMpu5-cu.js";import"./webhook-CGJdHhS_.js";import"./key-round-C0YBT1js.js";import"./activity-CSkDe4qN.js";import"./index-DXygAoiy.js";const te=["USD","EUR","GBP","NGN","GHS","KES","ZAR","XAF","XOF"];function re(){const t=b(V),u=b(X),c=T(),{data:m,isLoading:x}=G({queryKey:["admin-plans"],queryFn:()=>t()}),o=A({mutationFn:r=>u({data:r}),onSuccess:()=>{d.success("Plan saved"),c.invalidateQueries({queryKey:["admin-plans"]}),c.invalidateQueries({queryKey:["subscription-plans"]})},onError:r=>d.error(r?.message??"Save failed")});if(x)return e.jsx("div",{className:"flex justify-center py-20",children:e.jsx(P,{className:"h-6 w-6 animate-spin text-muted-foreground"})});const p=m?.plans??[],h=m?.prices??[];return e.jsxs("div",{className:"mx-auto max-w-5xl px-6 py-8",children:[e.jsx("h1",{className:"text-2xl font-bold tracking-tight",children:"Subscription plans"}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Edit plan names, descriptions, features, trial periods, and per-currency prices. Adding a price automatically creates the matching recurring price in Stripe."}),e.jsx("div",{className:"mt-8 grid gap-6 md:grid-cols-2 xl:grid-cols-3",children:p.map(r=>e.jsx(ae,{plan:r,prices:h.filter(l=>l.plan_id===r.id),onSave:l=>o.mutate(l),saving:o.isPending},r.id))})]})}function ae({plan:t,prices:u,onSave:c,saving:m}){const[x,o]=i.useState(t.name),[p,h]=i.useState(t.description??""),[r,l]=i.useState(t.features??[]),[j,v]=i.useState(""),[N,C]=i.useState(t.trial_days??0),[s,g]=i.useState(t.is_active),[f,B]=i.useState(t.highlight),[k,M]=i.useState(t.sort_order??0),E=()=>{j.trim()&&(l([...r,j.trim()]),v(""))};return e.jsxs("div",{className:"rounded-2xl border bg-card p-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold",children:t.name}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["code: ",t.code]})]}),e.jsxs("div",{className:"flex gap-2 items-center",children:[f&&e.jsx(S,{children:"Highlighted"}),!s&&e.jsx(S,{variant:"outline",children:"Inactive"})]})]}),e.jsxs("div",{className:"mt-4 grid gap-4 md:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx(n,{children:"Display name"}),e.jsx(y,{value:x,onChange:a=>o(a.target.value)})]}),e.jsxs("div",{children:[e.jsx(n,{children:"Sort order"}),e.jsx(y,{type:"number",value:k,onChange:a=>M(parseInt(a.target.value)||0)})]}),e.jsxs("div",{className:"md:col-span-2",children:[e.jsx(n,{children:"Description"}),e.jsx(O,{value:p,onChange:a=>h(a.target.value),rows:2})]}),e.jsxs("div",{children:[e.jsx(n,{children:"Free trial (days)"}),e.jsx(y,{type:"number",min:0,max:365,value:N,onChange:a=>C(parseInt(a.target.value)||0)}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Set to 7 for a 7-day trial; 0 to disable."})]}),e.jsxs("div",{className:"flex gap-6 items-end",children:[e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx(n,{className:"text-xs",children:"Active"}),e.jsx(I,{checked:s,onCheckedChange:g})]}),e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx(n,{className:"text-xs",children:"Most popular"}),e.jsx(I,{checked:f,onCheckedChange:B})]})]})]}),e.jsxs("div",{className:"mt-4",children:[e.jsx(n,{children:"Features"}),e.jsx("div",{className:"mt-2 flex flex-wrap gap-2",children:r.map((a,_)=>e.jsxs(S,{variant:"secondary",className:"gap-1",children:[a,e.jsx("button",{onClick:()=>l(r.filter((ne,R)=>R!==_)),children:e.jsx(H,{className:"h-3 w-3"})})]},_))}),e.jsxs("div",{className:"mt-2 flex gap-2",children:[e.jsx(y,{placeholder:"Add a featureâ¦",value:j,onChange:a=>v(a.target.value),onKeyDown:a=>a.key==="Enter"&&(a.preventDefault(),E())}),e.jsx(F,{type:"button",variant:"outline",onClick:E,children:"Add"})]})]}),e.jsxs("div",{className:"mt-4",children:[e.jsx(n,{children:"Prices"}),e.jsx(ie,{planId:t.id,prices:u})]}),e.jsx("div",{className:"mt-6 flex justify-end",children:e.jsx(F,{onClick:()=>c({id:t.id,code:t.code,name:x,description:p,features:r,trial_days:N,sort_order:k,is_active:s,highlight:f}),disabled:m,children:m?e.jsx(P,{className:"h-4 w-4 animate-spin"}):e.jsxs(e.Fragment,{children:[e.jsx(ee,{className:"h-4 w-4 mr-2"}),"Save"]})})})]})}function ie({planId:t,prices:u}){const c=T(),m=b(Y),x=b(Z),[o,p]=i.useState("USD"),[h,r]=i.useState("month"),[l,j]=i.useState(""),v=A({mutationFn:s=>m({data:s}),onSuccess:s=>{if(s?.ok===!1||s?.error){d.error(s?.error??"Could not create price");return}d.success("Price created and synced to Stripe"),j(""),c.invalidateQueries({queryKey:["admin-plans"]}),c.invalidateQueries({queryKey:["subscription-plans"]})},onError:s=>d.error(s?.message??"Failed")}),N=A({mutationFn:s=>x({data:{id:s}}),onSuccess:()=>{d.success("Price deactivated"),c.invalidateQueries({queryKey:["admin-plans"]}),c.invalidateQueries({queryKey:["subscription-plans"]})}}),C=()=>{const s=parseFloat(l||"0"),g=$(s,o);if(!g||g<50){d.error("Enter a valid amount (minimum 0.50)");return}try{v.mutate({plan_id:t,currency:o,interval:h,amount_minor:g,environment:z()})}catch(f){d.error(f?.message??"Stripe is not configured for this build")}};return e.jsxs("div",{className:"mt-2 space-y-2",children:[e.jsxs("div",{className:"grid gap-2 text-sm",children:[u.length===0&&e.jsx("p",{className:"text-xs text-muted-foreground italic",children:"No prices yet â add the first one below."}),u.map(s=>e.jsxs("div",{className:"flex items-center justify-between rounded-md border bg-muted/30 px-3 py-2",children:[e.jsxs("span",{children:[s.currency," · ",s.interval,!s.is_active&&e.jsx(S,{variant:"outline",className:"ml-2",children:"inactive"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"font-medium",children:J(W(s.amount_minor,s.currency),s.currency)}),e.jsx("button",{type:"button",className:"text-muted-foreground hover:text-destructive",onClick:()=>N.mutate(s.id),"aria-label":"Deactivate price",children:e.jsx(se,{className:"h-4 w-4"})})]})]},s.id))]}),e.jsxs("div",{className:"flex flex-wrap items-end gap-2 pt-3 border-t",children:[e.jsxs("div",{className:"w-28",children:[e.jsx(n,{className:"text-xs",children:"Currency"}),e.jsxs(q,{value:o,onValueChange:p,children:[e.jsx(D,{children:e.jsx(K,{})}),e.jsx(Q,{children:te.map(s=>e.jsx(w,{value:s,children:s},s))})]})]}),e.jsxs("div",{className:"w-28",children:[e.jsx(n,{className:"text-xs",children:"Interval"}),e.jsxs(q,{value:h,onValueChange:s=>r(s),children:[e.jsx(D,{children:e.jsx(K,{})}),e.jsxs(Q,{children:[e.jsx(w,{value:"month",children:"Monthly"}),e.jsx(w,{value:"year",children:"Yearly"})]})]})]}),e.jsxs("div",{className:"w-32",children:[e.jsx(n,{className:"text-xs",children:"Amount"}),e.jsx(y,{type:"number",min:"0",step:"0.01",placeholder:"29.00",value:l,onCh
1ange:s=>j(s.target.value)})]}),e.jsx(F,{type:"button",onClick:C,disabled:v.isPending,children:v.isPending?e.jsx(P,{className:"h-4 w-4 animate-spin"}):e.jsxs(e.Fragment,{children:[e.jsx(L,{className:"h-4 w-4 mr-1"}),"Add price"]})})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Creating a price calls Stripe and stores a stable lookup key so checkout works across sandbox and live."})]})}const Xe=()=>e.jsx(U,{children:e.jsx(re,{})});export{Xe as component};
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.