import{a5 as T,$,b,s as L,c as f,j as _,J as S,u as a,N as h,d as c,x as d,o as r,w as D,t as P}from"./app-583c7dce.js";import{P as p,b as U,c as R,d as B}from"./invoice-63485875.js";import{_ as M}from"./ProductModal-f3dda7dd.js";import{u as O}from"./useOpenModal-94afc182.js";import{u as j}from"./useDeleteModal-484b00a2.js";import{n as A}from"./helpers-7af1206d.js";import"./useSubmitForm-184dcd88.js";import"./useEmitter-7699a4d3.js";const F={class:"content-wrapper"},Y={__name:"ProductList",setup(V){const{canAccess:i}=T(),{t}=$(),s=b("product-table"),k=b({url:p,pageSize:5,rowLimit:10,orderBy:"desc",showGridView:!1,actionType:"dropdown",paginationType:"pagination",enableRowSelect:!1,enableBulkSelect:!1,showSearch:!0,showFilter:!0,exportPermission:i("product_export"),exportData:()=>g(),columns:[{title:t("name"),type:"text",key:"name"},{title:t("price"),type:"object",key:"price",modifier:e=>A(e)},{title:t("code"),type:"text",key:"code"},{title:t("unit"),type:"object",key:"unit",modifier:e=>e?e.name:"-"},{title:t("category"),type:"object",key:"category",modifier:e=>e?e.name:"-"},{title:t("action"),type:"action",align:"right"}],filters:[{label:t("category"),type:"advance-search-select",key:"category",listKeyField:"id",listValueField:"name",rowPerLoad:10,fetchUrl:`${U}?type=category`,permission:!0},{type:"advance-search-select",key:"unit",label:t("unit"),listKeyField:"id",listValueField:"name",rowPerLoad:10,fetchUrl:`${R}`,permission:!0}],actions:[{title:t("edit"),type:"edit",icon:"bi bi-pencil-square",modifier:()=>i("update_products")},{title:t("delete"),type:"delete",icon:"bi bi-trash3",modifier:()=>i("delete_products")}]}),{isModalActive:n,selectedData:u,closeModal:w}=O(),{deleteUrl:m,isDeleteModal:y,cancelled:v}=j(),C=(e,o)=>{o.type==="edit"?(n.value=!0,u.value=`${p}/${e.id}`):o.type==="delete"&&(y.value=!0,m.value=`${p}/${e.id}`)},g=()=>{L.get(B,{responseType:"arraybuffer"}).then(e=>{let o=window.URL.createObjectURL(new Blob([e.data])),l=document.createElement("a");l.href=o,l.setAttribute("download","products_export.xlsx"),document.body.appendChild(l),l.click()})};return(e,o)=>{const l=d("app-breadcrumb"),x=d("app-datatable"),E=d("app-delete-modal");return r(),f("div",F,[_(l,{"page-title":e.$t("product_list")},{"breadcrumb-actions":S(()=>[a(i)("create_products")?(r(),f("button",{key:0,onClick:o[0]||(o[0]=D(N=>n.value=!0,["prevent"])),class:"btn btn-primary text-white"},P(e.$t("add_product")),1)):c("",!0)]),_:1},8,["page-title"]),_(x,{id:s.value,options:k.value,onAction:C},null,8,["id","options"]),a(n)?(r(),h(M,{key:0,"table-id":s.value,"modal-id":"product-modal","selected-url":a(u),onClose:a(w)},null,8,["table-id","selected-url","onClose"])):c("",!0),a(y)?(r(),h(E,{key:1,"table-id":s.value,"selected-url":a(m),onCancelled:a(v)},null,8,["table-id","selected-url","onCancelled"])):c("",!0)])}}};export{Y as default};
