import{aj as h,r,y as n,z as a,W as b}from"./index-Bb2UEb_P.js";const S=h("documents",()=>{const i=r([]),u=r([]),d=r([]);async function m(){try{const t=await n.post(a.motionDocuments);t?.data&&(i.value=Object.values(t.data))}catch(t){console.error("Ошибка при загрузке документов:",t)}}async function p(){try{const t=await n.post(a.contractsEnclosures);t?.data&&(u.value=Object.values(t.data))}catch(t){console.error("Ошибка при загрузке документов договора:",t)}}async function w(t){const o=Object.fromEntries(Object.entries(t).filter(([L,f])=>f!=null)),e=new URLSearchParams(o).toString(),s=b+a.invoiceDocumentGuest+(e?`?${e}`:""),c=await n.post(s);d.value=c.data}async function D(t){try{const o=await n.post(a.motionDocumentDownload,{...t});if(o?.data?.Status==="Ok"){const e=await n.get(o?.data?.Location);e?.data?.Status==="Ok"&&l({url:e?.data?.Location,fileName:"contract"})}}catch(o){console.error("Ошибка при загрузке документа:",o)}}async function y(t){try{const o=await n.post(a.contractEnclosureDownload,{...t});o?.data?.Status==="Ok"&&l({url:o?.data?.Location,fileName:"document"})}catch(o){console.error("Ошибка при загрузке документа:",o)}}async function l({url:t,fileName:o}){const e=await n.get(t,{responseType:"blob"}),s=new Blob([e.data],{type:"application/pdf"}),c=document.createElement("a");c.href=URL.createObjectURL(s),c.download=o.endsWith(".pdf")?o:`${o}.pdf`,c.click(),URL.revokeObjectURL(c.href)}return{motionDocumentsList:i,contractDocumentsList:u,motionDocumentDownload:D,contractEnclosureDownload:y,fetchMotionDocuments:m,fetchContractDocuments:p,fetchInvoiceDocumentGuest:w,invoiceDocumentGuest:d}});export{S as u};
