import{u as p,f as S,g as F,y as A,bx as I,cu as E,by as N,p as B,bz as k,j as n,D as x,h as g,bF as H,m,bA as L,bG as M,bH as j,O as P,bE as R,bI as b,b8 as V,I as G,bf as O,F as z,bT as $,ac as q,aA as K,ae as J,k as Q,aG as v,aH as U,aI as W}from"./bundle.CHKSNOJF.js";import{D as X}from"./DataTableColumnsPicker-Cp4QPk4h.js";import{I as Y}from"./ImportButton-CAP92Rev.js";import{u as Z}from"./useActions-DStR9fLW.js";import"./Import-DLbAH8Kx.js";const D=["number","name","city","phone","entity_state","created_at"];function w(){const[t,r,l,d]=k({entity:"vendor"});return["number","name","city","phone","entity_state","created_at","address2","archived_at","last_login_at","contacts","country_id","currency_id",t,r,l,d,"documents","id_number","is_deleted","postal_code","private_notes","address1","updated_at","vat_number","website"].map(u=>b(u))}function ee(){const{t}=p(),{dateFormat:r}=S(),l=F(),d=A(),i=I(),u=E(),s=N();w();const a=B.useCallback(e=>{const o=[];return e.contacts.map(C=>o.push(`${C.first_name} ${C.last_name}`)),o.join("<br />")},[]),[c,f,h,y]=k({entity:"vendor"}),T=[{column:"number",id:"number",label:t("number"),format:(e,o)=>n.jsx(x,{to:g("/vendors/:id",{id:o.id}),renderSpan:l("vendor",o),children:e})},{column:"name",id:"name",label:t("name"),format:(e,o)=>n.jsx(x,{to:g("/vendors/:id",{id:o.id}),renderSpan:l("vendor",o),children:e})},{column:"city",id:"city",label:t("city")},{column:"phone",id:"phone",label:t("phone")},{column:"entity_state",id:"id",label:t("entity_state"),format:(e,o)=>n.jsx(H,{entity:o})},{column:"created_at",id:"created_at",label:t("created_at"),format:e=>m(e,r)},{column:"last_login_at",id:"last_login",label:t("last_login"),format:e=>m(e,r)},{column:"address1",id:"address1",label:t("address1")},{column:"address2",id:"address2",label:t("address2")},{column:"archived_at",id:"archived_at",label:t("archived_at"),format:e=>m(e,r)},{column:"contacts",id:"id",label:t("contacts"),format:(e,o)=>n.jsx("span",{dangerouslySetInnerHTML:{__html:a(o)}})},{column:"country_id",id:"country_id",label:t("country"),format:e=>e&&i(e)?.name},{column:"currency_id",id:"id",label:t("currency"),format:e=>e&&u(e)?.code},{column:c,id:"custom_value1",label:c,format:e=>s("vendor1",e?.toString())},{column:f,id:"custom_value2",label:f,format:e=>s("vendor2",e?.toString())},{column:h,id:"custom_value3",label:h,format:e=>s("vendor3",e?.toString())},{column:y,id:"custom_value4",label:y,format:e=>s("vendor4",e?.toString())},{column:"documents",id:"documents",label:t("documents"),format:(e,o)=>o.documents.length},{column:"id_number",id:"id_number",label:t("id_number")},{column:"is_deleted",id:"is_deleted",label:t("is_deleted"),format:(e,o)=>o.is_deleted?t("yes"):t("no")},{column:"postal_code",id:"postal_code",label:t("postal_code")},{column:"private_notes",id:"private_notes",label:t("private_notes"),format:e=>n.jsx(L,{width:"auto",tooltipElement:n.jsx("div",{className:"w-full max-h-48 overflow-auto whitespace-normal break-all",children:n.jsx("article",{className:P("prose prose-sm",{"prose-invert":!d?.dark_mode}),dangerouslySetInnerHTML:{__html:j(e)}})}),children:n.jsx("span",{children:M(j(e)).slice(0,50)})})},{column:"updated_at",id:"updated_at",label:t("updated_at"),format:e=>m(e,r)},{column:"vat_number",id:"vat_number",label:t("vat_number")},{column:"website",id:"website",label:t("website"),format:e=>n.jsx(R,{text:e.toString()})}],_=d?.react_table_columns?.vendor||D;return T.filter(e=>_.includes(b(e.column))).sort((e,o)=>_.indexOf(b(e.column))-_.indexOf(b(o.column)))}const te=()=>{const[t]=p(),r=$(),l=s=>s.some(({documents:a})=>a.length),d=s=>s.flatMap(({documents:a})=>a.map(({id:c})=>c)),i=(s,a)=>{const c=d(s);r(c,"download"),a?.([])};return[({selectedResources:s,setSelected:a})=>n.jsx(V,{onClick:()=>s&&l(s)?i(s,a):z.error("no_documents_to_download"),icon:n.jsx(G,{element:O}),children:t("documents")})]};function le(){const{documentTitle:t}=q("vendors"),[r]=p(),l=K(),d=[{name:r("vendors"),href:"/vendors"}],i=Z(),u=ee(),s=w(),a=te();return n.jsx(J,{title:t,breadcrumbs:d,children:n.jsx(Q,{resource:"vendor",columns:u,endpoint:"/api/v1/vendors?sort=id|desc",bulkRoute:"/api/v1/vendors/bulk",linkToCreate:"/vendors/create",linkToEdit:"/vendors/:id/edit",withResourcefulActions:!0,customActions:i,customBulkActions:a,rightSide:n.jsxs("div",{className:"flex items-center space-x-2",children:[n.jsx(X,{columns:s,defaultColumns:D,table:"vendor"}),n.jsx(U,{type:"component",guards:[W(v("create_vendor"),v("edit_vendor"))],component:n.jsx(Y,{route:"/vendors/import"})})]}),linkToCreateGuards:[v("create_vendor")],hideEditableOptions:!l("edit_vendor"),enableSavingFilterPreference:!0,dateRangeColumns:[{column:"created_at",queryParameterKey:"created_between"}],enableSavingLatestDataForNavigation:!0})})}export{le as default};
