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); }
import React, { useCallback } from 'react';
import PropTypes from 'prop-types';
import getOr from 'lodash/fp/getOr';
import includes from 'lodash/fp/includes';
import Dropzone from 'react-dropzone';
import { NovaCompositionNavigationArrowLeft as ArrowLeft } from '@coorpacademy/nova-icons';
import Provider from '../../atom/provider';
import InputText from '../../atom/input-text';
import { Overlay } from './overlay';
import { UploadReport } from './upload-report';
import { PlaceHolder } from './placeholder';
import style from './style.css';
export const DragAndDrop = (props, context) => {
  const {
    skin
  } = context;
  const primaryColor = getOr('#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 = useCallback(e => {
    e.stopPropagation();
    e.preventDefault();
    onBack && onBack(e);
  }, [onBack]);
  const loading = state === 'loading';
  return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("span", {
    onClick: handleBack,
    className: style.back,
    "data-testid": "back"
  }, /*#__PURE__*/React.createElement(ArrowLeft, {
    width: 12,
    height: 12,
    className: style.arrow
  }), backLabel), /*#__PURE__*/React.createElement(Dropzone, {
    accept: accept,
    disabled: loading,
    onDrop: onDrop
  }, ({
    getRootProps,
    getInputProps,
    isDragActive
  }) => {
    const getView = () => {
      if (contentType !== 'scorm' || includes(state, ['success', 'error', 'ready'])) {
        return /*#__PURE__*/React.createElement(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.createElement(PlaceHolder, {
        title: title,
        buttonTitle: buttonTitle,
        uploadLabel: message,
        primaryColor: primaryColor,
        onClick: onDrop
      });
    };
    const disableFileInput = state === 'success';
    return /*#__PURE__*/React.createElement("div", _extends({}, getRootProps(), {
      "data-testid": "drop-zone",
      className: style.wrapper
    }), /*#__PURE__*/React.createElement("input", _extends({}, getInputProps(), {
      disabled: disableFileInput
    })), getView(), isDragActive || loading ? /*#__PURE__*/React.createElement(Overlay, {
      iconColor: primaryColor,
      description: dragAndDropMessage,
      isLoading: loading
    }) : null);
  }));
};
DragAndDrop.contextTypes = {
  skin: Provider.childContextTypes.skin
};
DragAndDrop.propTypes = process.env.NODE_ENV !== "production" ? {
  state: PropTypes.oneOf(['default', 'ready', 'loading', 'success', 'error']).isRequired,
  mode: PropTypes.oneOf(['edit', 'upload']),
  title: PropTypes.string,
  type: PropTypes.string,
  message: PropTypes.string,
  warningMessage: PropTypes.string,
  dragAndDropMessage: PropTypes.string,
  buttonTitle: PropTypes.string,
  backLabel: PropTypes.string,
  orLabel: PropTypes.string,
  onBack: PropTypes.func,
  accept: PropTypes.string,
  fields: PropTypes.arrayOf(PropTypes.shape({
    ...InputText.propTypes,
    type: PropTypes.oneOf(['text'])
  })),
  onDrop: PropTypes.func,
  onDelete: PropTypes.func,
  actions: PropTypes.arrayOf(PropTypes.shape({
    type: PropTypes.oneOf(['edit', 'upload', 'delete']),
    label: PropTypes.string,
    onClick: PropTypes.func
  }))
} : {};
export default DragAndDrop;
//# sourceMappingURL=index.js.map