import{O as S,g as V,S as z,A as B,U as H,z as R}from"./primevue-CfIk0_DY.js";import{b as w,s as i}from"./index-BxIwIJfy.js";import{o as U,b as x,c as _,d as l,t as c,v as s,l as r,f as j,a as d,y as T}from"./vue-core-Di3IuVqe.js";import"./cjs-helpers-psZwOBky.js";import"./vue-cal-DKMVGERa.js";import"./moment-BeHQNF8T.js";const E={class:"max-w-6xl mx-auto"},M={class:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3",style:{"margin-bottom":"16px"}},O={class:"text-gray-500",style:{"margin-top":"2px"}},L=["src"],q={key:1,class:"bg-slate-100 rounded flex items-center justify-center",style:{width:"40px",height:"40px"}},G={class:"font-mono text-gray-700"},J={class:"text-gray-700"},K={class:"font-semibold text-gray-900"},se={__name:"PortailClientCatalogue",setup(Q){const u=T(()=>i.state.portailClientDb),f=T(()=>i.state.portailClientToken),n=d([]),p=d(!1),m=d("");let g=null;const h=d({}),y=t=>{if(!t)return null;const e=h.value[t];return e?`${i.lienApi}${e}`:null},k=async()=>{try{const t=await w.get(`${i.lienApi}/portail-client/articles-images/${u.value}`,{headers:{Authorization:`Bearer ${f.value}`}});h.value=t.data||{}}catch{h.value={}}},v=t=>t==null?"0,00":Number(t).toLocaleString("fr-FR",{minimumFractionDigits:2,maximumFractionDigits:2}),$=t=>{const e=Number(t||0);return e<=0?"Epuise":e<=5?"Faible":"En stock"},C=t=>{const e=Number(t||0);return e<=0?"danger":e<=5?"warn":"success"},b=async()=>{if(u.value){p.value=!0;try{const t=await w.get(`${i.lienApi}/portail-client/catalogue/${u.value}`,{params:{recherche:m.value},headers:{Authorization:`Bearer ${f.value}`}});n.value=t.data||[]}catch{n.value=[]}finally{p.value=!1}}},P=()=>{clearTimeout(g),g=setTimeout(b,300)};return U(()=>{b(),k()}),(t,e)=>{const I=S,A=V,D=z,o=B,F=H,N=R;return x(),_("div",E,[l("div",M,[l("div",null,[e[1]||(e[1]=l("h1",{class:"text-2xl font-bold text-gray-800"},"Catalogue",-1)),l("p",O,c(n.value.length)+" article(s)",1)]),s(D,{iconPosition:"left",style:{"max-width":"320px",width:"100%"}},{default:r(()=>[s(I,{class:"pi pi-search"}),s(A,{modelValue:m.value,"onUpdate:modelValue":e[0]||(e[0]=a=>m.value=a),placeholder:"Recherche (libelle, code, reference)",size:"small",class:"w-full",onInput:P},null,8,["modelValue"])]),_:1})]),s(N,{value:n.value,loading:p.value,stripedRows:"",size:"small",paginator:"",rows:50,rowsPerPageOptions:[20,50,100,200],class:"bg-white rounded-xl shadow-sm overflow-hidden"},{empty:r(()=>[...e[2]||(e[2]=[l("div",{class:"text-center text-gray-400",style:{padding:"32px 0"}},[l("i",{class:"pi pi-shopping-bag text-3xl block",style:{"margin-bottom":"8px"}}),j(" Aucun article trouve. ")],-1)])]),default:r(()=>[s(o,{header:"",style:{width:"60px"}},{body:r(({data:a})=>[y(a.code_art)?(x(),_("img",{key:0,src:y(a.code_art),alt:"",style:{width:"40px",height:"40px","object-fit":"cover","border-radius":"4px"}},null,8,L)):(x(),_("div",q,[...e[3]||(e[3]=[l("i",{class:"pi pi-image text-gray-300"},null,-1)])]))]),_:1}),s(o,{field:"code_art",header:"Code",style:{width:"130px"}},{body:r(({data:a})=>[l("span",G,c(a.code_art),1)]),_:1}),s(o,{field:"libelle",header:"Article"}),s(o,{field:"reference",header:"Reference",style:{width:"130px"}}),s(o,{field:"famille",header:"Famille",style:{width:"150px"}}),s(o,{field:"Prix_vente_HT",header:"Prix HT",style:{width:"120px"}},{body:r(({data:a})=>[l("span",J,c(v(a.Prix_vente_HT))+" DH",1)]),_:1}),s(o,{field:"Prix_vente_TTC",header:"Prix TTC",style:{width:"130px"}},{body:r(({data:a})=>[l("span",K,c(v(a.Prix_vente_TTC))+" DH",1)]),_:1}),s(o,{header:"Stock",style:{width:"110px"}},{body:r(({data:a})=>[s(F,{value:$(a.stock_total),severity:C(a.stock_total)},null,8,["value","severity"])]),_:1}),s(o,{field:"unite",header:"Unite",style:{width:"90px"}})]),_:1},8,["value","loading"])])}}};export{se as default};
