var _excluded = ["maxFileNumber", "children", "onSubmit", "sources", "isOpen", "currentSource", "onCurrentSourceChange", "onCancel", "unsubmittedValueCount", "qa"];
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
import React from 'react';
import { Button } from '../../Button/Button';
import { Modal } from '../../Modal/Modal';
import { Tooltip } from '../../Tooltip/Tooltip';
import { Typography } from '../../Typography/Typography';
import { useI18nContext } from '../../_hooks/I18n';
import { FileExplorerSidebar } from '../FileExplorer/FileExplorerSidebar';
import { StyledAttachButton, StyledModalBody, StyledModalContent, StyledModalHeader, StyledModalInnerBody, StyledSource } from './FileExplorer.styles';
import { FileExplorerModal } from './FileExplorerModal';
export var FileExplorer = /*#__PURE__*/React.forwardRef(function FileExplorer(_ref, ref) {
  var _ref$maxFileNumber = _ref.maxFileNumber,
    maxFileNumber = _ref$maxFileNumber === void 0 ? Infinity : _ref$maxFileNumber,
    children = _ref.children,
    onSubmit = _ref.onSubmit,
    sources = _ref.sources,
    isOpen = _ref.isOpen,
    currentSource = _ref.currentSource,
    onCurrentSourceChange = _ref.onCurrentSourceChange,
    onCancel = _ref.onCancel,
    unsubmittedValueCount = _ref.unsubmittedValueCount,
    qa = _ref.qa,
    props = _objectWithoutProperties(_ref, _excluded);
  var I18n = useI18nContext();
  var hasPendingUploadSources = sources.some(function (_ref2) {
    var isUploading = _ref2.isUploading;
    return isUploading;
  });
  var isAttachButtonDisabled = hasPendingUploadSources || unsubmittedValueCount === 0;
  return /*#__PURE__*/React.createElement(FileExplorerModal, _extends({}, props, {
    ref: ref,
    open: isOpen,
    onKeyDown: function onKeyDown(e) {
      if (e.key === 'Esc' || e.key === 'Escape') {
        onCancel();
      }
    }
  }), /*#__PURE__*/React.createElement(StyledModalHeader, {
    onClose: function onClose() {
      onCancel();
    }
  }, I18n.t('core.fileExplorer.modalTitle')), /*#__PURE__*/React.createElement(StyledModalBody, null, /*#__PURE__*/React.createElement(StyledModalInnerBody, null, /*#__PURE__*/React.createElement(FileExplorerSidebar, {
    value: currentSource,
    onChange: onCurrentSourceChange,
    sources: sources,
    isOpen: isOpen
  }), /*#__PURE__*/React.createElement(StyledModalContent, {
    tabIndex: -1
  }, /*#__PURE__*/React.createElement(StyledSource, null, children)))), /*#__PURE__*/React.createElement(Modal.Footer, null, /*#__PURE__*/React.createElement(Modal.FooterNotation, null, /*#__PURE__*/React.createElement(Typography, {
    color: "gray45",
    italic: true
  }, maxFileNumber === Infinity ? I18n.t('core.fileExplorer.filesSelected', {
    count: unsubmittedValueCount
  }) : I18n.t('core.fileExplorer.filesSelectedWithLimit', {
    count: unsubmittedValueCount,
    maxFileNumber: maxFileNumber
  }))), /*#__PURE__*/React.createElement(Modal.FooterButtons, null, /*#__PURE__*/React.createElement(Button, {
    "data-qa": qa === null || qa === void 0 ? void 0 : qa.cancelButton,
    variant: "tertiary",
    onClick: function onClick() {
      onCancel();
    }
  }, I18n.t('core.fileExplorer.cancelAction')), /*#__PURE__*/React.createElement(Tooltip, {
    showKeys: [],
    trigger: isAttachButtonDisabled ? 'hover' : 'none',
    overlay: hasPendingUploadSources ? I18n.t('core.fileExplorer.filesPendingUpload') : I18n.t('core.fileExplorer.noSelectedItems')
  }, /*#__PURE__*/React.createElement(StyledAttachButton, null, /*#__PURE__*/React.createElement(Button, {
    "data-qa": qa === null || qa === void 0 ? void 0 : qa.attachButton,
    variant: "primary",
    disabled: isAttachButtonDisabled,
    onClick: function onClick() {
      onSubmit === null || onSubmit === void 0 ? void 0 : onSubmit();
    }
  }, I18n.t('core.fileExplorer.attachAction')))))));
});
//# sourceMappingURL=FileExplorer.js.map