1import{j as e}from"./vendor-ui-r4iVzRl6.js";import{m as G,i as K,r as b}from"./vendor-react-BfGFalVa.js";import{y as R,b as C,T as Q,u as Z,n as ee,a6 as se,a7 as m,a8 as x,a9 as h,aa as p,I as u,ab as f,B as d,N as ae,L as re,C as v,g as _,h as N,i as g}from"./index-DrTqwVsL.js";import{T as ne,a as ie,b as k,c as V}from"./tabs-2dj5w2bN.js";import{S as F,a as A,b as E,c as P}from"./sheet-DIXpj0oV.js";import{A as te,a as le,b as ce,c as de,d as oe,e as me,f as xe,g as he}from"./alert-dialog-2ZJErjf2.js";import{T as L,a as I,b as M,c as z}from"./tooltip-BnFtVbt5.js";import{C as pe}from"./circle-check-big-BK41ADMh.js";import{C as je}from"./circle-x-Bv6CAPMt.js";import{V as ue,a as fe}from"./vendor-trade-badges-kanwJyWM.js";import{V as ve}from"./vendor-form-Cs1EK_tX.js";import{C as ge}from"./checkbox-BTZnd2FC.js";import{v as _e}from"./vendor-BikM7aFW.js";import{d as Ne,e as ye,g as we,h as be,i as Ce,j as ke}from"./use-vendors-PGfEu7h8.js";import{n as Ve}from"./use-work-orders-B0oz3yCR.js";import{A as Se}from"./arrow-left-tscW42Lh.js";import{S as O}from"./star-YK2OuSps.js";import{S as B}from"./square-pen-BVptv9S_.js";import{T as Te}from"./trash-2-CnMRvDbx.js";import{P as De}from"./phone-DPwBVNEa.js";import{M as Fe}from"./mail-C_k2pCDI.js";import{M as Ae}from"./map-pin-i4zEv0SS.js";import"./vendor-query-DHLwvY3K.js";import"./vendor-supabase-OAvKDiam.js";import"./vendor-charts-D47kEIWf.js";import"./textarea-CYUWIRDh.js";const Ee=[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"m9 15 2 2 4-4",key:"1grp1n"}]],Pe=R("file-check",Ee);const Le=[["path",{d:"M8.34 8.34 2 9.27l5 4.87L5.82 21 12 17.77 18.18 21l-.59-3.43",ke
1y:"16m0ql"}],["path",{d:"M18.42 12.76 22 9.27l-6.91-1L12 2l-1.44 2.91",key:"1vt8nq"}],["line",{x1:"2",x2:"22",y1:"2",y2:"22",key:"a6p6uj"}]],Ie=R("star-off",Le);function Me({compliance:j}){const{is_compliant:l,issues:i,license_expires_soon:c,insurance_expires_soon:r}=j;return l&&!c&&!r?e.jsxs(C,{variant:"default",className:"bg-green-100 text-green-800 hover:bg-green-100",children:[e.jsx(pe,{className:"mr-1 h-3 w-3"}),"Compliant"]}):l&&(c||r)?e.jsx(L,{children:e.jsxs(I,{children:[e.jsx(M,{asChild:!0,children:e.jsxs(C,{variant:"secondary",className:"bg-yellow-100 text-yellow-800 hover:bg-yellow-100 cursor-help",children:[e.jsx(Q,{className:"mr-1 h-3 w-3"}),"Expiring Soon"]})}),e.jsx(z,{children:e.jsxs("ul",{className:"text-xs space-y-1",children:[c&&e.jsx("li",{children:"License expires within 30 days"}),r&&e.jsx("li",{children:"Insurance expires within 30 days"})]})})]})}):e.jsx(L,{children:e.jsxs(I,{children:[e.jsx(M,{asChild:!0,children:e.jsxs(C,{variant:"destructive",className:"cursor-help",children:[e.jsx(je,{className:"mr-1 h-3 w-3"}),"Issues"]})}),e.jsx(z,{children:e.jsx("ul",{className:"text-xs space-y-1",children:i.map((a,o)=>e.jsx("li",{children:a},o))})})]})})}function ze({defaultValues:j,onSubmit:l,onCancel:i,isLoading:c}){const r=Z({resolver:ee(_e),defaultValues:{license_number:"",license_expiration:"",insurance_company:"",insurance_policy_number:"",insurance_expiration:"",w9_on_file:!1,w9_received_date:"",...j}});return e.jsx(se,{...r,children:e.jsxs("form",{onSubmit:r.handleSubmit(l),className:"space-y-6",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"font-medium",children:"License Information"}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(m,{control:r.control,name:"license_number",render:({field:a})=>e.jsxs(x,{children:[e.jsx(h,{children:"License Number"}),e.jsx(p,{children:e.jsx(u,{...a,value:a.value??""})}),e.jsx(f,{})]})}),e.jsx(m,{control:r.control,name:"license_expiration",render:({field:a})=>e.jsxs(x,{children:[e.jsx(h,{children:"Expiration Date"}),e.jsx(p,{children:e.jsx(u,{type:"date",...a,value:a.value??""})}),e.jsx(f,{})]})})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"font-medium",children:"Insurance Information"}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(m,{control:r.control,name:"insurance_company",render:({field:a})=>e.jsxs(x,{children:[e.jsx(h,{children:"Insurance Company"}),e.jsx(p,{children:e.jsx(u,{...a,value:a.value??""})}),e.jsx(f,{})]})}),e.jsx(m,{control:r.control,name:"insurance_policy_number",render:({field:a})=>e.jsxs(x,{children:[e.jsx(h,{children:"Policy Number"}),e.jsx(p,{children:e.jsx(u,{...a,value:a.value??""})}),e.jsx(f,{})]})})]}),e.jsx(m,{control:r.control,name:"insurance_expiration",render:({field:a})=>e.jsxs(x,{children:[e.jsx(h,{children:"Expiration Date"}),e.jsx(p,{children:e.jsx(u,{type:"date",...a,value:a.value??""})}),e.jsx(f,{})]})})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"font-medium",children:"W-9 Form"}),e.jsx(m,{control:r.control,name:"w9_on_file",render:({field:a})=>e.jsxs(x,{className:"flex items-center gap-2",children:[e.jsx(p,{children:e.jsx(ge,{checked:a.value,onCheckedChange:a.onChange})}),e.jsx(h,{className:"!mt-0",children:"W-9 on file"})]})}),r.watch("w9_on_file")&&e.jsx(m,{control:r.control,name:"w9_received_date",render:({field:a})=>e.jsxs(x,{children:[e.jsx(h,{children:"Date Received"}),e.jsx(p,{children:e.jsx(u,{type:"date",...a,value:a.value??""})}),e.jsx(f,{})]})})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(d,{type:"button",variant:"outline",onClick:i,children:"Cancel"}),e.jsx(d,{type:"submit",disabled:c,children:c?"Saving...":"Save Compliance Info"})]})]})})}function ms(){const{id:j}=G(),l=K(),{toast:i}=ae(),[c,r]=b.useState(!1),[a,o]=b.useState(!1),[U,y]=b.useState(!1),{data:s,isLoading:W}=Ne(j),{data:w=[]}=Ve(j),S=ye(),T=we(),D=be(),q=Ce();if(W)return e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(re,{className:"h-8 w-8 animate-spin text-muted-foreground"})});if(!s)return e.jsx("div",{className:"container py-6",children:e.jsx("p",{className:"text-muted-foreground",children:"Vendor not found"})});const t=ke({license_expiration:s.license_expiration,insurance_expiration:s.insurance_expiration,w9_on_file:s.w9_on_file}),H=async n=>{try{await S.mutateAsync({id:s.id,data:n}),r(!1),i({title:"Vendor updated",description:"Vendor information has been saved"})}catch{i({variant:"destructive",title:"Error",description:"Failed to update vendor"})}},$=async n=>{try{await T.mutateAsync({id:s.id,data:n}),o(!1),i({title:"Compliance updated",description:"Compliance information has been saved"})}catch{i({variant:"destructive",title:"Error",description:"Failed to update compliance"})}},J=async()=>{try{await D.mutateAsync({id:s.id,isPreferred:!s.is_preferred}),i({title:s.is_preferred?"Removed from preferred":"Marked as preferred"})}catch{i({variant:"destructive",title:"Error",description:"Failed to update vendor"})}},X=async()=>{try{await q.mutateAsync(s.id),y(!1),i({title:"Vendor deactivated",description:"Vendor has been deactivated"}),l("/vendors")}catch{i({variant:"destructive",title:"Error",description:"Failed to deactivate vendor"})}};return e.jsxs("div",{className:"container py-6 space-y-6",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs(d,{variant:"ghost",size:"sm",onClick:()=>l("/vendors"),children:[e.jsx(Se,{className:"mr-2 h-4 w-4"}),"Back to Vendors"]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("h1",{className:"text-2xl font-bold",children:s.company_name}),s.is_preferred&&e.jsx(O,{className:"h-5 w-5 fill-yellow-400 text-yellow-400"})]}),e.jsx(ue,{trades:s.trade_categories||[],maxShow:5})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(d,{variant:"outline",size:"icon",onClick:J,disabled:D.isPending,children:s.is_preferred?e.jsx(Ie,{className:"h-4 w-4"}):e.jsx(O,{className:"h-4 w-4"})}),e.jsxs(d,{variant:"outline",onClick:()=>r(!0),children:[e.jsx(B,{className:"mr-2 h-4 w-4"}),"Edit"]}),e.jsxs(d,{variant:"outline",onClick:()=>y(!0),children:[e.jsx(Te,{className:"mr-2 h-4 w-4"}),"Deactivate"]})]})]}),e.jsxs(ne,{defaultValue:"overview",children:[e.jsxs(ie,{children:[e.jsx(k,{value:"overview",children:"Overview"}),e.jsx(k,{value:"compliance",children:"Compliance"}),e.jsxs(k,{value:"work-orders",children:["Work Orders (",w.length,")"]})]}),e.jsxs(V,{value:"overview",className:"space-y-6 pt-4",children:[e.jsxs("div",{className:"grid gap-6 md:grid-cols-3",children:[e.jsxs(v,{children:[e.jsx(_,{children:e.jsx(N,{children:"Contact Information"})}),e.jsxs(g,{className:"space-y-3",children:[s.contact_name&&e.jsx("p",{className:"font-medium",children:s.contact_name}),s.phone&&e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(De,{className:"h-4 w-4 text-muted-foreground"}),s.phone]}),s.email&&e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(Fe,{className:"h-4 w-4 text-muted-foreground"}),s.email]}),s.address_line1&&e.jsxs("div",{className:"flex items-start gap-2 text-sm",children:[e.jsx(Ae,{className:"h-4 w-4 text-muted-foreground mt-0.5"}),e.jsxs("div",{children:[e.jsx("p",{children:s.address_line1}),s.address_line2&&e.jsx("p",{children:s.address_line2}),e.jsxs("p",{children:[s.city,", ",s.state," ",s.zip]})]})]})]})]}),e.jsxs(v,{children:[e.jsx(_,{children:e.jsx(N,{children:"Performance"})}),e.jsxs(g,{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Rating"}),e.jsx(fe,{rating:s.average_rating,showLabel:!0,size:"lg"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Jobs Completed"}),e.jsxs("p",{className:"text-2xl font-bold",children:[s.completed_jobs||0,e.jsxs("span",{className:"text-sm font-normal text-muted-foreground",children:[" ","/ ",s.total_jobs||0]})]}),s.completion_rate!==null&&e.jsxs("p",{className:"text-sm text-muted-foreground",children:[(s.completion_rate*100).toFixed(0),"% completion rate"]})]}),s.average_response_hours&&e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Avg Response Time"}),e.jsxs("p",{className:"text-lg font-semibold",children:[s.average_response_hours.toFixed(1)," hours"]})]})]})]}),e.jsxs(v,{children:[e.jsx(_,{children:e.jsxs(N,{className:"flex items-center justify-between",children:[e.jsx("span",{children:"Compliance"}),e.jsx(Me,{compliance:t})]})}),e.jsxs(g,{className:"space-y-3",children:[t.issues.length>0?e.jsx("ul",{className:"space-y-1",children:t.issues.map((n,Y)=>e.jsxs("li",{className:"text-sm text-destructive flex items-center gap-2",children:["* ",n]},Y))}):e.jsx("p",{className:"text-sm text-green-600",children:"All compliance requirements met"}),e.jsxs(d,{variant:"outline",size:"sm",className:"w-full",onClick:()=>o(!0),children:[e.jsx(Pe,{className:"mr-2 h-4 w-4"}
1),"Update Compliance"]})]})]})]}),s.notes&&e.jsxs(v,{children:[e.jsx(_,{children:e.jsx(N,{children:"Notes"})}),e.jsx(g,{children:e.jsx("p",{className:"whitespace-pre-wrap",children:s.notes})})]})]}),e.jsx(V,{value:"compliance",className:"pt-4",children:e.jsxs(v,{children:[e.jsxs(_,{className:"flex flex-row items-center justify-between",children:[e.jsx(N,{children:"Compliance Details"}),e.jsxs(d,{variant:"outline",onClick:()=>o(!0),children:[e.jsx(B,{className:"mr-2 h-4 w-4"}),"Update"]})]}),e.jsx(g,{children:e.jsxs("div",{className:"grid gap-6 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium",children:"License"}),e.jsxs("div",{className:"p-4 border rounded-lg space-y-2",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Number:"}),e.jsx("span",{children:s.license_number||"-"})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Expires:"}),e.jsx("span",{className:t.license_valid?t.license_expires_soon?"text-yellow-600":"":"text-destructive",children:s.license_expiration||"-"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium",children:"Insurance"}),e.jsxs("div",{className:"p-4 border rounded-lg space-y-2",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Company:"}),e.jsx("span",{children:s.insurance_company||"-"})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Policy #:"}),e.jsx("span",{children:s.insurance_policy_number||"-"})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Expires:"}),e.jsx("span",{className:t.insurance_valid?t.insurance_expires_soon?"text-yellow-600":"":"text-destructive",children:s.insurance_expiration||"-"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium",children:"W-9 Form"}),e.jsxs("div",{className:"p-4 border rounded-lg space-y-2",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"On File:"}),e.jsx("span",{className:t.w9_on_file?"text-green-600":"text-destructive",children:t.w9_on_file?"Yes":"No"})]}),s.w9_received_date&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Received:"}),e.jsx("span",{children:s.w9_received_date})]})]})]})]})})]})}),e.jsx(V,{value:"work-orders",className:"pt-4",children:w.length===0?e.jsx("div",{className:"text-center py-12",children:e.jsx("p",{className:"text-muted-foreground",children:"No work orders for this vendor"})}):e.jsx("div",{className:"grid gap-4",children:w.map(n=>e.jsx(v,{className:"cursor-pointer hover:bg-accent/50",onClick:()=>l(`/work-orders/${n.id}`),children:e.jsx(g,{className:"py-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:n.title}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[n.work_order_number," - ",n.property?.name]})]}),e.jsxs("div",{className:"text-right",children:[e.jsx("p",{className:"text-sm font-medium",children:n.status}),n.scheduled_date&&e.jsx("p",{className:"text-sm text-muted-foreground",children:n.scheduled_date})]})]})})},n.id))})})]}),e.jsx(F,{open:c,onOpenChange:r,children:e.jsxs(A,{className:"w-full sm:max-w-lg overflow-y-auto",children:[e.jsx(E,{children:e.jsx(P,{children:"Edit Vendor"})}),e.jsx("div",{className:"mt-6",children:e.jsx(ve,{defaultValues:{company_name:s.company_name,contact_first_name:s.contact_first_name,contact_last_name:s.contact_last_name,email:s.email,phone:s.phone,address_line1:s.address_line1,address_line2:s.address_line2,city:s.city,state:s.state,zip:s.zip,trade_categories:s.trade_categories||[],is_preferred:s.is_preferred||!1,notes:s.notes},onSubmit:H,onCancel:()=>r(!1),isLoading:S.isPending,isEdit:!0})})]})}),e.jsx(F,{open:a,onOpenChange:o,children:e.jsxs(A,{className:"w-full sm:max-w-lg overflow-y-auto",children:[e.jsx(E,{children:e.jsx(P,{children:"Update Compliance"})}),e.jsx("div",{className:"mt-6",children:e.jsx(ze,{defaultValues:{license_number:s.license_number,license_expiration:s.license_expiration,insurance_company:s.insurance_company,insurance_policy_number:s.insurance_policy_number,insurance_expiration:s.insurance_expiration,w9_on_file:s.w9_on_file||!1,w9_received_date:s.w9_received_date},onSubmit:$,onCancel:()=>o(!1),isLoading:T.isPending})})]})}),e.jsx(te,{open:U,onOpenChange:y,children:e.jsxs(le,{children:[e.jsxs(ce,{children:[e.jsx(de,{children:"Deactivate Vendor?"}),e.jsx(oe,{children:"This vendor will be marked as inactive and won't appear in vendor selection. Existing work orders will not be affected."})]}),e.jsxs(me,{children:[e.jsx(xe,{children:"Cancel"}),e.jsx(he,{onClick:X,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Deactivate"})]})]})})]})}export{ms 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.