1import{u as w,r,j as e,a as S,X as R}from"./index-Kbt7gc3j.js";import{B as c,C as L,I as f,S as P}from"./Input-D13OgHNR.js";import{P as _}from"./PageHeader-TDjVikB7.js";import{B as O}from"./Badge-B4MWdX5K.js";import{E as U}from"./EmptyState-1WhedNae.js";import{S as V}from"./Spinner-fD_M-TUa.js";import{T as q,a as Y,b as j,c as z,d as v}from"./Table-BKdYB3NN.js";import{P as A}from"./plus-C2U6TQ54.js";import{C as F}from"./credit-card-DQdmbA6_.js";import{E as I}from"./eye-L0qo3y0T.js";import{S as k}from"./send-DWxRRVhc.js";import{C as M}from"./copy-C29hHjwz.js";const C=s=>s==null?"â":new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",maximumFractionDigits:0}).format(Number(s)),$=s=>s?new Date(s).toLocaleDateString():"â",Q=s=>`${window.location.origin}/net-terms/${s}`,H={REQUESTED:"amber",SUBMITTED:"blue",APPROVED:"green",PARTIALLY_APPROVED:"green",DECLINED:"red"},B={REQUESTED:"Awaiting customer",SUBMITTED:"Needs review",APPROVED:"Approved",PARTIALLY_APPROVED:"Partially approved",DECLINED:"Declined"},oe=()=>{const{showToast:s}=w(),[o,m]=r.useState([]),[d,x]=r.useState(!0),[i,h]=r.useState(!1),[u,y]=r.useState({customerEmail:"",customerName:"",companyName:""}),[b,E]=r.useState(!1),[N,p]=r.useState(null),g=async()=>{x(!0);try{m(await S.get("/net-terms")||[])}finally{x(!1)}};r.useEffect(()=>{g()},[]);const D=async t=>{t.preventDefault(),E(!0);try{await S.post("/net-terms",u),s("Net Terms form sent to customer.","success"),h(!1),y({customerEmail:"",customerName:"",companyName:""}),g()}catch(a){s(a?.message||"Could not send the form.","error")}finally{E(!1)}},n=async t=>{try{await S.post(`/net-terms/${t.id}/resend`,{}),s("Reminder email re-sent.","success")}catch(a){s(a?.message||"Could not resend.","error")}},l=t=>{navigator.clipboard?.writeText(Q(t.token)).then(()=>s("Application link copied.","success"),()=>s("Could not copy link.","error"))};return e.jsxs("div",{children:[e.jsx(_,{title:"Net Terms",subtitle:"Send credit applications and review customer submissions",actions:e.jsx(c,{leftIcon:A,onClick:()=>h(!0),children:"Send Net Terms form"})}),e.jsx(L,{padded:!1,children:e.jsxs(q,{children:[e.jsx(Y,{children:e.jsxs("tr",{children:[e.jsx(j,{children:"Customer"}),e.jsx(j,{children:"Status"}),e.jsx(j,{align:"right",children:"Requested"}),e.jsx(j,{align:"right",children:"Approved"}),e.jsx(j,{children:"Updated"}),e.jsx(j,{align:"right",children:"Actions"})]})}),e.jsxs("tbody",{children:[d&&e.jsx("tr",{children:e.jsx("td",{colSpan:6,children:e.jsx(V,{center:!0,label:"Loading applicationsâ¦"})})}),!d&&o.length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:6,children:e.jsx(U,{compact:!0,icon:F,title:"No applications yet",description:"Send a Net Terms form to a customer to get started.",action:e.jsx(c,{leftIcon:A,size:"sm",onClick:()=>h(!0),children:"Send Net Terms form"})})})}),!d&&o.map(t=>e.jsxs(z,{children:[e.jsx(v,{children:e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"font-medium text-navy-900 truncate",children:t.companyName||t.customerName||t.customerEmail}),e.jsx("p",{className:"text-xs text-navy-400 truncate",children:t.customerEmail})]})}),e.jsx(v,{children:e.jsx(O,{tone:H[t.status]||"gray",dot:!0,children:B[t.status]||t.status})}),e.jsx(v,{align:"right",children:C(t.application?.requestedLimit)}),e.jsx(v,{align:"right",children:t.approvedLimit!=null?C(t.approvedLimit):"â"}),e.jsx(v,{className:"text-navy-600",children:$(t.updatedAt)}),e.jsxs(v,{align:"right",className:"whitespace-nowrap",children:[t.status==="SUBMITTED"&&e.jsx(c,{size:"sm",leftIcon:I,onClick:()=>p(t),children:"Review"}),(t.status==="APPROVED"||t.status==="PARTIALLY_APPROVED"||t.status==="DECLINED")&&e.jsx(c,{size:"sm",variant:"ghost",leftIcon:I,onClick:()=>p(t),children:"View"}),t.status==="REQUESTED"&&e.jsxs(e.Fragment,{children:[e.jsx(c,{size:"sm",variant:"ghost",leftIcon:k,onClick:()=>n(t),children:"Resend"}),e.jsx(c,{size:"sm",variant:"ghost",leftIcon:M,onClick:()=>l(t),children:"Link"})]})]})]},t.id))]})]})}),i&&e.jsx(W,{form:u,setForm:y,onClose:()=>h(!1),onSubmit:D,sending:b}),N&&e.jsx(X,{app:N,onClose:()=>p(null),onDone:()=>{p(null),g()}})]})},W=({form:s,setForm:o,onClose:m,onSubmit:d,sending:x})=>e.jsx("div",{className:"fixed inset-0 bg-navy-900/50 backdrop-blur-sm flex items-center justify-center p-4 z-50 animate-fadeIn",onClick:m,children:e.jsxs(L,{className:"w-full max-w-md animate-scaleIn",onClick:i=>i.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h2",{className:"text-lg font-bold text-navy-900",children:"Send Net Terms form"}),e.jsx("button",{onClick:m,"aria-label":"Close",className:"text-navy-400 hover:text-navy-900 transition-colors cursor-pointer",children:e.jsx(R,{className:"w-5 h-5"})})]}),e.jsxs("form",{onSubmit:d,className:"space-y-3",children:[e.jsx(f,{label:"Customer email *",type:"email",required:!0,value:s.customerEmail,onChange:i=>o({...s,customerEmail:i.target.value}),placeholder:"[email protected]"}),e.jsx(f,{label:"Contact name",value:s.customerName,onChange:i=>o({...s,customerName:i.target.value})}),e.jsx(f,{label:"Company",value:s.companyName,onChange:i=>o({...s,companyName:i.target.value})}),e.jsx("p",{className:"text-xs text-navy-500",children:"We'll email the customer a secure link to complete the credit application."}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[e.jsx(c,{type:"button",variant:"secondary",onClick:m,children:"Cancel"}),e.jsx(c,{type:"submit",loading:x,leftIcon:k,children:"Send form"})]})]})]})}),X=({app:s,onClose:o,onDone:m})=>{const{showToast:d}=w(),x=["APPROVED","PARTIALLY_APPROVED","DECLINED"].includes(s.status),[i,h]=r.useState(s.status==="PARTIALLY_APPROVED"?"PARTIALLY_APPROVED":"APPROVED"),[u,y]=r.useState(s.approvedLimit!=null?String(s.approvedLimit):String(s.application?.requestedLimit??"")),[b,E]=r.useState(s.approvedTerms||s.application?.requestedTerms||"NET_30"),[N,p]=r.useState(s.decisionNote||""),[g,D]=r.useState(!1),n=s.application||{},l=({label:a,value:T})=>e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-navy-400",children:a}),e.jsx("dd",{className:"text-sm text-navy-900",children:T||"â"})]}),t=async()=>
1{if(i!=="DECLINED"&&(!u||Number(u)<=0)){d("Enter an approved credit limit.","error");return}D(!0);try{await S.patch(`/net-terms/${s.id}/decision`,{status:i,approvedLimit:i==="DECLINED"?void 0:Number(u),approvedTerms:i==="DECLINED"?void 0:b,note:N.trim()||void 0}),d("Decision sent to customer.","success"),m()}catch(a){d(a?.message||"Could not save decision.","error")}finally{D(!1)}};return e.jsx("div",{className:"fixed inset-0 bg-navy-900/50 backdrop-blur-sm flex items-center justify-center p-4 z-50 animate-fadeIn",onClick:o,children:e.jsxs(L,{className:"w-full max-w-2xl max-h-[90vh] overflow-y-auto animate-scaleIn",onClick:a=>a.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h2",{className:"text-lg font-bold text-navy-900",children:s.companyName||s.customerName||s.customerEmail}),e.jsx("button",{onClick:o,"aria-label":"Close",className:"text-navy-400 hover:text-navy-900 transition-colors cursor-pointer",children:e.jsx(R,{className:"w-5 h-5"})})]}),e.jsxs("dl",{className:"grid sm:grid-cols-3 gap-3 mb-5",children:[e.jsx(l,{label:"Legal name",value:n.legalName}),e.jsx(l,{label:"DBA",value:n.dba}),e.jsx(l,{label:"Tax ID / EIN",value:n.taxId}),e.jsx(l,{label:"Billing address",value:n.billingAddress}),e.jsx(l,{label:"Phone",value:n.phone}),e.jsx(l,{label:"Years in business",value:n.yearsInBusiness}),e.jsx(l,{label:"Requested limit",value:n.requestedLimit!=null?C(n.requestedLimit):"â"}),e.jsx(l,{label:"Requested terms",value:n.requestedTerms?.replace("_"," ")}),e.jsx(l,{label:"AP contact",value:[n.apContactName,n.apContactEmail,n.apContactPhone].filter(Boolean).join(" · ")}),e.jsx(l,{label:"Bank reference",value:[n.bankName,n.bankContact,n.bankPhone].filter(Boolean).join(" · ")}),e.jsxs("div",{className:"sm:col-span-3",children:[e.jsx("dt",{className:"text-xs text-navy-400 mb-1",children:"Trade references"}),e.jsx("dd",{className:"text-sm text-navy-900",children:(n.tradeReferences||[]).length===0?"â":(n.tradeReferences||[]).map((a,T)=>e.jsx("div",{children:[a.name,a.contact,a.phone,a.email].filter(Boolean).join(" · ")||"â"},T))})]}),e.jsx(l,{label:"Signed by",value:[n.signerName,n.signerTitle].filter(Boolean).join(", ")})]}),x?e.jsxs("div",{className:"rounded-lg bg-navy-50 border border-navy-200 p-4",children:[e.jsxs("p",{className:"text-sm font-semibold text-navy-900",children:["Decision: ",B[s.status]]}),s.approvedLimit!=null&&e.jsxs("p",{className:"text-sm text-navy-700 mt-1",children:["Limit ",C(s.approvedLimit),s.approvedTerms?` · ${s.approvedTerms.replace("_"," ")}`:""]}),s.decisionNote&&e.jsx("p",{className:"text-sm text-navy-500 mt-1",children:s.decisionNote})]}):e.jsxs("div",{className:"border-t border-navy-100 pt-4",children:[e.jsx("h3",{className:"font-semibold text-navy-900 mb-3",children:"Decision"}),e.jsxs("div",{className:"flex flex-wrap items-end gap-3",children:[e.jsxs(P,{label:"Outcome",value:i,onChange:a=>h(a.target.value),className:"w-48",children:[e.jsx("option",{value:"APPROVED",children:"Approve"}),e.jsx("option",{value:"PARTIALLY_APPROVED",children:"Partially approve"}),e.jsx("option",{value:"DECLINED",children:"Decline"})]}),i!=="DECLINED"&&e.jsxs(e.Fragment,{children:[e.jsx(f,{label:"Approved limit (USD)",type:"number",min:"0",value:u,onChange:a=>y(a.target.value),className:"w-44"}),e.jsxs(P,{label:"Terms",value:b,onChange:a=>E(a.target.value),className:"w-36",children:[e.jsx("option",{value:"NET_15",children:"Net 15"}),e.jsx("option",{value:"NET_30",children:"Net 30"}),e.jsx("option",{value:"NET_45",children:"Net 45"}),e.jsx("option",{value:"NET_60",children:"Net 60"})]})]})]}),e.jsx(f,{label:"Note to customer (optional)",className:"mt-3",value:N,onChange:a=>p(a.target.value),placeholder:i==="DECLINED"?"Reason / next stepsâ¦":"Any conditionsâ¦"}),e.jsxs("div",{className:"flex justify-end gap-2 mt-4",children:[e.jsx(c,{variant:"secondary",onClick:o,children:"Cancel"}),e.jsx(c,{loading:g,onClick:t,children:"Send decision"})]})]})]})})};export{oe 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.