1import{b as K,j as e}from"./vendor-query-CniT1WJL.js";import{b1 as G,b2 as Y,b3 as V,b4 as _,b5 as H,b6 as J,b7 as W,b8 as X,b9 as Z,ba as ee,q as T,V as u,P as h,m as se,bb as U,I as ae,a$ as S,bc as te}from"./index-KjAD5lCC.js";import{r as D}from"./vendor-react-69GsFwrV.js";import{u as ie,A as ne}from"./AddressFormFields-Byy1VLUa.js";import{A as le,d as B}from"./AddressUseSelect-6JVVOxBe.js";import{b as $,a as F}from"./AccountSection-B7Ueu1lP.js";import{u as re,C as ce,N as oe}from"./CompanyPortalShell-S13F8qfG.js";import{a8 as de,b7 as me,ba as ue,bb as pe,h as he,P as xe,ag as Q,a3 as O}from"./vendor-ui-Ad3ANzF6.js";import"./vendor-forms-q6h4WU-p.js";import"./AccountNav-CGK2802V.js";const ge={name:"",email:"",phone:null,title:null,receivesQuotes:!1,receivesInvoices:!1,receivesPaymentReminders:!1,receivesOrderUpdates:!1,isPrimary:!1},ye={type:"both",label:"",attention:"",line1:"",line2:"",city:"",state:"",zip:"",country:"US",isDefaultBilling:!1,isDefaultShipping:!1};function y({id:t,label:i,value:d,onChange:x,type:m="text",required:a,autoComplete:p}){return e.jsxs("label",{htmlFor:t,className:"block text-caption font-semibold text-ink-2",children:[i,a?e.jsx("span",{className:"text-danger",children:" *"}):null,e.jsx(ae,{id:t,type:m,value:d,required:a,autoComplete:p,onChange:r=>x(r.currentTarget.value),className:"mt-1.5 rounded-xl"})]})}function j({id:t,label:i,checked:d,onChange:x,disabled:m,hint:a}){return e.jsxs("div",{children:[e.jsxs("label",{htmlFor:t,className:"flex min-h-10 items-center gap-2 text-sm text-ink-2",children:[e.jsx("input",{id:t,type:"checkbox",checked:d,disabled:m,onChange:p=>x(p.currentTarget.checked),className:"size-4 rounded border-card-border accent-primary disabled:opacity-50"}),i]}),a&&e.jsx("p",{className:"ml-6 text-caption text-ink-3",children:a})]})}function L({initial:t,idPrefix:i,saving:d,onCancel:x,onSave:m}){const[a,p]=D.useState(t),r=n=>p(l=>({...l,...n}));return e.jsxs("form",{className:"rounded-card border border-card-border bg-muted/50 p-4",onSubmit:n=>{n.preventDefault(),m(a)},children:[e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsx(y,{id:`${i}-name`,label:"Name",value:a.name,required:!0,autoComplete:"name",onChange:n=>r({name:n})}),e.jsx(y,{id:`${i}-email`,label:"Email",value:a.email,type:"email",required:!0,autoComplete:"email",onChange:n=>r({email:n})}),e.jsx(y,{id:`${i}-title`,label:"Title",value:a.title??"",autoComplete:"organization-title",onChange:n=>r({title:n||null})}),e.jsx(y,{id:`${i}-phone`,label:"Phone",value:a.phone??"",type:"tel",autoComplete:"tel",onChange:n=>r({phone:n||null})})]}),e.jsxs("fieldset",{className:"mt-4 grid gap-x-4 sm:grid-cols-2",children:[e.jsx("legend",{className:"mb-1 text-caption font-semibold text-ink-2",children:"Receives"}),e.jsx(j,{id:`${i}-quotes`,label:"Quotes",checked:a.receivesQuotes??!1,onChange:n=>r({receivesQuotes:n})}),e.jsx(j,{id:`${i}-invoices`,label:"Invoices",checked:a.receivesInvoices??!1,onChange:n=>r({receivesInvoices:n})}),e.jsx(j,{id:`${i}-reminders`,label:"Payment reminders",checked:a.receivesPaymentReminders??!1,onChange:n=>r({receivesPaymentReminders:n})}),e.jsx(j,{id:`${i}-orders`,label:"Order updates",checked:a.receivesOrderUpdates??!1,onChange:n=>r({receivesOrderUpdates:n})}),e.jsx(j,{id:`${i}-primary`,label:"Primary business contact",checked:a.isPrimary??!1,onChange:n=>r({isPrimary:n})})]}),e.jsxs("div",{className:"mt-4 flex flex-wrap justify-end gap-2",children:[e.jsx(u,{type:"button",size:"sm",variant:"ghost",disabled:d,onClick:x,children:"Cancel"}),e.jsx(u,{type:"submit",size:"sm",disabled:d,children:d?"Saving":"Save contact"})]})]})}function M({initial:t,idPrefix:i,saving:d,onCancel:x,onSave:m}){const[a,p]=D.useState(t),r=l=>p(f=>({...f,...l})),n=ie();return e.jsxs("form",{className:"rounded-card border border-card-border bg-muted/50 p-4",onSubmit:l=>{l.preventDefault(),n.ensureResolvedForSubmit(a).then(f=>{f&&m(a)})},children:[e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsx(y,{id:`${i}-label`,label:"Label",value:a.label,required:!0,onChange:l=>r({label:l})}),e.jsx(le,{id:`${i}
1-type`,value:a.type,onChange:l=>r({type:l,isDefaultBilling:a.isDefaultBilling&&S(l,"billing"),isDefaultShipping:a.isDefaultShipping&&S(l,"shipping")})}),e.jsx(y,{id:`${i}-attention`,label:"Attention",value:a.attention,onChange:l=>r({attention:l})}),e.jsx("div",{className:"sm:col-span-2",children:e.jsx(ne,{idPrefix:i,value:a,onChange:l=>r({...l,line2:l.line2??"",country:l.country??a.country}),check:n,required:!0})}),e.jsx(y,{id:`${i}-country`,label:"Country code",value:a.country,required:!0,autoComplete:"country",onChange:l=>r({country:l.toUpperCase()})})]}),e.jsxs("div",{className:"mt-4 grid gap-x-4 sm:grid-cols-2",children:[e.jsx(j,{id:`${i}-default-billing`,label:"Default billing address",checked:a.isDefaultBilling,disabled:!S(a.type,"billing"),hint:B(a.type,"billing"),onChange:l=>r({isDefaultBilling:l})}),e.jsx(j,{id:`${i}-default-shipping`,label:"Default shipping address",checked:a.isDefaultShipping,disabled:!S(a.type,"shipping"),hint:B(a.type,"shipping"),onChange:l=>r({isDefaultShipping:l})})]}),e.jsxs("div",{className:"mt-4 flex flex-wrap justify-end gap-2",children:[e.jsx(u,{type:"button",size:"sm",variant:"ghost",disabled:d,onClick:x,children:"Cancel"}),e.jsx(u,{type:"submit",size:"sm",disabled:d,children:d?"Saving":"Save address"})]})]})}function be(t){return{name:t.name,email:t.email,phone:t.phone,title:t.title,receivesQuotes:t.receivesQuotes,receivesInvoices:t.receivesInvoices,receivesPaymentReminders:t.receivesPaymentReminders,receivesOrderUpdates:t.receivesOrderUpdates,isPrimary:t.isPrimary}}function ve(t){return{type:t.type,label:t.label,attention:t.attention??"",line1:t.line1,line2:t.line2??"",city:t.city,state:t.state,zip:t.zip,country:t.country,isDefaultBilling:t.isDefaultBilling,isDefaultShipping:t.isDefaultShipping}}function ze(){const t=K(),{toast:i}
1=se(),d=G(),{enabled:x,capabilities:m}=re(),a=Y({query:{enabled:x,queryKey:U()}}),p=V({query:{queryKey:te()}}),r=_(),n=H(),l=J(),f=W(),q=X(),R=Z(),I=ee(),[N,A]=D.useState(null),[P,C]=D.useState(null),[w,k]=D.useState(null),b=()=>t.invalidateQueries({queryKey:U()}),o=a.data,z=n.isPending||l.isPending||f.isPending,E=q.isPending||R.isPending||I.isPending,v=s=>{i({title:"Company account was not updated",description:s instanceof Error?s.message:"Please try again.",variant:"destructive"})};return e.jsx(ce,{title:"Profile",children:a.isLoading?e.jsxs("div",{className:"grid gap-4 lg:grid-cols-2","aria-busy":"true",children:[e.jsx(T,{className:"h-64 rounded-card"}),e.jsx(T,{className:"h-64 rounded-card"})]}):a.isError||!o?e.jsx(oe,{memberships:p.data?.memberships??[],invitations:p.data?.invitations??[],email:p.data?.email??"",loading:p.isLoading}):e.jsxs("div",{className:"grid gap-4 lg:grid-cols-2 lg:items-start",children:[e.jsxs($,{icon:de,overline:o.account.accountNumber,title:o.account.dbaName||o.account.legalName,sub:o.account.dbaName?o.account.legalName:"Legal business name",action:m.canEditProfile&&!N?e.jsxs(u,{type:"button",size:"sm",variant:"ghost",onClick:()=>A({legalName:o.account.legalName,dbaName:o.account.dbaName??"",paymentTermsDays:String(o.account.paymentTermsDays),poRequired:o.account.poRequired}),children:[e.jsx(me,{className:"size-4","aria-hidden":"true"}),"Edit"]}):null,"data-testid":"company-profile-card",children:[N?e.jsxs("form",{onSubmit:s=>{s.preventDefault(),r.mutateAsync({data:{expectedVersion:o.account.version,legalName:N.legalName.trim(),dbaName:N.dbaName.trim()||null}}).then(async()=>{await b(),A(null),i({title:"Company profile updated"})}).catch(v)},children:[e.jsxs("div",{className:"grid gap-4",children:[e.jsx(y,{id:"company-legal-name",label:"Legal name",value:N.legalName,required:!0,autoComplete:"organization",onChange:s=>A(c=>c&&{...c,legalName:s})}),e.jsx(y,{id:"company-dba-name",label:"DBA name",value:N.dbaName,onChange:s=>A(c=>c&&{...c,dbaName:s})}),e.jsxs("div",{className:"rounded-xl bg-muted p-3 text-caption text-ink-2",children:[e.jsxs("p",{children:[e.jsx("span",{className:"text-ink-3",children:"Payment terms:"})," ",e.jsx("span",{className:"font-semibold text-ink",children:o.account.paymentTermsDays>0?`Net ${o.account.paymentTermsDays}`:"Due on receipt"})]}),e.jsxs("p",{className:"mt-1",children:[e.jsx("span",{className:"text-ink-3",children:"Purchase order required:"})," ",e.jsx("span",{className:"font-semibold text-ink",children:o.account.poRequired?"Yes":"No"})]}),e.jsx("p",{className:"mt-2 text-ink-3",children:"Contact us to change your payment terms or purchase-order policy."})]})]}),e.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[e.jsx(u,{type:"button",size:"sm",variant:"ghost",disabled:r.isPending,onClick:()=>A(null),children:"Cancel"}),e.jsx(u,{type:"submit",size:"sm",disabled:r.isPending,children:r.isPending?"Saving":"Save profile"})]})]}):e.jsxs("dl",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"rounded-xl bg-muted p-3",children:[e.jsx("dt",{className:"text-overline uppercase text-ink-3",children:"Payment terms"}),e.jsx("dd",{className:"mt-1 text-sm font-semibold text-ink",children:o.account.paymentTermsDays===0?"Due on receipt":`Net ${o.account.paymentTermsDays}`})]}),e.jsxs("div",{className:"rounded-xl bg-muted p-3",children:[e.jsx("dt",{className:"text-overline uppercase text-ink-3",children:"Purchase orders"}),e.jsx("dd",{className:"mt-1 text-sm font-semibold text-ink",children:o.account.poRequired?"Required":"Optional"})]})]}),m.canEditProfile?null:e.jsx("p",{className:"mt-4 text-caption text-ink-3",children:"Your company role has read-only access."})]}),e.jsxs($,{icon:ue,overline:"Document routing",title:"Contacts",sub:"Contacts receive documents without receiving sign-in access.",action:m.canEditContacts&&P===null?e.jsxs(u,{type:"button",size:"sm",variant:"ghost",onClick:()=>C("new"),children:[e.jsx(Q,{className:"size-4","aria-hidden":"true"}),"Add"]}):null,children:[P==="new"?e.jsx(L,{initial:ge,idPrefix:"new-company-contact",saving:z,onCancel:()=>C(null),onSave:async s=>{try{await n.mutateAsync({data:s}),await b(),C(null),i({title:"Contact added"})}catch(c){v(c)}}}):null,e.jsxs("div",{className:"space-y-3",children:[o.contacts.length===0&&P!=="new"?e.jsx(F,{icon:pe,message:"No business contacts yet",hint:"Add a contact before issuing company documents.",bordered:!1}):null,o.contacts.map(s=>P===s.id?e.jsx(L,{initial:be(s),idPrefix:`company-contact-${s.id}`,saving:z,onCancel:()=>C(null),onSave:async c=>{try{await l.mutateAsync({contactId:s.id,data:c}),await b(),C(null),i({title:"Contact updated"})}catch(g){v(g)}}},s.id):e.jsxs("article",{className:"rounded-card border border-card-border bg-card p-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("h3",{className:"font-semibold text-ink",children:s.name}),s.isPrimary?e.jsx(h,{variant:"mint",children:"Primary"}):null,s.status==="inactive"?e.jsx(h,{children:"Inactive"}):null]}),s.title?e.jsx("p",{className:"mt-0.5 text-caption text-ink-3",children:s.title}):null]}),m.canEditContacts&&s.status==="active"?e.jsxs("div",{className:"flex flex-wrap justify-end gap-1",children:[e.jsx(u,{type:"button",size:"sm",variant:"ghost",onClick:()=>C(s.id),children:"Edit"}),e.jsx(u,{type:"button",size:"sm",variant:"ghost",disabled:z,onClick:()=>{d({title:"Deactivate contact?",description:"This contact will stop receiving new company documents. Issued document history is unchanged.",confirmLabel:"Deactivate contact",destructive:!0}).then(async c=>{if(c)try{await f.mutateAsync({contactId:s.id}),await b(),i({title:"Contact deactivated"})}catch(g){v(g)}})},children:"Deactivate"})]}):null]}),e.jsxs("div",{className:"mt-3 space-y-1 text-caption text-ink-2",children:[e.jsxs("p",{className:"flex items-center gap-2",children:[e.jsx(he,{className:"size-3.5 text-ink-3","aria-hidden":"true"}),e.jsx("a",{className:"break-all hover:text-primary",href:`mailto:${s.email}`,children:s.email})]}),s.phone?e.jsxs("p",{className:"flex items-center gap-2",children:[e.jsx(xe,{className:"size-3.5 text-ink-3","aria-hidden":"true"}),s.phone]}):null]}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-1.5",children:[s.receivesQuotes?e.jsx(h,{variant:"outline",children:"Quotes"}):null,s.receivesInvoices?e.jsx(h,{variant:"outline",children:"Invoices"}):null,s.receivesPaymentReminders?e.jsx(h,{variant:"outline",children:"Payment reminders"}):null,s.receivesOrderUpdates?e.jsx(h,{variant:"outline",children:"Order updates"}):null]})]},s.id))]})]}),e.jsxs($,{icon:O,overline:"Billing and fulfillment",title:"Addresses",sub:"Reusable addresses are copied into issued documents.",action:m.canEditAddresses&&w===null?e.jsxs(u,{type:"button",size:"sm",variant:"ghost",onClick:()=>k("new"),children:[e.jsx(Q,{className:"size-4","aria-hidden":"true"}),"Add"]}):null,className:"lg:col-span-2",children:[w==="new"?e.jsx(M,{initial:ye,idPrefix:"new-company-address",saving:E,onCancel:()=>k(null),onSave:async s=>{const c={...s,attention:s.attention.trim()||null,line2:s.line2.trim()||null,country:s.country.toUpperCase()};try{await q.mutateAsync({data:c}),await b(),k(null),i({title:"Address added"})}catch(g){v(g)}}}):null,o.addresses.length===0&&w!=="new"?e.jsx(F,{icon:O,message:"No company addresses yet",hint:"Add b
1illing or shipping details before issuing documents.",bordered:!1}):e.jsx("div",{className:"grid gap-3 md:grid-cols-2",children:o.addresses.map(s=>w===s.id?e.jsx(M,{initial:ve(s),idPrefix:`company-address-${s.id}`,saving:E,onCancel:()=>k(null),onSave:async c=>{try{await R.mutateAsync({addressId:s.id,data:{...c,attention:c.attention.trim()||null,line2:c.line2.trim()||null,country:c.country.toUpperCase()}}),await b(),k(null),i({title:"Address updated"})}catch(g){v(g)}}},s.id):e.jsxs("article",{className:"rounded-card border border-card-border bg-card p-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("h3",{className:"font-semibold text-ink",children:s.label}),e.jsx(h,{variant:"outline",className:"capitalize",children:s.type}),s.status==="inactive"?e.jsx(h,{children:"Inactive"}):null]}),e.jsxs("address",{className:"mt-2 text-caption not-italic leading-relaxed text-ink-2",children:[s.attention?e.jsxs("span",{className:"block",children:["Attn: ",s.attention]}):null,e.jsx("span",{className:"block",children:s.line1}),s.line2?e.jsx("span",{className:"block",children:s.line2}):null,e.jsxs("span",{className:"block",children:[s.city,", ",s.state," ",s.zip]}),e.jsx("span",{className:"block",children:s.country})]})]}),m.canEditAddresses&&s.status==="active"?e.jsxs("div",{className:"flex flex-wrap justify-end gap-1",children:[e.jsx(u,{type:"button",size:"sm",variant:"ghost",onClick:()=>k(s.id),children:"Edit"}),e.jsx(u,{type:"button",size:"sm",variant:"ghost",disabled:E,onClick:()=>{d({title:"Deactivate address?",description:"This address will no longer be offered for new company documents. Issued document history is unchanged.",confirmLabel:"Deactivate address",destructive:!0}).then(async c=>{if(c)try{await I.mutateAsync({addressId:s.id}),await b(),i({title:"Address deactivated"})}catch(g){v(g)}})},children:"Deactivate"})]}):null]}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-1.5",children:[s.isDefaultBilling?e.jsx(h,{variant:"mint",children:"Default billing"}):null,s.isDefaultShipping?e.jsx(h,{variant:"mint",children:"Default shipping"}):null]})]},s.id))})]})]})})}export{ze 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.