import{ac as w}from"./primevue-CfIk0_DY.js";import{r as p,s as E}from"./index-BxIwIJfy.js";import{w as M,o as N,b as f,c as b,t as k,p as A,v as D,a as o,y as n}from"./vue-core-Di3IuVqe.js";const F={class:"relative"},_={key:0,class:"block text-sm font-medium text-gray-700 mb-1"},T={__name:"MultiComboDynamique",props:{modelValue:{type:Array,default:()=>[]},table:{type:String,required:!0},filters:{type:Object,default:null},annee:{type:[String,Number],default:null},texteLabel:{type:String,default:""},disabled:{type:Boolean,default:!1},placeholder:{type:String,default:""},maxLabels:{type:Number,default:2}},emits:["change","update:modelValue"],setup(t,{emit:v}){const c=v,e=t,s=o([]),r=o(!1),u=o({text:"Libelle",value:"Numéro"}),l=o([]),h=["unite","tva","depot","MoisEnLettres","Mois","situationFamiliale","MoisExercice","devise","modep","Terminal"],i=n(()=>!h.includes(e.table)),m=n(()=>{if(e.annee!==null&&e.annee!==void 0&&e.annee!==""){const a=parseInt(e.annee,10);if(Number.isFinite(a))return a}return["tva","MoisExercice","PeriodeDeclarationTVA"].includes(e.table)&&parseInt(E.state.annee_fiscale,10)||null}),y=n(()=>e.placeholder?e.placeholder:e.texteLabel?`Choisir ${e.texteLabel.toLowerCase()}`:"Choisir"),x=n(()=>i.value?u.value.text:"text"),g=n(()=>i.value?u.value.value:"value"),L=async()=>{try{if(r.value=!0,i.value){const a=await p(e.table,{searchQuery:"",filters:e.filters,annee:m.value,maxResults:9999,returnFormat:"autocomplete"});s.value=a.dataSource||[],u.value=a.fields}else{const a=await p(e.table,{searchQuery:"",filters:e.filters,annee:m.value,maxResults:9999,returnFormat:"list"});Array.isArray(a)&&(s.value=a)}}catch{s.value=[]}finally{r.value=!1}},C=()=>{c("update:modelValue",l.value),c("change",l.value)};return M(()=>e.modelValue,a=>{l.value=a||[]},{immediate:!0}),N(async()=>{await L()}),(a,d)=>{const V=w;return f(),b("div",F,[t.texteLabel?(f(),b("label",_,k(t.texteLabel),1)):A("",!0),D(V,{size:"small",modelValue:l.value,"onUpdate:modelValue":d[0]||(d[0]=S=>l.value=S),options:s.value,optionLabel:x.value,optionValue:g.value,placeholder:y.value,filter:!0,showClear:!0,loading:r.value,disabled:t.disabled,maxSelectedLabels:t.maxLabels,selectedItemsLabel:"{0} sélectionnés",display:"chip",class:"w-full",onChange:C},null,8,["modelValue","options","optionLabel","optionValue","placeholder","loading","disabled","maxSelectedLabels"])])}}};export{T as _};
