1import{i as e}from"./rolldown-runtime-Dd_uD5pT.js";import{n as t,t as n}from"./jsx-runtime-BpzPEenQ.js";import{a as r,i,n as a,r as o,t as s}from"./select-BRWw7FAc.js";import{t as c}from"./button-Df5N-Q5b.js";import{t as l}from"./client-CXrrauhi.js";import{t as u}from"./format-Ckg9wD-A.js";import{Bi as d,Do as f,Ia as p,Io as m,Ir as h,Ma as g,Ro as _,So as v,Wi as y,ai as b,ar as x,cs as ee,er as te,f as S,io as C,ir as w,jo as T,ka as E,nr as D,oi as O,qo as k,rs as ne,sr as A,tr as j,ts as M,ua as N}from"./index-Det80ELu.js";import{t as P}from"./AdminSubNav-D_B5mqKP.js";import{a as F,n as I,o as L,r as R,s as z,t as re}from"./table-BUhKoqt7.js";import{t as ie}from"./economy-nav-BTniqDR5.js";var B=e(t(),1),V=n(),H={monthly:`MÃ¥nadsvis`,quarterly:`Kvartalsvis (3 mÃ¥n)`,semiannual:`HalvÃ¥rsvis (6 mÃ¥n)`,yearly:`Ã
rligen (12 mÃ¥n)`},U={monthly:1,quarterly:3,semiannual:6,yearly:12},W=({open:e,onOpenChange:t,subscriptionId:n,currentPlan:l,currentPriceId:u,customerEmail:d,getAuthHeaders:f,onUpgraded:p})=>{let{toast:m}=ee(),[h,g]=(0,B.useState)([]),[_,v]=(0,B.useState)(!1),[y,T]=(0,B.useState)(``),[E,k]=(0,B.useState)(`monthly`),[M,N]=(0,B.useState)(!1),[P,F]=(0,B.useState)(0),[I,L]=(0,B.useState)(!1),[R,z]=(0,B.useState)(!1);(0,B.useEffect)(()=>{e&&((async()=>{v(!0);try{let e=await f(),t=await(await fetch(`https://uopdyigkglqacbzvjwog.supabase.co/functions/v1/subscription-admin?action=list-plans`,{headers:e})).json();g(t.plans||[]);let n=(t.plans||[]).find(e=>e.priceId===u);n&&(T(n.slug||n.name),k(n.billingPeriod||`monthly`))}catch{m({title:`Kunde inte ladda planer`,variant:`destructive`})}finally{v(!1)}})(),N(!1),F(0),L(!1))},[e,f,m,u]);let re=(0,B.useMemo)(()=>{let e=new Set,t=[];for(let n of h){let r=n.slug||n.name;e.has(r)||(e.add(r),t.push({slug:r,displayName:n.displayName}))}return t},[h]),ie=(0,B.useMemo)(()=>h.filter(e=>(e.slug||e.name)===y).map(e=>e.billingPeriod||`monthly`),[h,y]),W=(0,B.useMemo)(()=>h.find(e=>(e.slug||e.name)===y&&(e.billingPeriod||`monthly`)===E),[h,y,E]),G=W?.priceId===u;return(0,V.jsx)(te,{open:e,onOpenChange:t,children:(0,V.jsxs)(j,{className:`sm:max-w-md`,children:[(0,V.jsxs)(w,{children:[(0,V.jsx)(x,{children:`Byt plan / period / bindning`}),(0,V.jsxs)(D,{children:[`Uppdatera prenumerationen för `,(0,V.jsx)(`strong`,{children:d}),`.`]})]}),(0,V.jsxs)(`div`,{className:`space-y-4 pt-2`,children:[(0,V.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,V.jsx)(`span`,{className:`text-muted-foreground`,children:`Nuvarande:`}),(0,V.jsx)(A,{variant:`secondary`,children:l})]}),_?(0,V.jsx)(`div`,{className:`flex justify-center py-4`,children:(0,V.jsx)(C,{className:`w-5 h-5 animate-spin text-primary`})}):(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(`div`,{className:`space-y-2`,children:[(0,V.jsx)(b,{className:`text-xs`,children:`Plan`}),(0,V.jsxs)(s,{value:y,onValueChange:e=>{T(e),k(`monthly`)},children:[(0,V.jsx)(i,{children:(0,V.jsx)(r,{placeholder:`Välj planâ¦`})}),(0,V.jsx)(a,{children:re.map(e=>(0,V.jsx)(o,{value:e.slug,children:e.displayName},e.slug))})]})]}),(0,V.jsxs)(`div`,{className:`space-y-2`,children:[(0,V.jsx)(b,{className:`text-xs`,children:`Faktureringsperiod`}),(0,V.jsxs)(s,{value:E,onValueChange:e=>{k(e)},disabled:!y,children:[(0,V.jsx)(i,{children:(0,V.jsx)(r,{placeholder:`Välj periodâ¦`})}),(0,V.jsx)(a,{children:ie.map(e=>(0,V.jsx)(o,{value:e,children:H[e]||e},e))})]})]}),(0,V.jsxs)(`div`,{className:`space-y-2`,children:[(0,V.jsx)(b,{className:`text-xs`,children:`Bindningstid (mÃ¥n) â sparas i metadata, 0 = ändra inte`}),(0,V.jsxs)(`div`,{className:`flex gap-2`,children:[(0,V.jsx)(O,{type:`number`,min:0,max:36,value:P,onChange:e=>F(parseInt(e.target.value)||0)}),(0,V.jsx)(c,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>F(U[E]||1),children:`Matcha period`}),(0,V.jsx)(c,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>F(12),children:`12 mÃ¥n`})]})]}),(0,V.jsxs)(`div`,{className:`flex items-center justify-between rounded-lg border border-border p-3`,children:[(0,V.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,V.jsx)(b,{className:`text-sm`,children:`Vid periodens slut`}),(0,V.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`PÃ¥ = bytet schemaläggs och träder i kraft när nuvarande betalperiod slutar (ingen extra debitering nu). Av = bytet sker direkt.`})]}),(0,V.jsx)(S,{checked:I,onCheckedChange:L})]}),(0,V.jsxs)(`div`,{className:`flex items-center justify-between rounded-lg border border-border p-3 ${I?`opacity-50`:``}`,children:[(0,V.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,V.jsx)(b,{className:`text-sm`,children:`Skapa proration`}),(0,V.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Av = ingen extra debitering nu. PÃ¥ = mellanskillnad debiteras direkt.`})]}),(0,V.jsx)(S,{checked:M,onCheckedChange:N,disabled:I})]}),W&&(0,V.jsxs)(`div`,{className:`flex items-center gap-2 text-sm bg-muted/50 rounded-lg p-3 flex-wrap`,children:[(0,V.jsx)(A,{variant:`secondary`,children:l}),(0,V.jsx)(ne,{className:`w-4 h-4 text-muted-foreground`}),(0,V.jsxs)(A,{className:`bg-primary`,children:[W.displayName,` · `,H[W.billingPeriod||`monthly`]]}),(0,V.jsxs)(`span`,{className:`text-muted-foreground ml-auto`,children:[W.price.toLocaleStr
1ing(`sv-SE`),` kr`]})]}),G&&P>0&&(0,V.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Inga prisändringar â endast bindningstid uppdateras i metadata.`})]}),(0,V.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,V.jsx)(c,{variant:`outline`,onClick:()=>t(!1),children:`Avbryt`}),(0,V.jsxs)(c,{onClick:async()=>{if(W){z(!0);try{let e=await f(),r=await(await fetch(`https://uopdyigkglqacbzvjwog.supabase.co/functions/v1/subscription-admin?action=upgrade-plan`,{method:`POST`,headers:{...e,"Content-Type":`application/json`},body:JSON.stringify({subscriptionId:n,newPriceId:W.priceId,customerEmail:d,prorationBehavior:M?`create_prorations`:`none`,commitmentMonths:P>0?P:void 0,scheduleAtPeriodEnd:I})})).json();if(r.error)throw Error(r.error);let i=[];G||i.push(`${r.oldPlan} â ${r.newPlan}`),r.scheduled&&r.effectiveDate&&i.push(`aktiveras ${new Date(r.effectiveDate).toLocaleDateString(`sv-SE`)}`),P>0&&i.push(`${P} mÃ¥n bindning`),I||i.push(M?`med proration`:`ingen proration`),m({title:r.scheduled?`Planbyte schemalagt`:`Prenumeration uppdaterad`,description:i.join(` · `)}),p(),t(!1)}catch(e){m({title:`Uppdatering misslyckades`,description:e.message,variant:`destructive`})}finally{z(!1)}}},disabled:!W||R||G&&P===0,children:[R&&(0,V.jsx)(C,{className:`w-4 h-4 mr-2 animate-spin`}),`Bekräfta`]})]})]})]})})},G={pause:{title:`Pausa vid periodens slut`,cta:`Schemalägg paus`,desc:`Kunden behÃ¥ller portalÃ¥tkomsten under hela pausen. Coaching och TrainingPeaks-access inaktiveras â ingen debitering sker.`},cancel:{title:`Säg upp vid periodens slut`,cta:`Schemalägg uppsägning`,desc:`Prenumerationen avslutas helt vid nästa periodslut. Kunden fÃ¥r tillgÃ¥ng hela perioden ut.`}},ae=({open:e,onOpenChange:t,actionType:n,subscriptionId:r,customerEmail:i,currentPeriodEnd:a,onDone:o})=>{let{toast:s}=ee(),[d,f]=(0,B.useState)(!1),[p,m]=(0,B.useState)(!0),[g,_]=(0,B.useState)(()=>{let e=new Date;return e.setMonth(e.getMonth()+3),e.toISOString().slice(0,10)}),[v,y]=(0,B.useState)(!1),[T,E]=(0,B.useState)(()=>(a?new Date(a):new Date).toISOString().slice(0,10)),k=G[n],ne=a?u(new Date(a),`d MMMM yyyy`,{locale:h}):`â`;return(0,V.jsx)(te,{open:e,onOpenChange:t,children:(0,V.jsxs)(j,{className:`sm:max-w-md`,children:[(0,V.jsxs)(w,{children:[(0,V.jsx)(x,{className:`font-display text-2xl`,children:k.title}),(0,V.jsx)(D,{children:k.desc})]}),(0,V.jsxs)(`div`,{className:`rounded-lg bg-muted/40 p-3 text-sm flex gap-2`,children:[(0,V.jsx)(N,{className:`w-4 h-4 text-primary shrink-0 mt-0.5`}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`p`,{className:`font-medium`,children:i}),(0,V.jsxs)(`p`,{className:`text-muted-foreground text-xs mt-0.5`,children:[`Periodens slut: `,(0,V.jsx)(`strong`,{children:ne})]})]})]}),(0,V.jsxs)(`div`,{className:`space-y-3`,children:[(0,V.jsxs)(`div`,{className:`flex items-center justify-between rounded-lg border border-border/40 p-3`,children:[(0,V.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,V.jsx)(b,{htmlFor:`custom-date`,className:`text-sm`,children:`Anpassat effektivt datum`}),(0,V.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Som standard träder Ã¥tgärden i kraft vid periodens slut. SlÃ¥ pÃ¥ för att välja ett eget datum.`})]}),(0,V.jsx)(S,{id:`custom-date`,checked:v,onCheckedChange:y})]}),v&&(0,V.jsxs)(`div`,{className:`space-y-2`,children:[(0,V.jsx)(b,{htmlFor:`effective`,children:`Träder i kraft`}),(0,V.jsx)(O,{id:`effective`,type:`date`,value:T,min:new Date(Date.now()+864e5).toISOString().slice(0,10),onChange:e=>E(e.target.value)}),(0,V.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n===`pause`?`Pausen aktiveras detta datum.`:`Prenumerationen avslutas detta datum.`})]})]}),n===`pause`&&(0,V.jsxs)(`div`,{className:`space-y-3`,children:[(0,V.jsxs)(`div`,{className:`flex items-center justify-between rounded-lg border border-border/40 p-3`,children:[(0,V.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,V.jsx)(b,{htmlFor:`open-ended`,className:`text-sm`,children:`Obekräftat slutdatum`}),(0,V.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Pausen löper tills den lyfts manuellt. Kunden fortsätter nyttja portalen.`})]}),(0,V.jsx)(S,{id:`open-ended`,checked:p,onCheckedChange:m})]}),!p&&(0,V.jsxs)(`div`,{className:`space-y-2`,children:[(0,V.jsx)(b,{htmlFor:`resumes`,children:`Ã
terupptas automatiskt`}),(0,V.jsx)(O,{id:`resumes`,type:`date`,value:g,min:new Date(Date.now()+2592e6).toISOString().slice(0,10),onChange:e=>_(e.target.value)}),(0,V.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Vid detta datum återupptas debiteringen automatiskt.`})]})]}),(0,V.jsxs)(`div`,{className:`flex gap-2 pt-2`,children:[(0,V.jsx)(c,{variant:`outline`,className:`flex-1`,onClick:()=>t(!1),disabled:d,children:`Avbryt`}),(0,V.jsx)(c,{variant:n===`cancel`?`destructive`:`default`,className:`flex-1`,onClick:async()=>{f(!0);try{let e=(await l.auth.getSession()).data.session,a=await fetch(`https://uopdyigkglqacbzvjwog.supabase.co/functions/v1/subscription-admin?action=schedule-action`,{method:`POST`,headers:{Authorization:`Bearer ${e?.access_token}`,apikey:`eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InVvcGR5aWdrZ2xxYWNienZqd29nIiwicm9sZSI6ImFub24iLCJpYXQiOjE3Njk5NzkxOTksImV4cCI6MjA4NTU1NTE5OX0.J6SPxNrNMIJ-qSDnSiVJwtPLbStOFQtsYqj_d9SFtu8`,"Content-Type":`application/json`},body:JSON.stringify({subscriptionId:r,actionType:n,customerEmail:i,...v?{effectiveDate:new Date(T).toISOString()}:{},...n===`pause`?p?{}:{resumesAt:new Date(g).toISOString()}:{}})}),c=await a.json();if(!a.ok||c.error)throw Error(c.error||`Misslyckades`);s({title:n===`pause`?`Paus schemalagd`:`Uppsägning schemalagd`,description:`Träder i kraft ${u(new Date(c.effectiveDate),`d MMMM yyyy`,{locale:h})}.`}),t(!1),o?.()}catch(e){s({title:`Fel`,description:e.message,variant:`destructive`})}finally{f(!1)}},disabled:d,children:d?(0,V.jsx)(C,{className:`w-4 h-4 animate-spin`}):k.cta})]})]})})},K=()=>{let{user:e,loading:t}=d(),n=y(),{toast:b}=ee(),[x,te]=(0,B.useState)(!1),[S,w]=(0,B.useState)(!0),[D,ne]=(0,B.useState)([]),[j,H]=(0,B.useState)([]),[U,G]=(0,B.useState)(!0),[
1K,oe]=(0,B.useState)(!0),[q,se]=(0,B.useState)(`all`),[ce,le]=(0,B.useState)(``),[ue,de]=(0,B.useState)(null),[fe,pe]=(0,B.useState)({}),[J,me]=(0,B.useState)(`subscriptions`),[Y,he]=(0,B.useState)(null),[X,ge]=(0,B.useState)(null),[_e,ve]=(0,B.useState)(null),[ye,be]=(0,B.useState)(null),Z=async()=>({Authorization:`Bearer ${(await l.auth.getSession()).data.session?.access_token}`,apikey:`eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InVvcGR5aWdrZ2xxYWNienZqd29nIiwicm9sZSI6ImFub24iLCJpYXQiOjE3Njk5NzkxOTksImV4cCI6MjA4NTU1NTE5OX0.J6SPxNrNMIJ-qSDnSiVJwtPLbStOFQtsYqj_d9SFtu8`}),Q=(0,B.useCallback)(async()=>{G(!0);try{let e=await Z(),t=await(await fetch(`https://uopdyigkglqacbzvjwog.supabase.co/functions/v1/subscription-admin?action=list-subscriptions&status=${q}`,{headers:e})).json();if(t.error)throw Error(t.error);ne(t.subscriptions||[])}catch(e){console.error(`Failed to load subscriptions:`,e),b({title:`Kunde inte ladda prenumerationer`,variant:`destructive`})}finally{G(!1)}},[q,b]),$=(0,B.useCallback)(async()=>{oe(!0);try{let e=await Z(),t=await(await fetch(`https://uopdyigkglqacbzvjwog.supabase.co/functions/v1/subscription-admin?action=list-failed-invoices`,{headers:e})).json();if(t.error)throw Error(t.error);H(t.invoices||[])}catch(e){console.error(`Failed to load invoices:`,e)}finally{oe(!1)}},[]),xe=async e=>{de(e),pe(t=>({...t,[e]:``}));try{let t=await Z(),n=await(await fetch(`https://uopdyigkglqacbzvjwog.supabase.co/functions/v1/subscription-admin?action=retry-invoice`,{method:`POST`,headers:{...t,"Content-Type":`application/json`},body:JSON.stringify({invoiceId:e})})).json();if(n.error||n.success===!1)throw Error(n.error||`Okänt fel`);b({title:`Betalningsförsök skickat`,description:`Status: ${n.status}`}),$()}catch(t){let n=t.message||`Kunde inte göra om betalningen`;pe(t=>({...t,[e]:n})),b({title:`Betalningen gick inte igenom`,description:n,variant:`destructive`})}finally{de(null)}};(0,B.useEffect)(()=>{!t&&e?(async()=>{w(!0);let{data:t}=await l.from(`user_roles`).select(`role`).eq(`user_id`,e.id).eq(`role`,`admin`).maybeSingle();if(!t){n(`/`);return}te(!0),w(!1)})():!t&&!e&&n(`/auth`)},[t,e,n]),(0,B.useEffect)(()=>{x&&(Q(),$())},[x,Q,$]);let Se=D.filter(e=>{if(!ce)return!0;let t=ce.toLowerCase();return e.customerEmail.toLowerCase().includes(t)||e.customerName&&e.customerName.toLowerCase().includes(t)||e.plan.toLowerCase().includes(t)||e.status.toLowerCase().includes(t)}),Ce=(e,t,n)=>{if(n&&(e===`active`||e===`past_due`))return(0,V.jsxs)(A,{className:`bg-blue-600`,children:[(0,V.jsx)(_,{className:`w-3 h-3 mr-1`}),` Pausad`]});if(t&&e===`active`)return(0,V.jsx)(A,{variant:`outline`,className:`text-orange-500 border-orange-500`,children:`Avslutas`});switch(e){case`active`:return(0,V.jsx)(A,{className:`bg-green-600`,children:`Aktiv`});case`past_due`:return(0,V.jsx)(A,{variant:`destructive`,children:`Förfallen`});case`canceled`:return(0,V.jsx)(A,{variant:`secondary`,children:`Avslutad`});case`incomplete`:return(0,V.jsx)(A,{variant:`outline`,className:`text-yellow-500 border-yellow-500`,children:`Ofullständig`});case`trialing`:return(0,V.jsx)(A,{className:`bg-blue-600`,children:`Provperiod`});case`unpaid`:return(0,V.jsx)(A,{variant:`destructive`,children:`Obetald`});default:return(0,V.jsx)(A,{variant:`secondary`,children:e})}},we=async e=>{ve(e.id);try{let t=await Z(),n=await fetch(`https://uopdyigkglqacbzvjwog.supabase.co/functions/v1/subscription-admin?action=undo-scheduled-action`,{method:`POST`,headers:{...t,"Content-Type":`application/json`},body:JSON.stringify({subscriptionId:e.id})}),r=await n.json();if(!n.ok||r.error)throw Error(r.error||`Misslyckades`);b({title:`Schemalagd åtgärd ångrad`}),Q()}catch(e){b({title:`Fel`,description:e.message,variant:`destructive`})}finally{ve(null)}},Te=async e=>{let t=window.prompt(`Konvertera ${e.customerEmail} till fakturabetalning?\n\nStripe behåller samma prenumeration och periodslut (${e.currentPeriodEnd?u(new Date(e.currentPeriodEnd),`d MMM yyyy`,{locale:h}):`okänt`}). Nästa faktura skickas via e-post istället för att dras på kort.\n\nDagar till förfallodag:`,`14`);
1if(t===null)return;let n=Number(t)||14;be(e.id);try{let t=await Z(),r=await fetch(`https://uopdyigkglqacbzvjwog.supabase.co/functions/v1/subscription-admin?action=convert-to-invoice`,{method:`POST`,headers:{...t,"Content-Type":`application/json`},body:JSON.stringify({subscriptionId:e.id,daysUntilDue:n})}),i=await r.json();if(!r.ok||i.error)throw Error(i.error||`Misslyckades`);b({title:i.alreadyInvoice?`Redan fakturakund`:`Konverterad till faktura`,description:`Nästa faktura skickas via e-post. Period och prenumeration behÃ¥lls.`}),Q()}catch(e){b({title:`Fel`,description:e.message,variant:`destructive`})}finally{be(null)}},Ee=e=>{switch(e){case`open`:return(0,V.jsx)(A,{variant:`outline`,className:`text-orange-500 border-orange-500`,children:`Ãppen`});case`uncollectible`:return(0,V.jsx)(A,{variant:`destructive`,children:`Ej indrivbar`});case`paid`:return(0,V.jsx)(A,{className:`bg-green-600`,children:`Betald`});default:return(0,V.jsx)(A,{variant:`secondary`,children:e})}};if(t||S||!x)return(0,V.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-background`,children:(0,V.jsx)(C,{className:`w-8 h-8 animate-spin text-primary`})});let De=D.filter(e=>e.pausedCollection).length,Oe=D.filter(e=>e.status===`active`&&!e.cancelAtPeriodEnd&&!e.pausedCollection).length,ke=D.filter(e=>e.cancelAtPeriodEnd&&!e.pausedCollection).length,Ae=D.filter(e=>!e.pausedCollection&&(e.status===`past_due`||e.status===`unpaid`)).length;return(0,V.jsxs)(`div`,{className:`min-h-screen bg-background`,children:[(0,V.jsx)(P,{...ie,currentLabel:`Prenumerationer`}),(0,V.jsxs)(`div`,{className:`max-w-7xl mx-auto px-4 py-8`,children:[(0,V.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-5 gap-4 mb-8`,children:[(0,V.jsxs)(`div`,{className:`bg-glass-base border border-glass-soft backdrop-blur-glass ring-1 ring-glow-info rounded-xl p-4`,children:[(0,V.jsx)(`div`,{className:`text-2xl font-bold text-green-500`,children:Oe}),(0,V.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:`Aktiva`})]}),(0,V.jsxs)(`div`,{className:`bg-glass-base border border-glass-soft backdrop-blur-glass ring-1 ring-glow-info rounded-xl p-4`,children:[(0,V.jsx)(`div`,{className:`text-2xl font-bold text-blue-500`,children:De}),(0,V.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:`Pausade`})]}),(0,V.jsxs)(`div`,{className:`bg-glass-base border border-glass-soft backdrop-blur-glass ring-1 ring-glow-info rounded-xl p-4`,children:[(0,V.jsx)(`div`,{className:`text-2xl font-bold text-orange-500`,children:ke}),(0,V.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:`Avslutas`})]}),(0,V.jsxs)(`div`,{className:`bg-glass-base border border-glass-soft backdrop-blur-glass ring-1 ring-glow-info rounded-xl p-4`,children:[(0,V.jsx)(`div`,{className:`text-2xl font-bold text-destructive`,children:Ae}),(0,V.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:`Förfallna/Obetalda`})]}),(0,V.jsxs)(`div`,{className:`bg-glass-base border border-glass-soft backdrop-blur-glass ring-1 ring-glow-info rounded-xl p-4`,children:[(0,V.jsx)(`div`,{className:`text-2xl font-bold text-destructive`,children:j.length}),(0,V.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:`Misslyckade fakturor`})]})]}),(0,V.jsxs)(`div`,{className:`flex gap-2 mb-6`,children:[(0,V.jsxs)(c,{variant:J===`subscriptions`?`default`:`outline`,onClick:()=>me(`subscriptions`),children:[(0,V.jsx)(T,{className:`w-4 h-4 mr-2`}),`Prenumerationer`]}),(0,V.jsxs)(c,{variant:J===`failed`?`default`:`outline`,onClick:()=>me(`failed`),children:[(0,V.jsx)(N,{className:`w-4 h-4 mr-2`}),`Misslyckade fakturor (`,j.length,`)`]})]}),J===`subscriptions`&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-4 mb-6`,children:[(0,V.jsxs)(`div`,{className:`relative flex-1`,children:[(0,V.jsx)(E,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground`}),(0,V.jsx)(O,{placeholder:`Sök kund (e-post, namn, plan)...`,value:ce,onChange:e=>le(e.target.value),className:`pl-10`})]}),(0,V.jsxs)(s,{value:q,onValueChange:e=>se(e),children:[(0,V.jsx)(i,{className:`w-[180px]`,children:(0,V.jsx)(r,{placeholder:`Filtrera status`})}),(0,V.jsxs)(a,{children:[(0,V.jsx)(o,{value:`all`,children:`Alla`}),(0,V.jsx)(o,{value:`active`,children:`Aktiva`}),(0,V.jsx)(o,{value:`past_due`,children:`Förfallna`}),(0,V.jsx)(o,{value:`canceled`,children:`Avslutade`}),(0,V.jsx)(o,{value:`unpaid`,children:`Obetalda`})]})]}),(0,V.jsx)(c,{variant:`outline`,size:`icon`,onClick:Q,disabled:U,children:(0,V.jsx)(p,{className:`w-4 h-4 ${U?`animate-spin`:``}`})})]}),(0,V.jsxs)(`div`,{className:`bg-glass-base border border-glass-soft backdrop-blur-glass ring-1 ring-glow-info rounded-2xl overflow-hidden`,children:[(0,V.jsx)(`div`,{className:`p-6 border-b border-border`,children:(0,V.jsxs)(`h2`,{className:`font-display text-xl`,children:[`Prenumerationer (`,Se.length,`)`]})}),U?(0,V.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,V.jsx)(C,{className:`w-6 h-6 animate-spin text-primary`})}):Se.length===0?(0,V.jsx)(`div`,{className:`text-center py-12 text-muted-foreground`,children:`Inga prenumerationer hittades.`}):(0,V.jsx)(`div`,{className:`overflow-x-auto`,children:(0,V.jsxs)(re,{children:[(0,V.jsx)(L,{children:(0,V.jsxs)(z,{children:[(0,V.jsx)(F,{children:`Kund`}),(0,V.jsx)(F,{children:`Plan`}),(0,V.jsx)(F,{children:`Pris`}),(0,V.jsx)(F,{children:`Status`}
1),(0,V.jsx)(F,{children:`Schemalagt`}),(0,V.jsx)(F,{children:`Nästa period`}),(0,V.jsx)(F,{children:`Startad`}),(0,V.jsx)(F,{children:`Ã
tgärder`})]})}),(0,V.jsx)(I,{children:Se.map(e=>(0,V.jsxs)(z,{children:[(0,V.jsx)(R,{children:(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`div`,{className:`font-medium`,children:e.customerEmail}),e.customerName&&(0,V.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:e.customerName}),e.collectionMethod===`send_invoice`&&(0,V.jsxs)(A,{variant:`outline`,className:`text-xs mt-1 text-primary border-primary/30`,children:[(0,V.jsx)(v,{className:`w-3 h-3 mr-1`}),` Faktura`]})]})}),(0,V.jsx)(R,{children:(0,V.jsx)(`span`,{className:`font-mono text-sm`,children:e.plan})}),(0,V.jsx)(R,{children:e.effectivePrice!=null&&e.effectivePrice!==e.price?(0,V.jsxs)(`div`,{className:`flex flex-col`,children:[(0,V.jsxs)(`span`,{className:`font-medium text-primary`,children:[e.effectivePrice,` kr/mÃ¥n`]}),(0,V.jsxs)(`span`,{className:`text-xs text-muted-foreground line-through`,children:[e.price,` kr`]}),e.discountPercent?(0,V.jsxs)(`span`,{className:`text-xs text-primary`,children:[`-`,e.discountPercent,`%`]}):null]}):(0,V.jsxs)(`span`,{children:[e.price,` kr/mÃ¥n`]})}),(0,V.jsx)(R,{children:Ce(e.status,e.cancelAtPeriodEnd,e.pausedCollection)}),(0,V.jsx)(R,{children:e.scheduledAction?(0,V.jsxs)(`div`,{className:`text-xs flex items-center gap-1 text-primary`,children:[(0,V.jsx)(k,{className:`w-3 h-3`}),e.scheduledAction.action_type===`pause`&&`Paus`,e.scheduledAction.action_type===`cancel`&&`Uppsägning`,e.scheduledAction.action_type===`downgrade`&&`Planbyte`,` `,u(new Date(e.scheduledAction.effective_date),`d MMM yyyy`,{locale:h})]}):(0,V.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`â`})}),(0,V.jsx)(R,{children:e.currentPeriodEnd?u(new Date(e.currentPeriodEnd),`d MMM yyyy`,{locale:h}):`â`}),(0,V.jsx)(R,{children:u(new Date(e.created),`d MMM yyyy`,{locale:h})}),(0,V.jsx)(R,{children:(e.status===`active`||e.status===`trialing`)&&(0,V.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:e.scheduledAction?(0,V.jsx)(c,{size:`sm`,variant:`outline`,onClick:()=>we(e),disabled:_e===e.id,children:_e===e.id?(0,V.jsx)(C,{className:`w-4 h-4 animate-spin`}):(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(g,{className:`w-4 h-4 mr-1`}),`Ã
ngra`]})}):(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(c,{size:`sm`,variant:`outline`,onClick:()=>he(e),children:[(0,V.jsx)(M,{className:`w-4 h-4 mr-1`}),`Byt plan`]}),e.collectionMethod!==`send_invoice`&&(0,V.jsxs)(c,{size:`sm`,variant:`outline`,onClick:()=>Te(e),disabled:ye===e.id,title:`Byt frÃ¥n kort till faktura via e-post (behÃ¥ller period)`,children:[ye===e.id?(0,V.jsx)(C,{className:`w-4 h-4 mr-1 animate-spin`}):(0,V.jsx)(v,{className:`w-4 h-4 mr-1`}),`Till faktura`]}),(0,V.jsxs)(c,{size:`sm`,variant:`outline`,onClick:()=>ge({sub:e,type:`pause`}),children:[(0,V.jsx)(_,{className:`w-4 h-4 mr-1`}),`Pausa`]}),(0,V.jsxs)(c,{size:`sm`,variant:`outline`,className:`text-destructive hover:text-destructive`,onClick:()=>ge({sub:e,type:`cancel`}),children:[(0,V.jsx)(m,{className:`w-4 h-4 mr-1`}),`Säg upp`]})]})})})]},e.id))})]})})]})]}),J===`failed`&&(0,V.jsxs)(`div`,{className:`bg-glass-base border border-glass-soft backdrop-blur-glass ring-1 ring-glow-info rounded-2xl overflow-hidden`,children:[(0,V.jsxs)(`div`,{className:`p-6 border-b border-border flex items-center justify-between`,children:[(0,V.jsxs)(`h2`,{className:`font-display text-xl`,children:[`Misslyckade fakturor (`,j.length,`)`]}),(0,V.jsx)(c,{variant:`outline`,size:`icon`,onClick:$,disabled:K,children:(0,V.jsx)(p,{className:`w-4 h-4 ${K?`animate-spin`:``}`})})]}),K?(0,V.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,V.jsx)(C,{className:`w-6 h-6 animate-spin text-primary`})}):j.length===0?(0,V.jsx)(`div`,{className:`text-center py-12 text-muted-foreground`,children:`Inga misslyckade fakturor. ð`}):(0,V.jsx)(`div`,{className:`overflow-x-auto`,children:(0,V.jsxs)(re,{children:[(0,V.jsx)(L,{children:(0,V.jsxs)(z,{children:[(0,V.jsx)(F,{children:`Kund`}),(0,V.jsx)(F,{children:`Belopp`}),(0,V.jsx)(F,{children:`Status`}),(0,V.jsx)(F,{children:`Försök`}),(0,V.jsx)(F,{children:`Skapad`}),(0,V.jsx)(F,{children:`Ã
tgärder`})]})}),(0,V.jsx)(I,{children:j.map(e=>(0,V.jsxs)(z,{children:[(0,V.jsx)(R,{className:`font-medium`,children:e.customerEmail}
1),(0,V.jsxs)(R,{children:[(e.amountDue/100).toLocaleString(`sv-SE`),` kr`]}),(0,V.jsx)(R,{children:Ee(e.status)}),(0,V.jsxs)(R,{children:[e.attemptCount,` försök`]}),(0,V.jsx)(R,{children:u(new Date(e.created),`d MMM yyyy`,{locale:h})}),(0,V.jsxs)(R,{children:[(0,V.jsxs)(`div`,{className:`flex gap-2`,children:[(e.status===`open`||e.status===`past_due`||e.status===`uncollectible`)&&(0,V.jsxs)(c,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>xe(e.id),disabled:ue===e.id,children:[ue===e.id?(0,V.jsx)(C,{className:`w-4 h-4 mr-1 animate-spin`}):(0,V.jsx)(p,{className:`w-4 h-4 mr-1`}),`Försök igen`]}),e.hostedInvoiceUrl&&(0,V.jsx)(c,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>window.open(e.hostedInvoiceUrl,`_blank`),children:(0,V.jsx)(f,{className:`w-4 h-4`})})]}),fe[e.id]&&(0,V.jsx)(`p`,{className:`mt-2 text-xs text-destructive max-w-xs`,children:fe[e.id]})]})]},e.id))})]})})]})]}),Y&&(0,V.jsx)(W,{open:!!Y,onOpenChange:e=>!e&&he(null),subscriptionId:Y.id,currentPlan:Y.plan,customerEmail:Y.customerEmail,getAuthHeaders:Z,onUpgraded:Q}),X&&(0,V.jsx)(ae,{open:!!X,onOpenChange:e=>!e&&ge(null),actionType:X.type,subscriptionId:X.sub.id,customerEmail:X.sub.customerEmail,currentPeriodEnd:X.sub.currentPeriodEnd,onDone:Q})]})};export{K 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.