import{f as h}from"./primevue-CfIk0_DY.js";import{_ as b,u as E,s as B}from"./index-BxIwIJfy.js";import{a as w}from"./ReportViewer-BNzhW7G2.js";import{s as a}from"./stimulsoft-B2-Y-rC1.js";import{a as N,o as L,a0 as V,b as x,k as M,l as R,d as D}from"./vue-core-Di3IuVqe.js";const j={__name:"ReportViewerMultiple",props:{show:Boolean,reports:Array},emits:["close"],setup(c,{emit:v}){const{showError:u}=E(),p=v,d=N(c.show);let m=null;const y={Nom:B.state.enreg_societe?.Nom||"",avecEntete:!0},f=(s,e)=>{if(!s||!e||e.length===0)return;const r=Array.isArray(e)?e[0]:e;if(r){for(const t in r)if(!s.columns.getByName(t)){const i=r[t];let o="System.String";typeof i=="number"?o=Number.isInteger(i)?"System.Int32":"System.Decimal":typeof i=="boolean"?o="System.Boolean":i instanceof Date&&(o="System.DateTime");const n=new a.Stimulsoft.Report.Dictionary.StiDataColumn(t,t,t,o);s.columns.add(n)}}},A=async s=>{const e=new a.Stimulsoft.Report.StiReport;let r="";try{const l=await fetch(s.url,{cache:"no-store"});if(!l.ok)throw new Error(`Telechargement du modele : ${l.status}`);r=await l.text(),e.load(r)}catch{e.loadFile(s.url)}const t=s.data,i=t&&!Array.isArray(t)&&typeof t=="object"&&(t.Entete||t.Lignes);let o,n;i?(o=t.Entete||[],n=t.Lignes||[]):(o=Array.isArray(t)?t:[],n=null),o=w(r,"Entete",o),n&&(n=w(r,"Lignes",n)),f(e.dictionary.dataSources.getByName("Entete"),o),f(e.dictionary.dataSources.getByName("Autres"),[y]),n&&f(e.dictionary.dataSources.getByName("Lignes"),n);let g=new a.Stimulsoft.System.Data.DataSet("Entete");g.readJson(JSON.stringify({root:Array.isArray(o)?o:[o]}));let S=new a.Stimulsoft.System.Data.DataSet("Autres");if(S.readJson(JSON.stringify({root:[y]})),e.dictionary.databases.clear(),e.regData("Entete","Entete",g),e.regData("Autres","Autres",S),n){let l=new a.Stimulsoft.System.Data.DataSet("Lignes");l.readJson(JSON.stringify({root:n})),e.regData("Lignes","Lignes",l)}return e};return L(async()=>{const s=new a.Stimulsoft.Viewer.StiViewerOptions;s.appearance.interfaceType=a.Stimulsoft.Viewer.StiInterfaceType.Mouse,s.toolbar.printDestination=a.Stimulsoft.Viewer.StiPrintDestination.Pdf;const e=new a.Stimulsoft.Viewer.StiViewer(s,"StiViewerMultiple",!1);m=e;try{if(!c.reports||c.reports.length===0){u("Aucun rapport à afficher");return}const r=new a.Stimulsoft.Report.StiReport,t=[];for(const i of c.reports)try{const o=await A(i);t.push(o)}catch{}if(t.length===0){u("Aucun rapport n'a pu être généré");return}r.reportUnit=t[0].reportUnit,await new Promise(i=>{r.renderAsync(function(){r.renderedPages.clear(),i()})});for(const i of t)await new Promise(o=>{i.renderAsync(function(){for(let n=0;n<i.renderedPages.count;n++)r.renderedPages.add(i.renderedPages.getByIndex(n));o()})});e.report=r,e.renderHtml("viewerMultiple")}catch(r){u(`Une erreur est survenue : ${r}`)}}),V(()=>{const s=m;if(m=null,!!s?.jsObject)try{s.dispose()}catch{try{s.jsObject?.stopAllTimers?.()}catch{}try{s.jsObject?.removeAllEvents?.()}catch{}}}),(s,e)=>{const r=h;return x(),M(r,{visible:d.value,"onUpdate:visible":[e[1]||(e[1]=t=>d.value=t),e[2]||(e[2]=t=>p("close"))],modal:"",maximizable:"",header:" ",style:{width:"80vw",height:"100vh"}},{default:R(()=>[D("button",{onClick:e[0]||(e[0]=t=>p("close")),class:"close-btn",title:"Fermer"},"✕"),e[3]||(e[3]=D("div",{id:"viewerMultiple",class:"flex-1"},null,-1))]),_:1},8,["visible"])}}},J=b(j,[["__scopeId","data-v-8d5ed5c1"]]);export{J as R};
