1import{j as e}from"./ui-vendor-BuIVDC_j.js";import{l as D,r}from"./react-vendor-CrJEcqUQ.js";import{d as R,S as A,F as w,z as U}from"./index-KEVldjck.js";import{b as $}from"./billing-D9Dre-xE.js";import{f as I}from"./dateFormatter-CkLysxqB.js";import{m as T,c as _,t as B}from"./adminTableSort-7NpAAitv.js";import{A as O}from"./arrow-up-BeUwHe7z.js";import{A as H,C as Z}from"./chevrons-up-down-DhmRlK-B.js";import{L as q}from"./list-filter-D_V2epj_.js";import{P as M}from"./package-BOEVbr23.js";import{S as G}from"./send-KxSGhDSN.js";import"./date-vendor-ghIBFdIZ.js";import"./form-vendor-BzHnMruS.js";const J=({id:d,product:y,amount:m,date:b,status:n,method:f,selected:o,onSelect:p,invoiceUuid:x,onDownloadInvoice:u})=>e.jsxs("tr",{className:`hover:bg-gray-50 text-[12px] text-[#171717] transition ${o?"bg-blue-50":""}`,children:[e.jsx("td",{className:"px-3 py-3 text-center w-10",children:e.jsx("input",{type:"checkbox",checked:o,onChange:p,className:"accent-[#2B7FFF] cursor-pointer"})}),e.jsx("td",{className:"px-3 py-3 text-[#171717] font-medium",children:d}),e.jsxs("td",{className:"px-3 py-3 flex items-center space-x-2",children:[e.jsx(M,{size:14,className:"text-[#737373]"}),e.jsx("span",{children:y})]}),e.jsx("td",{className:"px-3 py-3 text-right",children:m}),e.jsx("td",{className:"px-3 py-3",children:b}),e.jsx("td",{className:"px-3 py-3",children:e.jsx("span",{className:`px-2 py-0.5 rounded-full text-[11px] font-medium ${n==="Paid"?"bg-green-100 text-green-700":n==="Pending"?"bg-amber-100 text-amber-800":"bg-red-100 text-red-700"}`,children:n})}),e.jsx("td",{className:"px-3 py-3 text-[#171717]",children:f}),e.jsx("td",{className:"px-3 py-3 text-center",children:e.jsxs("div",{className:"flex items-center justify-center space-x-3 text-[#2B7FFF]",children:[e.jsx("button",{type:"button",className:"hover:opacity-80 transition disabled:opacity-40",title:"Download invoice PDF",disabled:!x||!u,onClick:u,children:e.jsx(w,{size:14})}),e.jsx("button",{type:"button",className:"hover:opacity-80 transition opacity-40 cursor-not-allowed",title:"Invoice is emailed automatically on payment",disabled:!0,children:e.jsx(G,{size:14})})]})})]}),le=()=>{const{companyUuid:d}=D(),[y,m]=r.useState([]),[b,n]=r.useState(!0),[f,o]=r.useState(!1),[p,x]=r.useState([]),[u,k]=r.useState(""),[j,F]=r.useState(null),[g,S]=r.useState({id:"",product:"",amount:"",date:"",status:"",method:""}),[l,C]=r.useState({key:"date",direction:"asc"}),E=t=>{const s=new Date(t);if(Number.isNaN(s.getTime()))return"â";const i=Intl.DateTimeFormat().resolvedOptions().timeZone,c=I(s,"â"),a=s.toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit",hour12:!0,timeZone:i});return`${c} ${a}`};r.useEffect(()=>{if(!d){m([]),o(!1),n(!1);return}let t=!1;return n(!0),R.get("/billing/transactions",{params:{company_uuid:d,limit:100}}).then(s=>{if(t)return;const c=(s.data.transactions||[]).map(a=>({id:a.invoice_number||a.invoiceNumber||"â",invoiceUuid:a.invoice_uuid||a.invoiceUuid||null,product:a.plan_name||a.planName||"Subscription",amount:a.amount?`â¹${a.amount}`:"â",date:a.created_at||a.createdAt?E(a.created_at||a.createdAt):"â",status:a.status==="paid"?"Paid":a.status==="created"?"Pending":"Failed",method:a.razorpay_payment_id||a.razorpayPaymentId?"Razorpay":"â"}));m(c),o(!1)}).catch(()=>{t||(m([]),o(!0))}).finally(()=>{t||n(!1)}),()=>{t=!0}},[d]);const N=y,h=[...N.filter(t=>{const s=u.trim().toLowerCase();return s?t.id.toLowerCase().includes(s)||t.product.toLowerCase().includes(s)||t.date.toLowerCase().includes(s):!0})].filter(t=>Object.keys(g).every(s=>T(t[s],g[s]))).sort((t,s)=>l.key?_(t[l.key],s[l.key],l.direction):0),v=p.length===h.length&&h.length>0,z=()=>{x(v?[]:h.map(t=>t.id))},L=t=>{x(s=>s.includes(t)?s.filter(i=>i!==t):[...s,t])},P=async(t,s)=>{try{const i=await $.downloadInvoicePdf(t),c=URL.createObjectURL(i),a=document.createElement("a");a.href=c,a.download=`invoice-${s.replace(/\//g,"-")}.pdf`,document.body.appendChild(a),a.click(),a.remove(),URL.revokeObjectURL(c)}catch{U.error("Could not download invoice",{duration:3e3})}};return e.jsxs("div",{className:"flex flex-col h-auto space-y-4 bg-[#FFFFFF] border border-[#
1E5E5E5] rounded-lg pt-4 px-4 pb-0",children:[e.jsx("div",{className:"flex items-center justify-between mb-3",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-[20px] font-semibold text-[#171717]",children:"Billing History"}),e.jsx("p",{className:"text-[14px] text-[#737373]",children:"Track this user's subscription payments across all products."})]})}),e.jsx("div",{className:"flex items-center space-x-2 mb-3",children:e.jsxs("div",{className:"flex items-center flex-1 border border-[#E5E5E5] rounded-md px-2",children:[e.jsx(A,{size:16,className:"text-gray-400 mr-2"}),e.jsx("input",{value:u,onChange:t=>k(t.target.value),className:"flex-1 h-8 border-none focus:outline-none text-[12px] text-[#737373] placeholder-[#737373]",placeholder:"Search by invoice ID, product or date..."})]})}),f&&e.jsx("div",{className:"flex items-center gap-2 px-3 py-1.5 bg-red-50 border border-red-200 rounded-md text-xs text-red-700 mb-2",children:"Could not load billing transactions. Please try again."}),e.jsx("div",{className:"-mx-4 border-t border-[#E5E5E5] bg-white rounded-b-lg overflow-hidden",children:b?e.jsx("div",{className:"flex items-center justify-center h-40 text-sm text-[#737373]",children:"Loading..."}):N.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center h-40 text-sm text-[#737373]",children:[e.jsx(w,{size:32,className:"mb-2 text-gray-300"}),e.jsx("p",{className:"font-medium text-[#171717]",children:"No billing history yet"}),e.jsx("p",{className:"text-xs mt-1",children:"Transactions will appear here once payments are made."})]}):e.jsxs("table",{className:"w-full border-collapse",children:[e.jsx("thead",{className:"text-[11px] text-[#737373] uppercase tracking-wide",children:e.jsxs("tr",{className:"border-b border-[#E5E5E5] bg-[#FAFAFA]",children:[e.jsx("th",{className:"px-3 py-2 text-center w-10",children:e.jsx("input",{type:"checkbox",checked:v,onChange:z,className:"accent-[#2B7FFF] cursor-pointer"})}),[{key:"id",label:"Invoice ID",align:"text-left"},{key:"product",label:"Product",align:"text-left"},{key:"amount",label:"Amount",align:"text-right"},{key:"date",label:"Date",align:"text-left"},{key:"status",label:"Status",align:"text-left"},{key:"method",label:"Payment Method",align:"text-left"}].map(t=>e.jsx("th",{className:`${t.align} px-3 py-2 font-medium`,children:e.jsxs("div",{className:"flex items-center justify-between gap-1",children:[e.jsxs("button",{type:"button",className:"flex items-center gap-1",onClick:()=>C(s=>B(s,t.key)),children:[e.jsx("span",{children:t.label}),l.key===t.key?l.direction==="asc"?e.jsx(O,{size:10}):e.jsx(H,{size:10}):e.jsx(Z,{size:10})]}),e.jsxs("div",{className:"relative",children:[e.jsx("button",{type:"button",className:"p-1 hover:bg-gray-200 rounded",onClick:()=>F(j===t.key?null:t.key),children:e.jsx(q,{size:12})}),j===t.key&&e.jsx("div",{className:"absolute right-0 top-full z-20 mt-1 w-48 rounded-lg border border-gray-200 bg-white shadow-lg p-2",children:e.jsx("input",{type:"text",value:g[t.key],onChange:s=>S(i=>({...i,[t.key]:s.target.value})),placeholder:`Filter ${t.label.toLowerCase()}...`,className:"w-full px-2 py-1 text-xs border border-gray-300 rounded focus:outline-none focus:ring-2 focus:ring-blue-500"})})]})]})},t.key))]})}),e.jsx("tbody",{className:"divide-y divide-[#E5E5E5]",children:h.map(t=>e.jsx(J,{...t,selected:p.includes(t.id),onSelect:()=>L(t.id),onDownloadInvoice:t.invoiceUuid?()=>P(t.invoiceUuid,t.id):void 0},`${t.id}-${t.date}`))})]})})]})};export{le 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.