import{f as P,w as V,g as J,o as u,c as m,b as c,a as n,z as X,d as g,i as y,av as U,q as H,r}from"./vendor-0kGcmQpG.js";import{u as O,s as o,a as W,S as Y,k as F}from"./index-Bn9WoKhP.js";const K={class:"flex flex-col"},Q={class:"w-full flex flex-wrap items-start md:flex-row justify-start gap-3"},Z={key:0},ee={class:"mt-4 bg-white p-4 border border-gray-300 shadow-md"},te={class:"mb-2 flex justify-end"},ae={key:0},ie={key:1},re={style:"height: calc(100vh - 240px)",class:"mt-2 ag-theme-quartz"},se={__name:"AvocatAcompteProvisionnel",setup(le){const{showError:h,showWarn:b,showInfo:w}=O(),C=r(),N=r(),f=r();let p=r(!1);const d=r([]),_=r(),a=r(!1),s=r([]),x=r(!1),A=r([{headerName:"",field:"selection",width:50,checkboxSelection:!0,headerCheckboxSelection:!0,hide:()=>!a.value,sortable:!1,resizable:!1,filter:!1},{headerName:"Année Dossier",field:"anneeNumDossier",width:130,editable:()=>a.value,sortable:!0,resizable:!0,filter:"agTextColumnFilter"},{headerName:"N°Dossier",field:"numDossier",width:120,editable:()=>a.value,sortable:!0,resizable:!0,filter:"agTextColumnFilter"},{headerName:"Code N° Dossier",field:"codeNumDossier",width:140,editable:()=>a.value,sortable:!0,resizable:!0,filter:"agTextColumnFilter"},{headerName:"Date Enregistrement",field:"dateEnregistrement",width:160,valueFormatter:t=>t.value?F(t.value):"",editable:()=>a.value,cellEditor:"agDateCellEditor",sortable:!0,resizable:!0,filter:"agDateColumnFilter"},{headerName:"Date Encaissement",field:"dateEncaissement",width:160,valueFormatter:t=>t.value?F(t.value):"",editable:()=>a.value,cellEditor:"agDateCellEditor",sortable:!0,resizable:!0,filter:"agDateColumnFilter"},{headerName:"Reference Paiement",field:"referencePaiement",width:160,editable:()=>a.value,sortable:!0,resizable:!0,filter:"agTextColumnFilter"},{headerName:"Réf. Nature Affaire Juridique",field:"refNatureAffaireJuridiqueCode",width:220,editable:()=>a.value,sortable:!0,resizable:!0,filter:"agTextColumnFilter"},{headerName:"Réf. Tribunal",field:"refTribunAlCode",width:120,editable:()=>a.value,sortable:!0,resizable:!0,filter:"agTextColumnFilter"},{headerName:"Actions",field:"actions",width:100,cellRenderer:t=>a.value?`
        <div class="flex justify-center">
          <button class="delete-btn p-2 text-red-600 hover:text-red-800"
                  data-id="${t.data.id}"
                  title="Supprimer">
            <i class="pi pi-trash"></i>
          </button>
        </div>
      `:"",cellStyle:{textAlign:"center"},hide:()=>!a.value,sortable:!1,resizable:!1,filter:!1,pinned:"right"}]),R=r({sortable:!0,resizable:!0,filter:"agTextColumnFilter",suppressHeaderMenuButton:!0}),T=r({mode:"multiRow",checkboxes:!0,headerCheckbox:!0,enableClickSelection:!0}),$=t=>{f.value=t.api,setTimeout(()=>{f.value&&f.value.sizeColumnsToFit()},100)},S=t=>{s.value=t.api.getSelectedRows()};P(async()=>{await v()});const v=async()=>{o.state.afficher_in_progress=!0;try{const t=await W.post(`${o.lienApi}/AcompteAvocats/${o.db}`,{annee_fiscale:o.state.annee_fiscale},{headers:{"Content-Type":"application/json"}});d.value=t.data.map((e,i)=>({...e,id:e.id||`temp_id_${i}`}))}catch(t){const e=t.response?.data?.message||t.message;h(`Une erreur est survenue : ${e}`)}finally{o.state.afficher_in_progress=!1}},z=()=>{a.value=!0,p.value=!0},M=async()=>{p.value=!1,a.value=!1,await v()},E=async()=>{try{o.state.afficher_in_progress=!0,a.value=!1,p.value=!1}catch(t){h("Une erreur est survenue lors de l'enregistrement: "+t.message)}finally{o.state.afficher_in_progress=!1}};V(_,async t=>{t&&await v()});const I=()=>{const e={id:`temp_id_${Date.now()}`,anneeNumDossier:o.state.annee_fiscale||new Date().getFullYear().toString(),numDossier:"",codeNumDossier:"",dateEnregistrement:new Date,dateEncaissement:new Date,referencePaiement:"",refNatureAffaireJuridiqueCode:"",refTribunAlCode:""};d.value.unshift(e),s.value=[e]},D=()=>{x.value=!x.value},k=()=>{window.print()},B=()=>{w({title:"Information",text:"Fonctionnalité d'importation à implémenter"})},G=()=>{if(s.value.length===0){b("Veuillez sélectionner au moins une ligne à supprimer");return}b({title:"Confirmation",text:`Voulez-vous vraiment supprimer ${s.value.length} ligne(s)?`,showCancelButton:!0,confirmButtonText:"Oui, supprimer",cancelButtonText:"Annuler",callback:()=>{const t=s.value.map(e=>e.id);d.value=d.value.filter(e=>!t.includes(e.id)),s.value=[]}})},q=()=>{w({title:"Information",text:"Fonctionnalité de génération XML à implémenter"})};return(t,e)=>{const i=X,j=U,L=J("ag-grid-vue");return u(),m("div",K,[c("div",Q,[a.value?g("",!0):(u(),m("div",Z,[n(i,{onClick:e[0]||(e[0]=l=>z()),text:"",icon:"pi pi-pencil",label:"Modifier"})])),a.value?(u(),y(i,{key:1,text:"",icon:"pi pi-save",label:"Enregistrer",onClick:e[1]||(e[1]=l=>E())})):g("",!0),c("div",null,[n(i,{text:"",icon:"pi pi-cog",label:"Actions",onClick:e[2]||(e[2]=l=>C.value.toggle(l))}),n(j,{ref_key:"actionsMenu",ref:C,model:[{label:"Importer",icon:"pi pi-upload",command:()=>B()},{label:"Supprimer",icon:"pi pi-trash",command:()=>G()},{label:"Générer XML...",icon:"pi pi-file-export",command:()=>q()}],popup:!0},null,8,["model"])]),a.value?(u(),y(i,{key:2,text:"",icon:"pi pi-times",label:"Annuler",onClick:e[3]||(e[3]=l=>M())})):g("",!0),n(i,{icon:"pi pi-times",label:"Fermer",text:"",onClick:e[4]||(e[4]=l=>H(Y)("AvocatAcompteProvisionnel"))})]),c("div",ee,[c("div",te,[a.value?(u(),m("span",ae,[n(i,{icon:"pi pi-plus",label:"Ajouter",severity:"success",class:"mr-2",onClick:e[5]||(e[5]=l=>I())}),n(i,{icon:"pi pi-search",label:"Rechercher",onClick:e[6]||(e[6]=l=>D()),class:"mr-2"}),n(i,{icon:"pi pi-print",label:"Imprimer",onClick:e[7]||(e[7]=l=>k())})])):(u(),m("span",ie,[n(i,{icon:"pi pi-search",label:"Rechercher",text:"",onClick:e[8]||(e[8]=l=>D()),class:"mr-2"}),n(i,{icon:"pi pi-print",label:"Imprimer",text:"",onClick:e[9]||(e[9]=l=>k())})]))]),c("div",re,[n(L,{ref_key:"agGrid",ref:N,localeText:t.$agGridLocale,rowData:d.value,columnDefs:A.value,defaultColDef:R.value,theme:t.$agGridTheme,rowSelection:T.value,suppressRowClickSelection:!1,pinnedBottomRowData:t.pinnedBottomRowData,getContextMenuItems:t.getContextMenuItems,onGridReady:$,onRowClicked:t.onRowClick,onSelectionChanged:S,onFilterChanged:t.onFilterChanged,onSortChanged:t.onFilterChanged,class:"ag-theme-quartz",style:{height:"100%",width:"100%"}},null,8,["localeText","rowData","columnDefs","defaultColDef","theme","rowSelection","pinnedBottomRowData","getContextMenuItems","onRowClicked","onFilterChanged","onSortChanged"])])])])}}};export{se as default};
