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