1import{j as e}from"./vendor-ui-C7MiEVzC.js";import{r as D}from"./vendor-react-BpyweTCE.js";import{u as L}from"./vendor-query-DnZbhdBj.js";import{u as z,a as E,v as F,w as P,s as g,D as B,C as p,b as m,d as x,bu as H,c as u,S as h,bV as b,aL as M,e as R,r as q,f as K,L as U,ae as V,B as c,bW as v}from"./index-CerUI-XW.js";import{T as I,a as Z,b as N,c as t,d as A,e as r}from"./table-DBVIad2-.js";import"./vendor-charts-IS_tyewZ.js";import"./vendor-motion-BEQOuUda.js";const $=()=>{const{t:a,i18n:w}=z(),{organization:i}=E(),_=w.language==="en"?F:P,{data:l,isLoading:o}=L({queryKey:["user-payments",i?.id],queryFn:async()=>{if(!i?.id)return[];const{data:s,error:n}=await g.from("payments").select("*").eq("organization_id",i.id).order("paid_at",{ascending:!1});if(n)throw n;return s},enabled:!!i?.id}),C=s=>{switch(s){case"completed":return e.jsx(c,{className:"bg-green-500/10 text-green-500 hover:bg-green-500/20",children:a("app.payments.status_completed","UspeÅ¡no")});case"pending":return e.jsx(c,{variant:"secondary",children:a("app.payments.status_pending","V obdelavi")});case"failed":return e.jsx(c,{variant:"destructive",children:a("app.payments.status_failed","NeuspeÅ¡no")});case"refunded":return e.jsx(c,{className:"bg-purple-500/10 text-purple-500 hover:bg-purple-500/20",children:a("app.payments.status_refunded","VraÄilo")});default:return e.jsx(c,{variant:"outline",children:s})}},k=l?.reduce((s,n)=>s+n.amount,0)||0,[j,y]=D.useState(null),S=async s=>{y(s);try{const{data:n,error:f}=await g.functions.invoke("generate-invoice",{body:{paymentId:s}});if(f)throw f;const d=document.createElement("a");d.href=n.pdf,d.download=n.filename,document.body.appendChild(d),d.click(),document.body.removeChild(d),v({title:a("app.payments.download_success","UspeÅ¡no"),description:a("app.payments.download_success_desc","RaÄun je bil uspeÅ¡no prenesen")})}catch(n){console.error("Error downloading invoice:",n),v({title:a("app.payments.download_error","Napaka"),description:a("app.payments.download_error_desc","Napaka pri prenosu raÄuna"),variant:"destructive"})}finally{y(null)}},T=s=>{switch(s){case"card":return a("app.payments.method_card","Kartica");case"proforma":return a("app.payments.method_proforma","PredraÄun");case"deferred_einvoice":return a("app.payments.method_einvoice","E-raÄun");default:return s||a("app.payments.method_card","Kartica")}};return e.jsx(B,{children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold",children:a("app.payments.title","Moja plaÄila")}),e.jsx("p",{className:"text-muted-foreground",children:a("app.payments.subtitle","Pregled vaÅ¡ih plaÄil in naroÄnin")})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-3",children:[e.jsxs(p,{children:[e.jsxs(m,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(x,{className:"text-sm font-medium",children:a("app.payments.total_paid","Skupaj plaÄano")}),e.jsx(H,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsx(u,{children:o?e.jsx(h,{className:"h-8 w-24"}):e.jsxs("div",{className:"text-2xl font-bold",children:[k.toFixed(2)," â¬"]})})]}),e.jsxs(p,{children:[e.jsxs(m,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(x,{className:"text-sm font-medium",children:a("app.payments.current_plan","Trenutni paket")}),e.jsx(b,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsx(u,{children:o?e.jsx(h,{className:"h-8 w-24"}):e.jsx("div",{className:"text-2xl font-bold",children:String(i?.plan||"Free")})})]}),e.jsxs(p,{children:[e.jsxs(m,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(x,{className:"text-sm font-medium",children:a("app.payments.payment_count","Å tevilo plaÄil")}),e.jsx(M,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsx(u,{children:o?e.jsx(h,{className:"h-8 w-24"}):e.jsx("div",{className:"text-2xl font-bold",children:l?.length||0})})]})]}),e.jsxs(p,{children:[e.jsxs(m,{children:[e.jsx(x,{children:a("app.payments.history_title","Zgodovina plaÄil")}),e.jsx(R,{children:a("app.payments.history_desc","Seznam vseh vaÅ¡ih opravljenih plaÄil")})]}),e.jsx(u,{children:o?e.jsx("div",{className:"space-y-2",children:[...Array(3)].map((s,n)=>e.jsx(h,{className:"h-12 w-full"},n))}):l&&l.length>0?e.jsxs(I,{children:[e.jsx(Z,{children:e.jsxs(N,{children:[e.jsx(t,{children:a("app.payments.invoice_number","Å t. raÄuna")}),e.jsx(t,{children:a("app.payments.date","Datum")}),e.jsx(t,{children:a("app.payments.plan","Paket")}),e.jsx(t,{children:a("app.payments.amount","Znesek")}),e.jsx(t,{children:a("app.payments.status","Status")}),e.jsx(t,{children:a("app.payments.payment_method","NaÄin plaÄila")}),e.jsx(t,{className:"text-right",children:a("app.payments.invoice","RaÄun")})]})}),e.jsx(A,{children:l.map(s=>e.jsxs(N,{children:[e.jsx(r,{className:"font-mono text-xs",children:s.invoice_number||"â"}
1),e.jsx(r,{children:q(new Date(s.paid_at),"d. MMM yyyy, HH:mm",{locale:_})}),e.jsx(r,{className:"font-medium",children:s.plan_name}),e.jsxs(r,{children:[s.amount.toFixed(2)," ",s.currency]}),e.jsx(r,{children:C(s.status)}),e.jsx(r,{className:"capitalize",children:T(s.payment_method)}),e.jsx(r,{className:"text-right",children:e.jsx(K,{variant:"outline",size:"sm",onClick:()=>S(s.id),disabled:j===s.id,children:j===s.id?e.jsx(U,{className:"h-4 w-4 animate-spin"}):e.jsxs(e.Fragment,{children:[e.jsx(V,{className:"h-4 w-4 mr-1"}),"PDF"]})})})]},s.id))})]}):e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(b,{className:"h-12 w-12 mx-auto mb-4 opacity-50"}),e.jsx("p",{children:a("app.payments.no_payments","Å e nimate nobenega plaÄila")})]})})]})]})})};export{$ 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.