1import{r as f,e as M,d as g,u as q,j as e}from"./vendor-query-CnAhr2B8.js";import{u as L,a as R,g as $,h as K,at as A,aP as B,L as y,B as n,O,Q,R as V,T as z,V as d,b as W,aa as N,F as _,d as m,ay as w,M as G,aQ as U,aR as H}from"./index-CLUtDhnY.js";import{D as J}from"./data-table-Db5LAlAB.js";import{a as b}from"./api-c_Wfq480.js";import{E as X}from"./export-button-DuGsAr6q.js";import{F as Y}from"./feature-tip-D5lKzg4O.js";import{D as Z,a as ee,b as se,c as r}from"./dropdown-menu-QOOilEE4.js";import{C as te}from"./circle-plus-7x-fFnx-.js";import{E as ae}from"./ellipsis-vertical-CBjhnLY4.js";import{P as ie}from"./printer-DKQ1dqb2.js";import{S as ne}from"./square-pen-6eLYV1-R.js";import"./vendor-ui-CYA7SV0W.js";import"./vendor-charts-CPMWc2oJ.js";import"./vendor-forms-UY-il7MQ.js";import"./table-2PZjRc6u.js";import"./chevrons-right-BKODknhn.js";import"./lightbulb-CC4qJ2Zf.js";import"./circle-CM1Tn-8Z.js";function Pe(){const[,o]=L(),[i,C]=f.useState(""),[re,h]=f.useState(null),{toast:l}=R(),P=M(),{user:u}=$(),S=u==null?void 0:u.businessId,k=g({mutationFn:s=>b("POST",`/api/invoices/${s}/generate-link`),onSuccess:async(s,t)=>{await navigator.clipboard.writeText(s.publicUrl),h(t),setTimeout(()=>h(null),2e3),l({title:"Link Created & Copied!",description:"Payment link has been copied to clipboard"}),P.invalidateQueries({queryKey:["/api/invoices"]})},onError:s=>{l({title:"Failed to Generate Link",description:(s==null?void 0:s.message)||"Could not generate payment link",variant:"destructive"})}}),p=g({mutationFn:s=>b("POST",`/api/invoices/${s}/send-reminder`),onSuccess:()=>{l({title:"Reminder Sent",description:"Payment reminder sent to customer"})},onError:s=>{l({title:"Failed to Send",description:(s==null?void 0:s.message)||"Could not send reminder",variant:"destructive"})}}),j={businessId:S};i&&(j.status=i);const{data:x=[],isLoading:D,isError:I,error:T,refetch:E}=q({queryKey:["/api/invoices",j],staleTime:3e4,refetchOnWindowFocus:!0}),v=s=>{switch(s){case"paid":return e.jsx(m,{className:"bg-green-100 text-green-800 hover:bg-green-100",children:"Paid"});case"pending":return e.jsx(m,{className:"bg-yellow-100 text-yellow-800 hover:bg-yellow-100",children:"Pending"});case"overdue":return e.jsx(m,{className:"bg-red-100 text-red-800 hover:bg-red-100",children:"Overdue"});default:return e.jsx(m,{children:s})}},F=[{header:"Invoice",accessorKey:"invoiceNumber",cell:s=>e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-primary-600",children:s.invoiceNumber}),e.jsx("div",{className:"text-sm text-gray-500",children:w(s.createdAt)})]})},{header:"Customer",accessorKey:"customer",cell:s=>{var t,a,c;return e.jsxs("div",{children:[e.jsxs("div",{className:"font-medium",children:[(t=s.customer)==null?void 0:t.firstName," ",(a=s.customer)==null?void 0:a.lastName]}),e.jsx("div",{className:"text-sm text-gray-500",children:(c=s.customer)==null?void 0:c.phone})]})}},{header:"Amount",accessorKey:"total",cell:s=>e.jsx("div",{className:"font-medium",children:N(s.total)})},{header:"Due Date",accessorKey:"dueDate",cell:s=>s.dueDate?w(s.dueDate):"N/A"},{header:"Status",accessorKey:"status",cell:s=>v(s.status)},{header:"Actions",accessorKey:"actions",cell:s=>e.jsxs("div",{className:"flex items-center space-x-2",children:[(s.status==="pending"||s.status==="overdue")&&e.jsx(n,{variant:"default",size:"sm",onClick:t=>{t.stopPropagation(),o(`/invoices/pay/${s.id}`)},children:"Pay Now"}),e.jsxs(Z,{children:[e.jsx(ee,{asChild:!0,children:e.jsx(n,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:t=>t.stopPropagation(),children:e.jsx(ae,{className:"h-4 w-4"})})}),e.jsxs(se,{align:"end",children:[(s.status==="pending"||s.status==="overdue")&&e.jsxs(r,{onClick:t=>{t.stopPropagation(),p.mutate(s.id)},disabled:p.isPending,children:[e.jsx(G,{className:"h-4 w-4 mr-2"})," Send Reminder"]}),e.jsxs(r,{onClick:t=>{t.stopPropagation(),k.mutate(s.id)},children:[e.jsx(U,{className:"h-4 w-4 mr-2"})," Copy Payment Link"]}),e.jsxs(r,{onClick:t=>{t.stopPropagation(),window.open(`/invoices/${s.id}/print`,"_blank")},children:[e.jsx(H,{className:"h-4 w-4 mr-2"})," Download PDF"]}),e.jsxs(r,{onClick:t=>{t.stopPropagation();const a=window.open(`/invoices/${s.id}/print`,"_blank");a&&(a.onload=()=>a.print())},children:[e.jsx(ie,{className:"h-4 w-4 mr-2"})," Print"]}),e.jsxs(r,{onClick:t=>{t.stopPropagation(),o(`/invoices/${s.id}`)},children:[e.jsx(ne,{className:"h-4 w-4 mr-2"})," Edit"]})]})]})]})}];return e.jsxs(K,{title:"Invoices",children:[I&&e.jsx(A,{error:T,onRetry:()=>E()}),e.jsx(Y,{tipId:"invoices-payments",title:"Collect payments online",description:"Each invoice includes a unique payment link. Share it with customers via SMS or email so they can pay instantly with a credit card.",icon:B}),e.jsxs("div",{className:"flex justify-between items-center mb-6",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold",children:"Invoice Management"}),e.jsx("p",{className:"text-gray-500",children:"Manage all your invoices and payments"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(X,{endpoint:"/api/export/invoices",filename:"invoices.csv"}),e.jsx(y,{href:"/invoices/create",children:e.jsxs(n,{className:"flex items-center",children:[e.jsx(te,{className:"mr-2 h-4 w-4"}),"New Invoice"]})})]})]}),e.jsxs("div",{className:"bg-white rounded-lg shadow-sm border overflow-hidden",children:[e.jsxs("div",{className:"p-4 border-b flex justify-between items-center",children:[e.jsx("h3",{className:"text-lg font-medium",children:"All Invoices"}),e.jsx("div",{className:"w-64",children:e.jsxs(O,{value:i,onValueChange:C,children:[e.jsx(Q,{children:e.jsx(V,{placeholder:"Filter by status"})}),e.jsxs(z,{children:[e.jsx(d,{value:"all",children:"All Invoices"}),e.jsx(d,{value:"pending",children:"Pending"}),e.jsx(d,{value:"paid",children:"Paid"}),e.jsx(d,{value:"overdue",children:"Overdue"})]})]})})]}),D?e.jsx(W,{rows:6}):x&&x.length>0?e.jsx(J,{columns:F,data:x,onRowClick:s=>{o(`/invoices/${s.id}`)},mobileCard:s=>{var t,a;return e.jsxs("div",{className:"p-4",children:[e.jsxs("div",{className:"flex justify-between items-start",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"font-medium",children:s.invoiceNumber}),e.jsxs("div",{className:"text-sm text-muted-foreground",children:[(t=s.customer)==null?void 0:t.firstName," ",(a=s.customer)==null?void 0:a.lastName]})]}),e.jsxs("div",{className:"text-right flex-shrink-0 ml-3",children:[e.jsx("div",{className:"font-semibold",children:N(s.total)}),e.jsx("div",{className:"mt-1",children:v(s.status)})]})]}),(s.status==="pending"||s.status==="overdue")&&e.jsx("div",{className:"mt-3",children:e.jsx(n,{variant:"default",size:"sm",className:"w-full",onClick:c=>{c.stopPropagation(),o(`/invoices/pay/${s.id}`)},children:"Pay Now"})})]})}}):e.jsxs("div",{className:"flex flex-col items-center justify-center p-12 text-center",children:[e.jsx("div",{className:"mx-auto flex h-16 w-16 items-center justify-center rounded-full bg-primary/10 mb-4",children:e.jsx(_,{className:"h-8 w-8 text-primary"})}),e.jsx("h3",{className:"text-lg font-semibold text-foreground",children:i?"No matching invoices":"Send your first invoice"}),e.jsx("p",{className:"mt-2 text-sm text-muted-foreground max-w-md mx-auto",children:i?`No invoices with status "${i}". Try a different filter.`:"Create professional invoices and get paid faster. Customers can pay online via the payment link, and
1you'll be notified when they do."}),!i&&e.jsx(y,{href:"/invoices/create",children:e.jsx(n,{className:"mt-6",children:"Create Invoice"})})]})]})]})}export{Pe 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.