"use strict";var e=require("vue"),i=(e=>(e[e["1MB"]=1e6]="1MB",e[e["2MB"]=2e6]="2MB",e[e["3MB"]=3e6]="3MB",e[e["4MB"]=4e6]="4MB",e[e["5MB"]=5e6]="5MB",e))(i||{}),t=(e=>(e.JPG=".jpg",e.JPEG=".jpeg",e.PNG=".png",e.WEBP=".webp",e.HEIC=".heic",e.HEIF=".heif",e))(t||{});const r=e=>`File size is more than ${e}`,s={[i["1MB"]]:r("1mb"),[i["2MB"]]:r("2mb"),[i["3MB"]]:r("3mb"),[i["4MB"]]:r("4mb"),[i["5MB"]]:r("5mb")},a=/(\.jpg)|(\.png)|(\.jpeg)|(\.png)|(\.heic)|(\.heif)/;var l=Object.defineProperty,n=(e,i,t)=>(((e,i,t)=>{i in e?l(e,i,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[i]=t})(e,"symbol"!=typeof i?i+"":i,t),t);exports.FileChooser=class{constructor(r,s){n(this,"_file",e.ref(null)),n(this,"_error",e.ref("")),n(this,"_imageDataUrl",e.ref("")),n(this,"_isDragging",e.ref(!1)),n(this,"_extensions",[t.JPG,t.JPEG,t.PNG]),n(this,"_maxSize",i["1MB"]),r&&(this._extensions=r),s&&(this._maxSize=s)}get file(){return this._file}get imageDataUrl(){return this._imageDataUrl}get isDragging(){return this._isDragging}get error(){return this._error}onChange(e,i){e.preventDefault();const t=this._readFileFromEvent(e,i);t?this._setFile(t):this._error.value="Please choose a file"}onDrag(e,i){e.preventDefault(),this._isDragging.value=i}destroy(){this._revokeObjectUrl(),this._isDragging.value=!1,this._imageDataUrl.value="",this._file.value=null,this._error.value=""}_setFile(e){const{ext:i,size:t}=this._getFileExtAndSize(e);return i&&this._extensions.includes(i)?t>this._maxSize?(this._handleOnFail(),void(this._error.value=(e=>s[e])(this._maxSize))):(this._file.value=e,void this._fileToDataUrl()):(this._handleOnFail(),void(this._error.value="File extensions is not eligible"))}_handleOnFail(){this._isDragging.value=!1}_getFileExtAndSize(e){const{ext:i,size:t}=(e=>{const{size:i,name:t}=e;return{ext:a.exec(t.toLowerCase())?.[0]??null,size:i}})(e);return{ext:i,size:t}}_fileToDataUrl(){this._revokeObjectUrl();const e=URL.createObjectURL(this._file.value),i=new FileReader;i.addEventListener("load",(()=>{this._imageDataUrl.value=e})),i.readAsArrayBuffer(this._file.value)}_readFileFromEvent(e,i){const t=i?e.dataTransfer?.files:e.target?.files;return t?.item(0)}_revokeObjectUrl(){this._imageDataUrl.value&&URL.revokeObjectURL(this._imageDataUrl.value)}},exports.SUPPORTED_EXTENSIONS=t,exports.SUPPORTED_MAX_FILE_SIZE=i;