"use strict";

exports.__esModule = true;
exports.default = exports.DragAndDrop = void 0;
var _react = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _getOr = _interopRequireDefault(require("lodash/fp/getOr"));
var _includes = _interopRequireDefault(require("lodash/fp/includes"));
var _reactDropzone = _interopRequireDefault(require("react-dropzone"));
var _novaIcons = require("@coorpacademy/nova-icons");
var _provider = _interopRequireDefault(require("../../atom/provider"));
var _inputText = _interopRequireDefault(require("../../atom/input-text"));
var _overlay = require("./overlay");
var _uploadReport = require("./upload-report");
var _placeholder = require("./placeholder");
var _style = _interopRequireDefault(require("./style.css"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
const DragAndDrop = (props, context) => {
  const {
    skin
  } = context;
  const primaryColor = (0, _getOr.default)('#00B0FF', 'common.primary', skin);
  const {
    state,
    title,
    message,
    warningMessage,
    mode,
    dragAndDropMessage,
    buttonTitle,
    backLabel,
    orLabel,
    accept,
    type: contentType = 'scorm',
    fields,
    onDrop,
    onDelete,
    onBack
  } = props;
  const handleBack = (0, _react.useCallback)(e => {
    e.stopPropagation();
    e.preventDefault();
    onBack && onBack(e);
  }, [onBack]);
  const loading = state === 'loading';
  return /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement("span", {
    onClick: handleBack,
    className: _style.default.back,
    "data-testid": "back"
  }, /*#__PURE__*/_react.default.createElement(_novaIcons.NovaCompositionNavigationArrowLeft, {
    width: 12,
    height: 12,
    className: _style.default.arrow
  }), backLabel), /*#__PURE__*/_react.default.createElement(_reactDropzone.default, {
    accept: accept,
    disabled: loading,
    onDrop: onDrop
  }, ({
    getRootProps,
    getInputProps,
    isDragActive
  }) => {
    const getView = () => {
      if (contentType !== 'scorm' || (0, _includes.default)(state, ['success', 'error', 'ready'])) {
        return /*#__PURE__*/_react.default.createElement(_uploadReport.UploadReport, {
          state: state,
          message: message,
          warningMessage: warningMessage,
          fields: fields,
          type: contentType,
          onDelete: onDelete,
          mode: mode,
          orLabel: orLabel,
          onClick: onDrop,
          buttonTitle: buttonTitle,
          primaryColor: primaryColor
        });
      }
      return /*#__PURE__*/_react.default.createElement(_placeholder.PlaceHolder, {
        title: title,
        buttonTitle: buttonTitle,
        uploadLabel: message,
        primaryColor: primaryColor,
        onClick: onDrop
      });
    };
    const disableFileInput = state === 'success';
    return /*#__PURE__*/_react.default.createElement("div", _extends({}, getRootProps(), {
      "data-testid": "drop-zone",
      className: _style.default.wrapper
    }), /*#__PURE__*/_react.default.createElement("input", _extends({}, getInputProps(), {
      disabled: disableFileInput
    })), getView(), isDragActive || loading ? /*#__PURE__*/_react.default.createElement(_overlay.Overlay, {
      iconColor: primaryColor,
      description: dragAndDropMessage,
      isLoading: loading
    }) : null);
  }));
};
exports.DragAndDrop = DragAndDrop;
DragAndDrop.contextTypes = {
  skin: _provider.default.childContextTypes.skin
};
DragAndDrop.propTypes = process.env.NODE_ENV !== "production" ? {
  state: _propTypes.default.oneOf(['default', 'ready', 'loading', 'success', 'error']).isRequired,
  mode: _propTypes.default.oneOf(['edit', 'upload']),
  title: _propTypes.default.string,
  type: _propTypes.default.string,
  message: _propTypes.default.string,
  warningMessage: _propTypes.default.string,
  dragAndDropMessage: _propTypes.default.string,
  buttonTitle: _propTypes.default.string,
  backLabel: _propTypes.default.string,
  orLabel: _propTypes.default.string,
  onBack: _propTypes.default.func,
  accept: _propTypes.default.string,
  fields: _propTypes.default.arrayOf(_propTypes.default.shape({
    ..._inputText.default.propTypes,
    type: _propTypes.default.oneOf(['text'])
  })),
  onDrop: _propTypes.default.func,
  onDelete: _propTypes.default.func,
  actions: _propTypes.default.arrayOf(_propTypes.default.shape({
    type: _propTypes.default.oneOf(['edit', 'upload', 'delete']),
    label: _propTypes.default.string,
    onClick: _propTypes.default.func
  }))
} : {};
var _default = exports.default = DragAndDrop;
//# sourceMappingURL=index.js.map