"use strict";
// The require scope
var __webpack_require__ = {};
/************************************************************************/ // webpack/runtime/compat_get_default_export
(()=>{
    // getDefaultExport function for compatibility with non-ESM modules
    __webpack_require__.n = function(module) {
        var getter = module && module.__esModule ? function() {
            return module['default'];
        } : function() {
            return module;
        };
        __webpack_require__.d(getter, {
            a: getter
        });
        return getter;
    };
})();
// webpack/runtime/define_property_getters
(()=>{
    __webpack_require__.d = function(exports1, definition) {
        for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
            enumerable: true,
            get: definition[key]
        });
    };
})();
// webpack/runtime/has_own_property
(()=>{
    __webpack_require__.o = function(obj, prop) {
        return Object.prototype.hasOwnProperty.call(obj, prop);
    };
})();
// webpack/runtime/make_namespace_object
(()=>{
    // define __esModule on exports
    __webpack_require__.r = function(exports1) {
        if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
            value: 'Module'
        });
        Object.defineProperty(exports1, '__esModule', {
            value: true
        });
    };
})();
/************************************************************************/ var __webpack_exports__ = {};
// ESM COMPAT FLAG
__webpack_require__.r(__webpack_exports__);
// EXPORTS
__webpack_require__.d(__webpack_exports__, {
    default: ()=>/* binding */ Dropzone_rslib_entry_
});
const react_namespaceObject = require("@chakra-ui/react");
const external_react_namespaceObject = require("react");
const md_namespaceObject = require("react-icons/md");
const Avatars_js_namespaceObject = require("../../Avatars/Avatars.js");
var Avatars_js_default = /*#__PURE__*/ __webpack_require__.n(Avatars_js_namespaceObject);
function Dropzone({ setRawString, fileUploadLogo, fileUploadText, fileUploadDescription, fileUploadedLogo, fileUploadedText, fileRemoveText }) {
    // drag state
    const [dragActive, setDragActive] = (0, external_react_namespaceObject.useState)(false);
    const [file, setFile] = (0, external_react_namespaceObject.useState)();
    // ref
    const inputRef = (0, external_react_namespaceObject.useRef)(null);
    const formRef = (0, external_react_namespaceObject.useRef)(null);
    const handleFile = async (file)=>{
        const string = await file.text();
        setFile(file);
        setRawString(string);
    };
    // handle drag events
    const handleDrag = (event)=>{
        event.preventDefault();
        event.stopPropagation();
        if ('dragenter' === event.type || 'dragover' === event.type) setDragActive(true);
        else if ('dragleave' === event.type) setDragActive(false);
    };
    // triggers when file is dropped
    const handleDrop = async (event)=>{
        event.preventDefault();
        event.stopPropagation();
        setDragActive(false);
        if (event?.dataTransfer?.files?.length > 0) handleFile(event.dataTransfer.files[0]);
    };
    // triggers when file is selected with click
    const handleChange = (event)=>{
        event.preventDefault();
        if (event?.target?.files && event?.target?.files?.length > 0) handleFile(event.target.files[0]);
    };
    // triggers the input when the button is clicked
    const onButtonClick = ()=>{
        inputRef?.current?.click();
    };
    const cleanState = ()=>{
        setFile(void 0);
        setRawString(void 0);
        formRef?.current?.reset();
    };
    return /*#__PURE__*/ React.createElement(react_namespaceObject.FormControl, {
        mt: 4,
        id: "form-file-upload",
        onDragEnter: handleDrag,
        onSubmit: (e)=>e.preventDefault(),
        borderRadius: 10,
        height: "10vw",
        ref: formRef,
        as: "form"
    }, /*#__PURE__*/ React.createElement(react_namespaceObject.Flex, {
        justifyContent: "center",
        alignItems: "center",
        h: "100%",
        direction: "column"
    }, /*#__PURE__*/ React.createElement(react_namespaceObject.Input, {
        ref: inputRef,
        type: "file",
        id: "input-file-upload",
        onChange: handleChange,
        multiple: false,
        display: "none"
    }), void 0 === file ? /*#__PURE__*/ React.createElement(react_namespaceObject.Flex, {
        alignItems: "center",
        direction: "column"
    }, fileUploadLogo || /*#__PURE__*/ React.createElement(react_namespaceObject.chakra.img, {
        "data-testid": "upload-file-logo",
        src: Avatars_js_default().uploadFileSvg,
        mb: 5,
        alt: "upload-file-logo"
    }), /*#__PURE__*/ React.createElement(react_namespaceObject.Text, {
        textAlign: "center"
    }, /*#__PURE__*/ React.createElement(react_namespaceObject.Button, {
        variant: "link",
        onClick: onButtonClick
    }, fileUploadText || 'Click to upload'), /*#__PURE__*/ React.createElement(react_namespaceObject.Text, null, " or drag and drop a file here"), /*#__PURE__*/ React.createElement(react_namespaceObject.Center, null, fileUploadDescription))) : /*#__PURE__*/ React.createElement(React.Fragment, null, fileUploadedLogo || /*#__PURE__*/ React.createElement(react_namespaceObject.Icon, {
        as: md_namespaceObject.MdCloudDone,
        color: "green.500",
        w: "20",
        h: "20"
    }), fileUploadedText || /*#__PURE__*/ React.createElement(react_namespaceObject.Text, null, file.name, " successfully uploaded"), /*#__PURE__*/ React.createElement(react_namespaceObject.Button, {
        variant: "ghost",
        onClick: cleanState
    }, fileRemoveText || /*#__PURE__*/ React.createElement(react_namespaceObject.Text, {
        as: "u"
    }, "Remove file"))), dragActive && /*#__PURE__*/ React.createElement(react_namespaceObject.Box, {
        position: "absolute",
        w: "100%",
        h: "100%",
        top: "0",
        bottom: "0",
        right: "0",
        left: "0",
        id: "drag-file-element",
        onDragEnter: handleDrag,
        onDragLeave: handleDrag,
        onDragOver: handleDrag,
        onDrop: handleDrop
    })));
}
/* ESM default export */ const Dropzone_rslib_entry_ = Dropzone;
var __webpack_export_target__ = exports;
for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
    value: true
});
