import useParrotTranslation from '../../hooks/useParrotTranslation.js';
import React__default from 'react';
import { UploadWrapper } from './LocalUpload.style.js';
import { UploadLabel, UploadDescription, UploadButton, UploadDragger, UploadFileList, UploadFileInfo } from './LocalUpload.widget.js';

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.forwardRef(
  ({
    className,
    "data-testid": dataTestId,
    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.createElement(
      UploadComp.Wrapper,
      {
        className,
        ref,
        "data-testid": dataTestId
      },
      label ? /* @__PURE__ */ React__default.createElement(UploadComp.Label, null, label) : null,
      description ? /* @__PURE__ */ React__default.createElement(UploadComp.Description, null, description) : null,
      type === "button" ? /* @__PURE__ */ React__default.createElement(
        UploadComp.Button,
        __spreadValues({}, __spreadValues({
          accept,
          multiple,
          disabled,
          maxCount,
          fileList,
          setFileList,
          validate
        }, buttonProps)),
        t("components.select_file")
      ) : /* @__PURE__ */ React__default.createElement(
        UploadComp.Dragger,
        __spreadValues({}, {
          accept,
          multiple,
          disabled,
          maxCount,
          fileList,
          setFileList,
          validate
        })
      ),
      info != null ? info : /* @__PURE__ */ React__default.createElement(React__default.Fragment, null),
      type === "button" || !isSingleSelect ? /* @__PURE__ */ React__default.createElement(
        UploadComp.FileList,
        {
          fileList,
          removeFile,
          type: listType,
          disableRemove: disableRemoveList,
          onRemove
        }
      ) : null
    );
  }
);
UploadComp.Wrapper = UploadWrapper;
UploadComp.Label = UploadLabel;
UploadComp.Description = UploadDescription;
UploadComp.Button = UploadButton;
UploadComp.Dragger = UploadDragger;
UploadComp.FileList = UploadFileList;
UploadComp.FileInfo = UploadFileInfo;
const LocalUpload = UploadComp;

export { LocalUpload };
