import{r as F,f as I,a5 as o,o as B,i as O,j as k,b as A,c as T,a as C,s as $,d as J,E as R,S as P}from"./vendor-0kGcmQpG.js";import{_,u as j,a as U,s as m}from"./index-Bn9WoKhP.js";const H={key:0,class:"loading-overlay"},M={__name:"ReportViewer",props:{show:Boolean,ttc_ht:String,avecEntete:{type:Boolean,default:!0},urlFichier:String,isEnvoiMail:{type:Boolean,default:!1},data:[Array,Object],nomFichier:String},emits:["close","saveFichierPDF"],setup(s,{emit:N}){const{showError:w}=j(),v=N,b=F(s.show),p=F(!0),L=async()=>{try{const e=new o.Stimulsoft.Report.StiReport;e.loadFile(s.urlFichier),s.nomFichier&&(e.reportName=s.nomFichier,e.reportAlias=s.nomFichier);const t=s.data,i={...m.state.enreg_societe};i.avecEntete=s.avecEntete,i.ttc_ht=s.ttc_ht;const f=m.state.enreg_option_comm?.affichage_prix_doc||"BOTH";i.suffixePrix=f==="HT"?"HT":"TTC",i.lienApi=m.lienApi,i.cloudId=m.cloudId,i.id_societe=m.id_societe;const a=(r,D)=>{if(!r)return;const S=Array.isArray(D)?D[0]:D;if(!S)return;const E=new Set;for(let c=0;c<r.columns.count;c++){const u=r.columns.getByIndex(c);E.add(u.nameInSource||u.name)}for(const c in S)if(Object.hasOwn(S,c)){const u=S[c];if(Array.isArray(u)||E.has(c))continue;let h="System.String";typeof u=="number"?h=Number.isInteger(u)?"System.Int32":"System.Decimal":typeof u=="boolean"?h="System.Boolean":u instanceof Date&&(h="System.DateTime");const V=new o.Stimulsoft.Report.Dictionary.StiDataColumn(c,c,c,h);r.columns.add(V)}},g=t&&!Array.isArray(t)&&typeof t=="object"&&(t.Entete||t.Lignes);let l,n;g?(l=t.Entete||[],n=t.Lignes||[]):(l=Array.isArray(t)?t:[],n=null),a(e.dictionary.dataSources.getByName("Entete"),l),a(e.dictionary.dataSources.getByName("Autres"),[i]),n&&a(e.dictionary.dataSources.getByName("Lignes"),n);let d=new o.Stimulsoft.System.Data.DataSet("Entete");d.readJson(JSON.stringify({root:l}));let y=new o.Stimulsoft.System.Data.DataSet("Autres");if(y.readJson(JSON.stringify({root:[i]})),e.dictionary.databases.clear(),e.regData("Entete","Entete",d),e.regData("Autres","Autres",y),n){let r=new o.Stimulsoft.System.Data.DataSet("Lignes");r.readJson(JSON.stringify({root:n})),e.regData("Lignes","Lignes",r)}if(g){for(const r of Object.keys(t))r!=="Entete"&&r!=="Lignes"&&(i[r]=t[r]);a(e.dictionary.dataSources.getByName("Autres"),[i]),y=new o.Stimulsoft.System.Data.DataSet("Autres"),y.readJson(JSON.stringify({root:[i]})),e.regData("Autres","Autres",y)}const x=e.dictionary.variables.getByName("Len");if(x){const r=n?n.length:l.length;r>0&&(x.valueObject=r)}return e}catch(e){throw w(`Une erreur est survenue lors du chargement du rapport : ${e}`),e}};return I(async()=>{const e=new o.Stimulsoft.Viewer.StiViewerOptions;e.appearance.interfaceType=o.Stimulsoft.Viewer.StiInterfaceType.Mouse,e.toolbar.zoom=130,e.toolbar.printDestination=o.Stimulsoft.Viewer.StiPrintDestination.Direct;const t=new o.Stimulsoft.Viewer.StiViewer(e,"StiViewer",!1);try{const i=await L();s.isEnvoiMail?i.renderAsync(()=>{i.exportDocumentAsync(async f=>{const a=s.nomFichier||s.urlFichier.split("/").pop().split(".")[0],g=new Blob([new Uint8Array(f)],{type:"application/pdf"}),l=new File([g],a+new Date().getTime()+".pdf",{type:"application/pdf"}),n=new FormData;n.append("file",l);try{(await U.post(`${m.lienApi}/upload_un_fichier_sans_suppression`,n,{headers:{"x-custom-filename":a+".pdf","x-path":`temp/${m.cloudId}/${m.id_societe}/envoiemailrapports`}})).status===200&&v("saveFichierPDF",l)}catch(d){w(`Une erreur est survenue : ${d}`)}},o.Stimulsoft.Report.StiExportFormat.Pdf)}):i.renderAsync(()=>{t.report=i,t.renderHtml("viewer"),p.value=!1})}catch(i){w(`Une erreur est survenue : ${i}`),p.value=!1}}),(e,t)=>{const i=$,f=P;return B(),O(f,{visible:b.value,"onUpdate:visible":[t[1]||(t[1]=a=>b.value=a),t[2]||(t[2]=a=>v("close"))],modal:"",maximizable:"",header:" ",style:{width:"80vw",height:"100vh"}},{default:k(()=>[A("button",{onClick:t[0]||(t[0]=a=>v("close")),class:"close-btn",title:"Fermer"},"✕"),p.value?(B(),T("div",H,[C(i,{style:{width:"50px",height:"50px"},strokeWidth:"4"}),t[3]||(t[3]=A("p",{class:"loading-text"},"Chargement du rapport...",-1))])):J("",!0),A("div",{id:"viewer",class:R(["flex-1",{hidden:p.value}])},null,2)]),_:1},8,["visible"])}}},q=_(M,[["__scopeId","data-v-fc604c67"]]);export{q as R};
