import { slicedToArray as _slicedToArray } from '../../../_virtual/_rollupPluginBabelHelpers.js';
import React__default, { useState } from 'react';
import { Button } from '@mui/material';
import RequiredLabel from '../../labels/RequiredLabel/index.js';
import { FileUploadContainer, FileUploadWrapper } from './style.js';
import FileUploadIcon from '../../Icons/FileUploadIcon/index.js';
import FileUploadErrorIcon from '../../Icons/FileUploadErrorIcon/index.js';
import theme from '../../../Globals/theme.js';
import { ThemeProvider } from 'styled-components';
import globalStyle from '../../../Globals/global-styles.js';

var FileUpload = function FileUpload(_ref) {
  var isDisable = _ref.isDisable,
      label = _ref.label;

  var _useState = useState("Upload a file"),
      _useState2 = _slicedToArray(_useState, 2),
      fileName = _useState2[0],
      setFileName = _useState2[1];

  var _useState3 = useState(false),
      _useState4 = _slicedToArray(_useState3, 2),
      error = _useState4[0],
      setError = _useState4[1];

  var Class = function Class(err, disable) {
    if (err === true) {
      return "FileUploadError";
    } else if (disable === true) {
      return "disabled";
    } else {
      return "";
    }
  };

  return /*#__PURE__*/React__default.createElement(ThemeProvider, {
    theme: theme
  }, /*#__PURE__*/React__default.createElement(globalStyle, null), /*#__PURE__*/React__default.createElement(FileUploadContainer, null, label && /*#__PURE__*/React__default.createElement(RequiredLabel, {
    label: label
  }), /*#__PURE__*/React__default.createElement(FileUploadWrapper, {
    className: Class(error, isDisable)
  }, /*#__PURE__*/React__default.createElement("div", null, fileName), /*#__PURE__*/React__default.createElement(Button, {
    variant: "contained",
    component: "label"
  }, error === true ? /*#__PURE__*/React__default.createElement(FileUploadErrorIcon, null) : /*#__PURE__*/React__default.createElement(FileUploadIcon, null), "Choose", /*#__PURE__*/React__default.createElement("input", {
    type: "file",
    hidden: true,
    disabled: isDisable,
    onChange: function onChange(e) {
      if (e.target.files[0].size > 10485760) {
        setError(true);
      } else {
        setFileName(e.target.files[0].name);
      }
    }
  })))));
};

export { FileUpload as default };
//# sourceMappingURL=index.js.map
