import{b as _,s as f}from"./index-BxIwIJfy.js";import{n as I,y as V}from"./vue-core-Di3IuVqe.js";function T(c,x){const{modeModificationRef:y,gridApiRef:a,rowsRef:s,applyArticle:w,canEditRow:p,fieldName:u="code_art",focusColAfter:C,editorParams:E={},getCodeClient:h,getCodeFrs:g}=x,v=V(()=>{const e=new Map;for(const t of c.value||[])e.set(t.value,t.text||t.value);return e}),d=e=>!y.value||!e?!1:p?p(e):!0;return{articleFormatMap:v,columnPartialDef:{editable:e=>d(e.data),cellEditor:"agRichSelectCellEditor",cellEditorPopup:!0,cellEditorPopupPosition:"under",cellEditorParams:()=>({values:c.value?.map(e=>e.value)||[],allowTyping:!0,filterList:!0,searchType:"matchAny",highlightMatch:!0,cellHeight:38,valueListMaxHeight:320,valueListMaxWidth:480,formatValue:e=>v.value.get(e)||e||"",...E}),valueSetter:e=>{const t=e.newValue||"";return t===e.oldValue?!1:(e.data[u]=t,!0)},cellRenderer:e=>{const t=e.value||"",i=d(e.data);return`<div class="code-cell"><span class="code-cell-text" style="text-align:left">${t||(i?'<span style="color:#9ca3af;font-style:italic;">Cliquez...</span>':"")}</span>${i?'<i class="pi pi-chevron-down code-cell-chevron"></i>':""}</div>`},cellStyle:e=>{const t={padding:"4px 8px",display:"flex",alignItems:"center",justifyContent:"flex-start"};return d(e.data)?{...t,cursor:"pointer"}:t}},prewarmRichSelect:()=>{const e=()=>{const n=a.value;if(!n||!s?.value?.length||!c.value?.length)return!1;try{return n.startEditingCell({rowIndex:0,colKey:u}),n.stopEditing(!0),!0}catch{return!1}};let t=0;const i=setInterval(()=>{(e()||++t>20)&&clearInterval(i)},250)},handleArticleSelected:async e=>{if(!((e?.colDef?.field||e?.column?.getColId?.())===u&&e?.newValue&&e.newValue!==e.oldValue))return!1;const n=e.data?.nligne;let r=s.value.findIndex(l=>l.nligne===n);if(r<0&&typeof e.node?.rowIndex=="number"&&(r=e.node.rowIndex),r<0||r>=s.value.length)return!1;let o=null;try{const l={codes_articles:[e.newValue]};h&&(l.code_client=h()??null),g&&(l.code_frs=g()??null),o=(await _.post(`${f.lienApi}/SelectarticlesDetails/${f.db}`,l)).data?.[0]||null}catch{}if(!o){const l=c.value?.find(m=>m.value===e.newValue);l&&(o={code_art:l.value,libelle:l.text,tva:20,unite:"U",Prix_vente_HT:0,Prix_vente_TTC:0,QuantiteCarton:0})}if(!o)return!0;try{await w(o,r,e.data)}catch{}if(await I(),a.value){a.value.refreshCells({force:!0});const l=C||(f.state.enreg_option_comm?.saisie_en_pack?"Carton":"qte");a.value.ensureIndexVisible(r),a.value.setFocusedCell(r,l),setTimeout(()=>{a.value?.startEditingCell({rowIndex:r,colKey:l})},50)}return!0}}}export{T as u};
