import{r as p,w as C,o as k,i as V,j as w,b as n,a as r,M as D,ay as _,aw as S,z as N,S as j}from"./vendor-BDR7yMJi.js";import{_ as L,s as O,k as A}from"./index-BSaHX2oa.js";const B={class:"flex flex-col gap-4 p-4"},I={class:"flex gap-4"},R={class:"flex items-center gap-2"},T={class:"flex items-center gap-2"},U={class:"flex flex-col gap-2"},E={class:"flex items-center gap-2"},F={class:"flex justify-end gap-2"},P={__name:"RapportDynamique",props:{dataList:{type:Array,required:!0},titre:{type:String,default:"Rapport"},show:{type:Boolean,default:!1},gridApi:{type:Object,default:null}},setup(y){const i=y,c=p(i.show),m=p(i.titre),d=p("landscape"),b=p(!0),g=p(!1);C(()=>i.show,l=>{c.value=l});const $=()=>{if(!i.dataList?.length){alert("Aucune donnée à imprimer");return}g.value=!0;const l=window.open("","_blank","width=1200,height=800"),e=z();l.document.write(e),l.document.close(),g.value=!1},z=()=>{let l=[],e=i.dataList;if(i.gridApi)try{l=i.gridApi.getAllDisplayedColumns().filter(a=>{const s=a.getColDef();return s.field&&s.field!=="ndoc"&&!s.checkboxSelection&&!a.getColId().includes("ag-Grid-AutoColumn")}).map(a=>({field:a.getColDef().field,headerName:a.getColDef().headerName||a.getColDef().field}));const t=[];i.gridApi.forEachNodeAfterFilterAndSort(a=>{a.data&&t.push(a.data)}),e=(t.length>0?t:i.dataList).map(a=>{const s={};return l.forEach(h=>{s[h.field]=a[h.field]}),s})}catch{l=Object.keys(i.dataList[0]||{}).filter(t=>t!=="ndoc").map(t=>({field:t,headerName:t}))}else l=Object.keys(i.dataList[0]||{}).filter(o=>o!=="ndoc").map(o=>({field:o,headerName:o}));const x=(o,t)=>o?t.toLowerCase().includes("date")?A(o):o:"",u=b.value?"border: 1px solid #000;":"",v=O.state.enreg_societe?.Nom||"Société",f=A(new Date().toISOString());return`
    <!DOCTYPE html>
    <html>
    <head>
      <title>${m.value}</title>
      <style>
        body {
          font-family: Arial, sans-serif;
          margin: 20px;
          font-size: 11px;
        }

        h1 {
          text-align: center;
          margin-bottom: 30px;
          font-size: 16px;
        }

        table {
          width: 100%;
          border-collapse: collapse;
          font-size: 10px;
        }

        th, td {
          padding: 6px;
          text-align: left;
          ${u}
          font-size: 10px;
        }

        th {
          background-color: #f0f0f0;
          font-weight: bold;
          font-size: 10px;
        }

        .print-btn {
          background: #4CAF50;
          color: white;
          padding: 8px 16px;
          border: none;
          cursor: pointer;
          margin: 15px 8px;
          font-size: 14px;
        }

        @media print {
          .no-print { display: none !important; }
          body {
            margin: 0;
            font-size: 9px;
          }
          h1 { font-size: 14px; margin-top: 10px; }
          table { font-size: 8px; }
          th, td {
            padding: 3px;
            font-size: 8px;
          }

          @page {
            size: ${d.value};
            margin: 20mm 10mm 20mm 10mm;

            @top-left {
              content: "${v}";
              font-size: 9px;
              font-weight: bold;
              color: #333;
              font-family: Arial, sans-serif;
            }
            @top-right {
              content: "${f}";
              font-size: 9px;
              color: #666;
              font-family: Arial, sans-serif;
            }
            @bottom-left {
              content: "OMAG - omag.ma";
              font-size: 9px;
              color: #666;
              font-family: Arial, sans-serif;
            }
            @bottom-right {
              content: "Page " counter(page) " / " counter(pages);
              font-size: 9px;
              color: #666;
              font-family: Arial, sans-serif;
            }
          }
        }
      </style>
    </head>
    <body>
      <div class="no-print" style="text-align:center;">
        <button class="print-btn" onclick="window.print()">Imprimer</button>
        <button class="print-btn" onclick="window.close()" style="background:#f44336;">Fermer</button>
      </div>

      <h1>${m.value}</h1>

      <table>
        <thead>
          <tr>
            ${l.map(o=>`<th>${o.headerName}</th>`).join("")}
          </tr>
        </thead>
        <tbody>
          ${e.map(o=>`
            <tr>
              ${l.map(t=>`<td>${x(o[t.field],t.field)}</td>`).join("")}
            </tr>
          `).join("")}
        </tbody>
      </table>
    </body>
    </html>
  `};return(l,e)=>{const x=D,u=_,v=S,f=N,o=j;return k(),V(o,{visible:c.value,"onUpdate:visible":e[5]||(e[5]=t=>c.value=t),header:"Impression : "+y.titre,modal:"",style:{width:"400px"},onHide:e[6]||(e[6]=t=>l.$emit("close"))},{footer:w(()=>[n("div",F,[r(f,{label:"Annuler",icon:"pi pi-times",severity:"secondary",outlined:"",onClick:e[4]||(e[4]=t=>l.$emit("close"))}),r(f,{label:"Aperçu et Impression",icon:"pi pi-eye",onClick:$,loading:g.value},null,8,["loading"])])]),default:w(()=>[n("div",B,[n("div",null,[e[7]||(e[7]=n("label",{for:"titre-rapport",class:"block text-sm font-medium mb-2"}," Titre du rapport ",-1)),r(x,{size:"small",id:"titre-rapport",modelValue:m.value,"onUpdate:modelValue":e[0]||(e[0]=t=>m.value=t),class:"w-full",placeholder:"Saisir le titre du rapport"},null,8,["modelValue"])]),n("div",null,[e[10]||(e[10]=n("label",{class:"block text-sm font-medium mb-2"},"Orientation",-1)),n("div",I,[n("div",R,[r(u,{id:"portrait",modelValue:d.value,"onUpdate:modelValue":e[1]||(e[1]=t=>d.value=t),name:"orientation",value:"portrait"},null,8,["modelValue"]),e[8]||(e[8]=n("label",{for:"portrait"},"Portrait",-1))]),n("div",T,[r(u,{id:"paysage",modelValue:d.value,"onUpdate:modelValue":e[2]||(e[2]=t=>d.value=t),name:"orientation",value:"landscape"},null,8,["modelValue"]),e[9]||(e[9]=n("label",{for:"paysage"},"Paysage",-1))])])]),n("div",null,[e[12]||(e[12]=n("label",{class:"block text-sm font-medium mb-2"},"Options",-1)),n("div",U,[n("div",E,[r(v,{id:"bordures",modelValue:b.value,"onUpdate:modelValue":e[3]||(e[3]=t=>b.value=t),binary:""},null,8,["modelValue"]),e[11]||(e[11]=n("label",{for:"bordures"},"Afficher les bordures",-1))])])])])]),_:1},8,["visible","header"])}}},H=L(P,[["__scopeId","data-v-2360a65d"]]);export{H as _};
