1import{u as W,r as c,m as C,j as e,e as O}from"./vendor-DviMR2vF.js";import{P as R}from"./page-template-CgzGw9vz.js";import{I as T}from"./InvoiceProSubNav-fezQUr6C.js";/* empty css */import{ah as I}from"./ui-BChMl1ia.js";import"./utils-nrJLb57x.js";import"./app-layout-C81OBHIe.js";import"./app-shared-CKDgHUBD.js";import"./app-BYrJzvVt.js";/* empty css *//* empty css */import"./language-switcher-C43LMqYv.js";import"./language-DZ9KMQZW.js";import"./motion-DBVl-vA3.js";import"./CompanySupportChatWidget-B0rrjtnP.js";import"./recharts-DMgShWG-.js";import"./input-error-BGT-deR3.js";import"./theme-Bb3szHF7.js";import"./WatilySiteWebPushProvider-DTUrbJW9.js";import"./WebPushOptIn-AUUzvCeP.js";import"./watily-ui-shell-CFP-EonI.js";const k={A:{bg:"var(--good-soft, #dcfce7)",fg:"var(--good, #16a34a)"},B:{bg:"#ccfbf1",fg:"#0f766e"},C:{bg:"#fef3c7",fg:"#b45309"},D:{bg:"#fee2e2",fg:"#b91c1c"},new:{bg:"var(--surface-2)",fg:"var(--muted)"}},Z=[{key:"all",label:"All"},{key:"A",label:"A"},{key:"B",label:"B"},{key:"C",label:"C"},{key:"D",label:"D"},{key:"overdue",label:"Overdue"}];function de({customers:_,isSuperAdmin:v=!1}){const{t}=W(),[d,w]=c.useState(""),[S,u]=c.useState(!1),[h,x]=c.useState(null),[n,A]=c.useState("all"),[j,D]=c.useState("name"),l=v?"admin.invoice-pro":"invoice-pro",m=C({name:"",phone:"",email:"",address:"",vat_number:""}),i=C({name:"",phone:"",email:"",address:"",vat_number:""}),p=_.filter(s=>s.name.toLowerCase().includes(d.toLowerCase())||(s.phone||"").includes(d)||(s.email||"").toLowerCase().includes(d.toLowerCase())).filter(s=>{var a,r;return n==="all"?!0:n==="overdue"?(((a=s.payment_score)==null?void 0:a.overdue_count)||0)>0:((r=s.payment_score)==null?void 0:r.grade)===n}).sort((s,a)=>{var r,o;return j==="outstanding"?(((r=a.payment_score)==null?void 0:r.overdue_amount)||0)-(((o=s.payment_score)==null?void 0:o.overdue_amount)||0):s.name.localeCompare(a.name)}),E=s=>{s.preventDefault(),m.post(route("".concat(l,".customers.store")),{onSuccess:()=>{u(!1),m.reset()}})},M=s=>{s.preventDefault(),h&&i.put(route("".concat(l,".customers.update"),h.id),{onSuccess:()=>{x(null),i.reset()}})},$=s=>{x(s),i.setData({name:s.name,phone:s.phone||"",email:s.email||"",address:s.address||"",vat_number:s.vat_number||""})},B=s=>{confirm(t("Are you sure you want to delete this customer?"))&&O.delete(route("".concat(l,".customers.destroy"),s))},F=[{label:t("Add Customer"),icon:e.jsx(I,{className:"w-4 h-4"}),variant:"default",onClick:()=>u(!0)}],b=s=>e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"field",children:[e.jsx("label",{className:"flbl",children:t("Name")}
1),e.jsx("input",{className:"ctl",value:s.data.name,onChange:a=>s.setData("name",a.target.value),required:!0}),s.errors.name&&e.jsx("div",{className:"form-err",children:s.errors.name})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:12},children:[e.jsxs("div",{className:"field",children:[e.jsx("label",{className:"flbl",children:t("Phone")}),e.jsx("input",{className:"ctl",dir:"ltr",value:s.data.phone,onChange:a=>s.setData("phone",a.target.value)})]}),e.jsxs("div",{className:"field",children:[e.jsx("label",{className:"flbl",children:t("Email")}),e.jsx("input",{className:"ctl",type:"email",value:s.data.email,onChange:a=>s.setData("email",a.target.value)})]})]}),e.jsxs("div",{className:"field",children:[e.jsx("label",{className:"flbl",children:t("Address")}),e.jsx("input",{className:"ctl",value:s.data.address,onChange:a=>s.setData("address",a.target.value)})]}),e.jsxs("div",{className:"field",children:[e.jsx("label",{className:"flbl",children:t("VAT Number")}),e.jsx("input",{className:"ctl",value:s.data.vat_number,onChange:a=>s.setData("vat_number",a.target.value)})]})]});return e.jsxs(R,{title:t("Customers"),description:t("Manage your customers list"),url:route("".concat(l,".customers")),actions:F,breadcrumbs:[{title:t("Dashboard"),href:route("dashboard")},{title:t("Invoice Pro"),href:route("".concat(l,".index"))},{title:t("Customers"),href:route("".concat(l,".customers"))}],children:[e.jsx(T,{section:"customers",active:"customers"}),e.jsxs("div",{className:"ipa",dir:"ltr","data-accent":"classic",children:[e.jsxs("div",{className:"card",children:[e.jsx("div",{className:"card-head",children:e.jsxs("h3",{children:[e.jsx("span",{className:"ico",children:e.jsxs("svg",{viewBox:"0 0 24 24",fill:"currentColor",children:[e.jsx("circle",{cx:"9",cy:"8",r:"4"}),e.jsx("circle",{cx:"17",cy:"8",r:"3"}),e.jsx("path",{d:"M2 21a7 7 0 0 1 14 0Zm14-3a5.4 5.4 0 0 1 6 3h-5"})]})}),t("Customers")]})}),e.jsxs("div",{className:"filter-row",children:[e.jsxs("div",{className:"filter-search",children:[e.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("circle",{cx:"11",cy:"11",r:"7"}),e.jsx("path",{d:"m20 20-3.5-3.5"})]}),e.jsx("input",{value:d,onChange:s=>w(s.target.value),placeholder:t("Search customers...")})]}),e.jsxs("select",{className:"ctl",style:{maxWidth:220},value:j,onChange:s=>D(s.target.value),children:[e.jsx("option",{value:"name",children:t("Name (A-Z)")}),e.jsx("option",{value:"outstanding",children:t("Outstanding (high to low)")})]})]}),e.jsx("div",{className:"filter-row",style:{gap:6,flexWrap:"wrap"},children:Z.map(s=>e.jsx("button",{type:"button",className:"btn ghost",onClick:()=>A(s.key),style:{padding:"4px 12px",borderRadius:999,fontSize:12,fontWeight:700,background:n===s.key?"var(--accent, #2563eb)":"var(--surface-2)",color:n===s.key?"#fff":"var(--muted)",border:"1px solid var(--line)"},children:t(s.label)},s.key))}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:t("Name")}
1),e.jsx("th",{children:t("Phone")}),e.jsx("th",{children:t("Email")}),e.jsx("th",{children:t("VAT Number")}),e.jsx("th",{children:t("Grade")}),e.jsx("th",{children:t("Outstanding")}),e.jsx("th",{style:{textAlign:"right"},children:t("Actions")})]})}),e.jsx("tbody",{children:p.map(s=>{var f,g,N,y;const a=s.payment_score,r=(f=a==null?void 0:a.grade)!=null?f:"new",o=(g=k[r])!=null?g:k.new,L=r==="new"?t("New"):r,P=a&&r!=="new"?"".concat(t("On-time rate"),": ").concat(Math.round((a.on_time_rate||0)*100),"% · ").concat(t("Avg days late"),": ").concat((N=a.avg_days_late)!=null?N:0," ").concat(t("days")," · ").concat(t("Overdue amount"),": ").concat((a.overdue_amount||0).toFixed(2)):t("Paid invoices (12mo)")+": "+((y=a==null?void 0:a.paid_invoices_count)!=null?y:0);return e.jsxs("tr",{children:[e.jsx("td",{children:e.jsx("div",{className:"cname",children:s.name})}),e.jsx("td",{className:"date",dir:"ltr",children:s.phone||"â"}),e.jsx("td",{children:s.email||"â"}),e.jsx("td",{className:"date",children:s.vat_number||"â"}),e.jsx("td",{children:e.jsx("span",{title:P,style:{display:"inline-block",padding:"2px 10px",borderRadius:999,fontSize:12,fontWeight:700,background:o.bg,color:o.fg},children:L})}),e.jsx("td",{className:"date",dir:"ltr",children:((a==null?void 0:a.overdue_amount)||0).toFixed(2)}),e.jsx("td",{children:e.jsxs("div",{className:"actions-cell",children:[!v&&route().has("invoice-pro.customers.statement")&&e.jsx("a",{className:"icon-mini",title:t("Account statement"),href:route("invoice-pro.customers.statement",s.id),children:e.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8l-6-6Z"}),e.jsx("path",{d:"M14 2v6h6M9 13h6M9 17h6"})]})}),e.jsx("button",{className:"icon-mini",title:t("Edit"),onClick:()=>$(s),children:e.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("path",{d:"M12 20h9"}),e.jsx("path",{d:"M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z"})]})}),e.jsx("button",{className:"icon-mini del",title:t("Delete"),onClick:()=>B(s.id),children:e.jsx("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"M3 6h18M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2m-3 5v6m-4-6v6M5 6l1 14a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2l1-14"})})})]})})]},s.id)})})]})}),p.length===0&&e.jsxs("div",{className:"empty",children:[e.jsx("div",{className:"ei",children:e.jsxs("svg",{viewBox:"0 0 24 24",fill:"currentColor",children:[e.jsx("circle",{cx:"9",cy:"8",r:"4"}),e.jsx("circle",{cx:"17",cy:"8",r:"3"}),e.jsx("path",{d:"M2 21a7 7 0 0 1 14 0Z"})]})}),e.jsx("div",{className:"et",children:t("No customers found")})]})]}),S&&e.jsx("div",{className:"ipa-modal",children:e.jsxs("div",{className:"box",children:[e.jsx("h3",{children:t("Add New Customer")}),e.jsxs("form",{onSubmit:E,children:[b(m),e.jsxs("div",{className:"actions",children:[e.jsx("button",{type:"button",className:"btn ghost",onClick:()=>u(!1),children:t("Cancel")}),e.jsx("button",{type:"submit",className:"btn accent",disabled:m.processing,children:t("Save")})]})]})]})}),h&&e.jsx("div",{className:"ipa-modal",children:e.jsxs("div",{className:"box",children:[e.jsx("h3",{children:t("Edit Customer")}),e.jsxs("form",{onSubmit:M,children:[b(i),e.jsxs("div",{className:"actions",children:[e.jsx("button",{type:"button",className:"btn ghost",onClick:()=>x(null),children:t("Cancel")}),e.jsx("button",{type:"submit",className:"btn accent",disabled:i.processing,children:t("Save Changes")})]})]})]})})]})]})}export{de 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.