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