import{u as s,j as e}from"./fields-wnm5Jtc6.js";import{a as i,R as C}from"./vendor-D21mNUGX.js";import{L as E,n as x}from"./Layout-CFk9FOHT.js";import{u as A,m as v,c as I,I as h,aG as S,A as U,s as j,aH as D}from"./index-pmrLY__j.js";import{f as L,g as T}from"./files-BLOunQ8H.js";import{d as k}from"./json-DqPAWNCa.js";import"./browser-KE9NsxEH.js";const P=()=>{const b=A(),[r,l]=i.useState(null),[y,c]=i.useState(!1),[d,t]=i.useState(null);i.useEffect(()=>{v(s("Import data")),I("#/tools")},[]);const g=async m=>{l(null),t(null),c(!0);const n=m.target.files[0],F=T(n.name),N=n.type;let o=await n.text();F==="acpt"&&o.charAt(0)!=="{"&&(o=k(o));const u=new File([o],n.name,{type:N});let f=new FormData;f.append("file",u),b(D(f)).then(a=>{c(!1),l(u);const p=a.payload;p.success===!0?(x.success("File was successfully imported"),t(null)):(x.error(p.error),t(p.error))}).catch(a=>{console.error(a),x(a),c(!1),l(null),t(a)})},w=e.jsx("label",{htmlFor:"upload",className:"acpt-btn acpt-btn acpt-btn-primary",onClick:()=>{l(null),t(null)},children:s(y?"Loading...":"Upload file")});return e.jsx(E,{title:s("Import data"),crumbs:[{label:s("ACPT Tools"),link:"/tools"},{label:s("Import data")}],children:e.jsxs("div",{className:"bg-white b-rounded with-shadow p-24",children:[e.jsxs("div",{className:"b-rounded b-maxi p-24 text-center flex-column s-12",style:{minHeight:"200px",justifyContent:"center"},children:[e.jsx("div",{className:"text-center",children:e.jsx(h,{icon:"bx:import",width:64,color:S()})}),e.jsx("h3",{children:s("Upload your file")}),e.jsx("span",{className:"label",children:s("[Allowed extension: *.acpt, *.json, *.yaml, *.xml max size: 2Mb]")}),r&&e.jsx("div",{style:{maxWidth:"800px",margin:"auto"},children:e.jsx(U,{style:d?j.DANGER:j.SUCCESS,children:e.jsxs("div",{className:"flex-between s-24",children:[e.jsxs("span",{className:"i-flex-center s-8",children:[e.jsx(h,{width:"18px",icon:d?"bx:bx-x":"bx:bx-check",color:d?"#f94144":"#2271b1"}),e.jsx("span",{className:"name",children:r.name})]}),e.jsxs("span",{className:"size",children:["(",L(r.size),")"]})]})})}),e.jsx("div",{children:w})]}),e.jsx(C.Fragment,{children:e.jsx("input",{onChange:m=>g(m),style:{display:"none"},name:"file",type:"file",id:"upload"})})]})})};export{P as default};
