'use strict';

var useParrotTranslation = require('../../hooks/useParrotTranslation.js');
var React = require('react');
var LocalUpload_style = require('./LocalUpload.style.js');
var LocalUpload_widget = require('./LocalUpload.widget.js');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var React__default = /*#__PURE__*/_interopDefault(React);

var __defProp = Object.defineProperty;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
  for (var prop in b || (b = {}))
    if (__hasOwnProp.call(b, prop))
      __defNormalProp(a, prop, b[prop]);
  if (__getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(b)) {
      if (__propIsEnum.call(b, prop))
        __defNormalProp(a, prop, b[prop]);
    }
  return a;
};
const UploadComp = React__default.default.forwardRef(
  ({
    className,
    label,
    description,
    type = "dragger",
    multiple = false,
    accept,
    disabled,
    maxCount,
    info,
    fileList,
    setFileList,
    validate,
    buttonProps,
    listType = "list",
    disableRemoveList = false,
    onRemove
  }, ref) => {
    const { t } = useParrotTranslation();
    const removeFile = (id) => {
      const index = fileList.findIndex((f) => f.uid === id);
      if (index !== -1) {
        const file = fileList[index];
        fileList.splice(index, 1);
        setFileList([...fileList]);
        onRemove == null ? void 0 : onRemove(file);
      }
    };
    const _maxCount = multiple ? maxCount || Infinity : 1;
    const isSingleSelect = _maxCount === 1;
    return /* @__PURE__ */ React__default.default.createElement(UploadComp.Wrapper, { className, ref }, label ? /* @__PURE__ */ React__default.default.createElement(UploadComp.Label, null, label) : null, description ? /* @__PURE__ */ React__default.default.createElement(UploadComp.Description, null, description) : null, type === "button" ? /* @__PURE__ */ React__default.default.createElement(
      UploadComp.Button,
      __spreadValues({}, __spreadValues({
        accept,
        multiple,
        disabled,
        maxCount,
        fileList,
        setFileList,
        validate
      }, buttonProps)),
      t("components.select_file")
    ) : /* @__PURE__ */ React__default.default.createElement(
      UploadComp.Dragger,
      __spreadValues({}, {
        accept,
        multiple,
        disabled,
        maxCount,
        fileList,
        setFileList,
        validate
      })
    ), info != null ? info : /* @__PURE__ */ React__default.default.createElement(React__default.default.Fragment, null), type === "button" || !isSingleSelect ? /* @__PURE__ */ React__default.default.createElement(
      UploadComp.FileList,
      {
        fileList,
        removeFile,
        type: listType,
        disableRemove: disableRemoveList,
        onRemove
      }
    ) : null);
  }
);
UploadComp.Wrapper = LocalUpload_style.UploadWrapper;
UploadComp.Label = LocalUpload_widget.UploadLabel;
UploadComp.Description = LocalUpload_widget.UploadDescription;
UploadComp.Button = LocalUpload_widget.UploadButton;
UploadComp.Dragger = LocalUpload_widget.UploadDragger;
UploadComp.FileList = LocalUpload_widget.UploadFileList;
UploadComp.FileInfo = LocalUpload_widget.UploadFileInfo;
const LocalUpload = UploadComp;

exports.LocalUpload = LocalUpload;
