import{i as e}from"./nc-main-C6OeyNBF.js";import{t}from"./nc-sql.CJRr0HnB.js";import{createBlock as n,createCommentVNode as r,createElementBlock as i,createElementVNode as a,inject as o,openBlock as s,ref as c,renderSlot as l,resolveComponent as u}from"/vue.js";var d=[`type`,`multiple`],f=Object.assign({name:`NcDroparea`},{__name:`nc-droparea`,props:{icon:{type:String,default:``,required:!1},clickable:{type:Boolean,default:!0,required:!1},multiple:{type:Boolean,default:!1,required:!1}},emits:[`import-file`],setup(f,{emit:p}){let m=f,h=p,g=o(`state`),_=g.rec,v=c();function y(t){if(t[0]){if(t[0].size===0)e.setWarning(g,`Import from file '${t[0].name}' was not successful, file size is zero`);else if(t[0].name){let e=new FileReader;e.onloadend=function(e){h(`import-file`,t[0],e.target.result)},e.readAsDataURL(t[0])}return!0}return!1}function b(e){_.progress_bar&&(_.progress_bar.percent=0,_.progress_bar.message=``),e.target.value=``,e.target.files=[]}function x(n){let r=n.dataTransfer.files||n.target.files;if(!r){b(n),e.setWarning(g,`Importing from file failed`);return}let i=`Importing from file '${r[0].name}'...`;_.progress_bar?(_.progress_bar.percent=40,_.progress_bar.message=i):e.setInfo(g,i),setTimeout(async()=>{if(v.value.classList.remove(`nc-droparea-hover`),typeof r!=`object`||r[0]==null||r[0].name==null){b(n),e.setWarning(g,`Import from file '${r[0]}' was not successful`);return}(!n.target.files||n.target.files.length===0)&&(n.target.files=r),t().then(t=>{t.promise(`SELECT * FROM FILE(?, {headers: true})`,[n]).then(t=>{if(t.length==null){if(y(r))return;e.setWarning(g,`Import from file '${r[0].name}' did not succeed`)}else t.length>0?(e.setInfo(g,`Import from file '${r[0].name}' was successful, imported ${t.length} rows`),h(`import-file`,r[0],t)):e.setWarning(g,`Import from file '${r[0].name}' was not successful, imported 0 rows`)}).catch(t=>{y(r)||e.setWarning(g,`Selected file is not a valid import file, error: ${t?t.message.substring(0,300):`unknown error`}.`)}).finally(()=>{b(n)})})},100)}function S(e){m.clickable&&x(e)}function C(e){e.stopPropagation(),e.preventDefault(),x(e)}function w(e){e.stopPropagation(),e.preventDefault(),e.dataTransfer.dropEffect=`copy`,v.value.classList.add(`nc-droparea-hover`)}function T(e){e.stopPropagation(),e.preventDefault(),e.dataTransfer.dropEffect=`none`,v.value.classList.remove(`nc-droparea-hover`)}return(e,t)=>{let o=u(`nc-icon`);return s(),i(`label`,{class:`nc-droparea`,ref_key:`dropArea`,ref:v,onDragover:w,onDragleave:T,onDrop:C},[a(`input`,{id:`import-file`,type:f.clickable?`file`:`hidden`,multiple:f.multiple?``:void 0,onClick:S,onChange:x},null,40,d),f.icon?(s(),n(o,{key:0,class:`nc-droparea-icon fa-2x`,icon:f.icon},null,8,[`icon`])):r(``,!0),l(e.$slots,`default`)],544)}}});export{f as default};