ruạṛ
import{bD as j,u as v,z as P,p as d,fj as B,j as p,c as t,bv as E,fk as L,c2 as z,ay as A,b7 as R,J as U,bc as m,r as M,e as O,T as W,W as q,cf as J,C as K}from"./bundle.9abe88c8.js";const X=j.div` border-color: ${a=>a.theme.borderColor}; &:hover { border-color: ${a=>a.theme.hoverBorderColor}; } `;function G(a){const[c]=v(),{entity:f}=a,n=P(),[l,h]=d.useState([]),[y,b]=d.useState(),[i,u]=d.useState(new FormData),[F,w]=d.useState(!1),C=()=>{if(!F){if(!l.length){m.error("select_file");return}return m.processing(),w(!0),b(void 0),M("POST",O("/api/v1/edocument/upload"),i).then(e=>{var s;m.success(((s=e==null?void 0:e.data)==null?void 0:s.message)??"success")}).catch(e=>{var s;((s=e.response)==null?void 0:s.status)===422&&(m.dismiss(),b(e.response.data))}).finally(()=>{h([]),w(!1),u(new FormData)})}},_=()=>{l.forEach(e=>{i.append("documents[]",e)}),u(i)},N=e=>{const s=l.filter((o,g)=>e!==g),r=new FormData;r.append("import_type",f),r.append("_method","PUT"),h(s),u(r)},T=e=>new Promise(s=>{try{const r=new FileReader;r.onload=o=>{var D;const x=(((D=o.target)==null?void 0:D.result)||"").split(` `);!x.length||x.length===1||x.length===2&&!x[1]?s(!1):s(!0)},r.readAsText(e)}catch{s(!1)}}),I=async e=>{for(let s=0;s<e.length;s++)if(!await T(e[s]))return!1;return!0},{getRootProps:S,getInputProps:$,isDragActive:k}=B({accept:{"application/xml":[".xml"]},onDrop:async e=>{if(await I(e))if(e.every(({type:o})=>o.includes(o))){let o=[];e.map(g=>{o=[...o,g]}),h(o),i.append("import_type",f),i.append("_method","PUT"),u(i)}else m.error("wrong_file_extension");else m.error("xml_lines_length")}});return d.useEffect(()=>{_()},[l]),d.useEffect(()=>()=>{h([]),u(new FormData)},[]),p("div",{className:"flex flex-col space-y-4",children:[t(E,{leftSide:c("xml_file"),children:l.length?t("ul",{className:"grid xs:grid-rows-6 lg:grid-cols-2 gap-3",children:l.map((e,s)=>p("li",{className:"flex items-center justify-between cursor-pointer p-2",style:{backgroundColor:n.$4},children:[e.name," - ",(e.size/1024).toPrecision(2)," KB"," ",t(A,{element:R,size:19,className:"cursor-pointer",onClick:()=>N(s)})]},s))}):p("div",{...S(),className:"flex flex-col md:flex-row md:items-center",children:[p(X,{className:"relative block w-full border-2 border-dashed rounded-lg p-12 text-center focus:outline-none focus:ring-2 focus:ring-offset-2",theme:{borderColor:n.$5,hoverBorderColor:n.$3},children:[t("input",{...$()}),t(L,{className:"mx-auto h-12 w-12",style:{color:n.$3,colorScheme:n.$0}}),t("span",{className:"mt-2 block text-sm font-medium",style:{color:n.$3,colorScheme:n.$0},children:c(k?"drop_file_here":"dropzone_default_message")})]}),y&&Object.keys(y.errors).map((e,s)=>t(z,{type:"danger",children:y.errors[e]},s))]})}),t("div",{className:"flex justify-end pr-5",children:t(U,{behavior:"button",onClick:C,disableWithoutIcon:!0,disabled:!l.length||F,children:c("import")})})]})}function Q(){const{t:a}=v(),{documentTitle:c}=W("import"),f=[{name:a("expenses"),href:"/expenses"},{name:a("import"),href:"/expenses/import"}];return t(q,{title:c,breadcrumbs:f,children:t("div",{className:"grid grid-cols-12",children:p("div",{className:"col-span-12 xl:col-span-10 space-y-4",children:[t(J,{entity:"expense",onSuccess:!1,type:"csv"}),t(K,{children:t(G,{entity:"expense",type:"xml"})})]})})})}export{Q as default};
cải xoăn