const d=t=>{const r=Math.floor(t/3600),e=Math.floor(t%3600/60),a=Math.floor(t%60);return`${r.toString().padStart(2,"0")}:${e.toString().padStart(2,"0")}:${a.toString().padStart(2,"0")}`},h=t=>{if(t===0)return"0 Bytes";const r=1024,e=["Bytes","KB","MB","GB"],a=Math.floor(Math.log(t)/Math.log(r));return`${parseFloat((t/Math.pow(r,a)).toFixed(2))} ${e[a]}`},m=t=>new Promise(r=>{const e=document.createElement("canvas");e.width=t.videoWidth,e.height=t.videoHeight,t.currentTime=1,t.onseeked=()=>{const a=e.getContext("2d");a==null||a.drawImage(t,0,0,e.width,e.height),r(e.toDataURL("image/jpeg"))}}),g=t=>new Promise((r,e)=>{try{const a=t.type.split("/")[0],i=h(t.size);if(a==="video"){const o=document.createElement("video"),n=URL.createObjectURL(t);o.preload="metadata",o.onloadedmetadata=()=>{URL.revokeObjectURL(n);const s=d(o.duration);m(o).then(c=>{r({duration:s,dimensions:{width:o.videoWidth,height:o.videoHeight},size:i,thumbnail:c,name:t.name,type:t.type})})},o.onerror=()=>{URL.revokeObjectURL(n),e(new Error("Error loading video metadata"))},o.src=n}else if(a==="image"){const o=new Image,n=URL.createObjectURL(t);o.onload=()=>{URL.revokeObjectURL(n),r({dimensions:{width:o.width,height:o.height},size:i,thumbnail:n,name:t.name,type:t.type})},o.onerror=()=>{URL.revokeObjectURL(n),e(new Error("Error loading image metadata"))},o.src=n}else r({size:i,name:t.name,type:t.type})}catch(a){e(a)}});export{g};
