1import{g as V,j as e,L as Y}from"./app-gYVhCmRa.js";import{r as i,aw as G,aC as E,bH as K,e as Z,aY as W,ab as X,q as $,aV as ee,J as se,cc as ae,ak as te,v as T,L as ne}from"./lucide-icons-BMXgajIY.js";import{u as le,a9 as ie,aa as re,cm as ce,cn as de,co as oe,cp as me,B as m,a as he,b6 as I,I as n,aI as ue,b as _,c as C,a5 as N,q as xe,ab as pe,D as ge,g as je,h as ve,i as ye,p as Ne,L as l,a3 as fe,o as we,G as _e,H as Ce,J as be,K as Se,M as De,P as Ae,Q as Pe,R as Fe}from"./App-BHwpakgI.js";import"./demo-app-entry-D_9sjuUq.js";import"./client-Cq2WFJ68.js";import"./typeProfiles-JZsCo5-z.js";import"./index-BwmZbRqR.js";import"./index-BXajkYFU.js";import"./index-C0uYDMhq.js";import"./index-DBSpuipQ.js";import"./index-DH8rEaAI.js";import"./index-P30Trk1K.js";const b={name:"",contact_name:"",email:"",phone:"",address:"",city:"",state:"",zip:"",country:"US",payment_terms:"net_30",lead_time_days:7,account_number:"",notes:""};function Re(){const{toast:o}=le(),B=ie(),M=V(),[h,O]=i.useState(""),[U,p]=i.useState(!1),[q,g]=i.useState(!1),[u,j]=i.useState(null),[x,S]=i.useState(null),[a,t]=i.useState(b);i.useEffect(()=>{p(!1),g(!1),j(null)},[M.key]);const r=re({itemLabel:"suppliers"}),{data:v,isLoading:D,refetch:H}=ce({includeInactive:!0}),A=de(),P=oe(),y=me(),d=i.useMemo(()=>{if(!v)return[];if(h.length<2)return v;const s=h.toLowerCase();return v.filter(c=>{var L,k,z;return c.name.toLowerCase().includes(s)||((L=c.contact_name)==null?void 0:L.toLowerCase().includes(s))||((k=c.email)==null?void 0:k.toLowerCase().includes(s))||((z=c.phone)==null?void 0:z.toLowerCase().includes(s))})},[v,h]);i.useEffect(()=>{r.setTotalItems(d.length)},[d.length]),i.useEffect(()=>{r.setCurrentPage(1)},[h]);const R=i.useMemo(()=>{if(r.isShowingAll)return d;const s=(r.currentPage-1)*r.pageSize,c=s+r.pageSize;return d.slice(s,c)},[d,r.currentPage,r.pageSize,r.isShowingAll]),f=s=>{s?(j(s),t({name:s.name,contact_name:s.contact_name||"",email:s.email||"",phone:s.phone||"",address:s.address||"",city:s.city||"",state:s.state||"",zip:s.zip||"",country:s.country||"US",payment_terms:s.payment_terms||"net_30",lead_time_days:s.lead_time_days||7,account_number:s.account_number||"",notes:s.notes||""})):(j(null),t(b)),p(!0)},F=()=>{p(!1),j(null),t(b)},Q=async()=>{if(!a.name.trim()){o({title:"Name is required",variant:"destructive"});return}try{u?(await P.mutateAsync({id:u.id,updates:a}),o({title:"Supplier updated successfully"})):(await A.mutateAsync({...a,company_id:B,is_active:!0}),o({title:"Supplier created successfully"})),F()}catch(s){o({title:"Error",description:s.message||"Failed to save supplier",variant:"destructive"})}},J=async()=>{if(x)try{await y.mutateAsync(x.id),o({title:"Supplier deleted successfully"}),g(!1),S(null)}catch(s){o({title:"Error",description:s.message||"Failed to delete supplier",variant:"destructive"})}},w=A.isPending||P.isPending;return e.jsxs("div",{className:"w-full py-3 md:py-6 px-4 sm:px-6 md:px-12 space-y-4 md:space-y-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(m,{variant:"ghost",size:"sm",asChild:!0,children:e.jsxs(Y,{to:he.inventory(),children:[e.jsx(G,{className:"h-4 w-4 mr-2"}),"Back"]})}),e.jsx("div",{children:e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold tracking-tight",children:"Suppliers"})})]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs(I,{size:"sm",onClick:()=>f(),children:[e.jsx(E,{className:"h-4 w-4 mr-2"}),"Add Supplier"]})})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("div",{className:"relative flex-1 max-w-md",children:[e.jsx(K,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(n,{placeholder:"Search suppliers...",value:h,onChange:s=>O(s.target.value),className:"pl-10"})]}),e.jsx(m,{variant:"outline",size:"sm",onClick:()=>H(),children:e.jsx(Z,{className:ue("h-4 w-4",D&&"animate-spin")})})]}),D?e.jsx("div",{className:"grid gap-4 sm:grid-cols-2 lg:grid-cols-3",children:[1,2,3].map(s=>e.jsx(_,{className:"bg-white border-none shadow-sm",children:e.jsxs(C,{className:"p-6",children:[e.jsx(N,{className:"h-6 w-48 mb-2"}),e.jsx(N,{className:"h-4 w-32 mb-4"}),e.jsx(N,{className:"h-4 w-full mb-2"}),e.jsx(N,{className:"h-4 w-2/3"})]})},s))}):d.length>0?e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"grid gap-4 sm:grid-cols-2 lg:grid-cols-3",children:R.map(s=>e.jsx(_,{className:"bg-white border-none shadow-sm hover:shadow-md transition-shadow",children:e.jsxs(C,{className:"p-6",children:[e.jsxs("div",{className:"flex items-start justify-between mb-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-lg",children:s.name}),s.contact_name&&e.jsxs("p",{className:"text-sm text-muted-foreground flex items-center gap-1",children:[e.jsx(W,{className:"h-3 w-3"}),s.contact_name]})]}),e.jsx(xe,{variant:s.is_active?"default":"secondary",children:s.is_active?"Active":"Inactive"})]}),e.jsxs("div",{className:"space-y-2 text-sm mb-4",children:[s.email&&e.jsxs("p",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx(X,{className:"h-4 w-4"}),s.email]}),s.phone&&e.jsxs("p",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx($,{className:"h-4 w-4"}),s.phone]}),(s.city||s.state)&&e.jsxs("p",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx(ee,{className:"h-4 w-4"}
1),[s.city,s.state].filter(Boolean).join(", ")]}),s.lead_time_days&&e.jsxs("p",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx(se,{className:"h-4 w-4"}),s.lead_time_days," day lead time"]})]}),e.jsxs("div",{className:"flex gap-2 pt-2 border-t",children:[e.jsxs(m,{variant:"outline",size:"sm",className:"flex-1",onClick:()=>f(s),children:[e.jsx(ae,{className:"h-4 w-4 mr-1"}),"Edit"]}),e.jsx(m,{variant:"ghost",size:"sm",className:"text-destructive hover:bg-destructive/10",onClick:()=>{S(s),g(!0)},children:e.jsx(te,{className:"h-4 w-4"})})]})]})},s.id))}),d.length>0&&e.jsx(pe,{...r.paginationProps})]}):e.jsx(_,{className:"bg-white border-none shadow-sm",children:e.jsxs(C,{className:"py-12 text-center",children:[e.jsx(T,{className:"h-12 w-12 mx-auto mb-4 text-muted-foreground/20"}),e.jsx("h3",{className:"text-lg font-medium mb-2",children:"No suppliers yet"}),e.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:"Add your first supplier to start managing purchase orders"}),e.jsxs(I,{onClick:()=>f(),children:[e.jsx(E,{className:"h-4 w-4 mr-2"}),"Add Supplier"]})]})}),e.jsx(ge,{open:U,onOpenChange:p,children:e.jsxs(je,{className:"sm:max-w-xl max-h-[90vh] overflow-y-auto",children:[e.jsxs(ve,{children:[e.jsxs(ye,{className:"flex items-center gap-2",children:[e.jsx(T,{className:"h-5 w-5 text-primary"}),u?"Edit Supplier":"Add Supplier"]}),e.jsx(Ne,{children:u?"Update supplier information":"Add a new supplier to your vendor list"})]}),e.jsxs("div",{className:"grid gap-4 py-4",children:[e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{htmlFor:"name",children:"Supplier Name *"}),e.jsx(n,{id:"name",value:a.name,onChange:s=>t({...a,name:s.target.value}),placeholder:"Company name"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{htmlFor:"contact_name",children:"Contact Person"}),e.jsx(n,{id:"contact_name",value:a.contact_name,onChange:s=>t({...a,contact_name:s.target.value}),placeholder:"Primary contact"})]})]}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{htmlFor:"email",children:"Email"}),e.jsx(n,{id:"email",type:"email",value:a.email,onChange:s=>t({...a,email:s.target.value}),placeholder:"[email protected]"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{htmlFor:"phone",children:"Phone"}),e.jsx(n,{id:"phone",value:a.phone,onChange:s=>t({...a,phone:s.target.value}),placeholder:"(555) 123-4567"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{htmlFor:"address",children:"Address"}),e.jsx(n,{id:"address",value:a.address,onChange:s=>t({...a,address:s.target.value}),placeholder:"Street address"})]}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-4",children:[e.jsxs("div",{className:"space-y-2 sm:col-span-2",children:[e.jsx(l,{htmlFor:"city",children:"City"}),e.jsx(n,{id:"city",value:a.city,onChange:s=>t({...a,city:s.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{htmlFor:"state",children:"State"}),e.jsx(n,{id:"state",value:a.state,onChange:s=>t({...a,state:s.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{htmlFor:"zip",children:"ZIP"}),e.jsx(n,{id:"zip",value:a.zip,onChange:s=>t({...a,zip:s.target.value})})]})]}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{htmlFor:"payment_terms",children:"Payment Terms"}),e.jsx(n,{id:"payment_terms",value:a.payment_terms,onChange:s=>t({...a,payment_terms:s.target.value}),placeholder:"net_30"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{htmlFor:"lead_time_days",children:"Lead Time (days)"}),e.jsx(n,{id:"lead_time_days",type:"number",min:"0",value:a.lead_time_days,onChange:s=>{const c=s.target.value;t({...a,lead_time_days:c===""?0:parseInt(c)||0})}})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{htmlFor:"account_number",children:"Account #"}),e.jsx(n,{id:"account_number",value:a.account_number,onChange:s=>t({...a,account_number:s.target.value}),placeholder:"Your account number"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{htmlFor:"notes",children:"Notes"}),e.jsx(fe,{id:"notes",value:a.notes,onChange:s=>t({...a,notes:s.target.value}),placeholder:"Additional notes about this supplier...",rows:3})]})]}),e.jsxs(we,{children:[e.jsx(m,{variant:"outline",onClick:F,disabled:w,children:"Cancel"}),e.jsxs(m,{onClick:Q,disabled:w,children:[w&&e.jsx(ne,{className:"h-4 w-4 mr-2 animate-spin"}),u?"Save Changes":"Add Supplier"]})]})]})}),e.jsx(_e,{open:q,onOpenChange:g,children:e.jsxs(Ce,{children:[e.jsxs(be,{children:[e.jsx(Se,{children:"Delete Supplier?"}),e.jsxs(De,{children:['This will remove "',x==null?void 0:x.name,'" from your suppliers list. This action cannot be undone.']})]}),e.jsxs(Ae,{children:[e.jsx(Pe,{disabled:y.isPending,children:"Cancel"}),e.jsx(Fe,{onClick:J,disabled:y.isPending,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:y.isPending?"Deleting...":"Delete"})]})]})})]})}export{Re 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.