import _includes from "lodash/fp/includes";
import _isEmpty from "lodash/fp/isEmpty";
import _getOr from "lodash/fp/getOr";
import _head from "lodash/fp/head";
import _map from "lodash/fp/map";
import _last from "lodash/fp/last";
import _split from "lodash/fp/split";
import _pipe from "lodash/fp/pipe";
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 { NovaCompositionCoorpacademyValidate as Validated, NovaLineContentEditionBin as TrashIcon, NovaCompositionCoorpacademyWarn as WarnIcon } from '@coorpacademy/nova-icons';
import classnames from 'classnames';
import { EXTERNAL_CONTENT_ICONS } from '../../util/external-content';
import InputText from '../../atom/input-text';
import Button from '../../atom/button';
import style from './upload-report.css';
const SuccessMessage = ({
  message
}) => /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("span", {
  className: style.emoticon
}, "\uD83C\uDF89"), /*#__PURE__*/React.createElement("p", {
  className: style.message
}, message));
SuccessMessage.propTypes = process.env.NODE_ENV !== "production" ? {
  message: PropTypes.string.isRequired
} : {};
const ErrorMessage = ({
  message,
  buttonTitle,
  primaryColor
}) => /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("span", {
  className: style.emoticon
}, "\uD83E\uDD7A"), /*#__PURE__*/React.createElement("p", {
  className: style.message
}, message)), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Button, {
  "data-name": "cta",
  type: "link",
  submitValue: buttonTitle,
  className: style.selectButton,
  style: {
    backgroundColor: primaryColor
  }
})));
ErrorMessage.propTypes = process.env.NODE_ENV !== "production" ? {
  message: PropTypes.string.isRequired,
  buttonTitle: PropTypes.string,
  primaryColor: PropTypes.string
} : {};
export const UploadReport = ({
  state,
  message,
  warningMessage,
  type: contentType,
  fields,
  mode = 'upload',
  orLabel,
  buttonTitle,
  primaryColor,
  onDelete
}) => {
  const handleDelete = useCallback(e => {
    e.stopPropagation();
    e.preventDefault();
    onDelete && onDelete(e);
  }, [onDelete]);
  const stopPropagationHandler = useCallback(e => {
    e.stopPropagation();
    e.preventDefault();
  }, []);
  const showMessage = _includes(state, ['success', 'error']);
  const fileName = _pipe(_head, _getOr('', 'value'), _split('/'), _last)(fields);
  const fileView = fileName ? /*#__PURE__*/React.createElement("div", {
    className: style.fileWrapper
  }, /*#__PURE__*/React.createElement("div", {
    className: style.fileName,
    title: fileName
  }, fileName), _isEmpty(warningMessage) ? /*#__PURE__*/React.createElement(Validated, {
    className: style.validateIcon
  }) : /*#__PURE__*/React.createElement("div", {
    className: style.warning
  }, /*#__PURE__*/React.createElement("div", {
    className: style.showToolTip
  }, /*#__PURE__*/React.createElement("span", null, warningMessage)), /*#__PURE__*/React.createElement("div", {
    className: style.warningIcon
  }, /*#__PURE__*/React.createElement(WarnIcon, {
    width: 11,
    height: 11
  })))) : /*#__PURE__*/React.createElement("div", {
    className: style.emptyFileWrapper
  });
  const IconType = EXTERNAL_CONTENT_ICONS[contentType].icon;
  const iconColor = EXTERNAL_CONTENT_ICONS[contentType].color;
  const buildField = (field, index) => /*#__PURE__*/React.createElement(InputText, _extends({}, field, {
    key: index,
    theme: 'cockpit'
  }));
  const deleteView = onDelete ? /*#__PURE__*/React.createElement("div", {
    "data-testid": "trash-icon",
    onClick: handleDelete,
    className: classnames(style.actionIcon, style.trashIcon)
  }, /*#__PURE__*/React.createElement(TrashIcon, {
    width: 20,
    height: 20
  })) : null;
  const fieldsList = _map.convert({
    cap: false
  })(buildField, fields);
  return /*#__PURE__*/React.createElement("div", {
    className: style.reportingContainer
  }, /*#__PURE__*/React.createElement("div", {
    className: style.reportHeader,
    onClick: stopPropagationHandler
  }, /*#__PURE__*/React.createElement("div", {
    className: style.iconContainer,
    style: {
      backgroundColor: iconColor
    }
  }, /*#__PURE__*/React.createElement("div", {
    className: style.oval
  }, /*#__PURE__*/React.createElement(IconType, {
    className: style.iconHeader,
    style: {
      color: iconColor
    }
  }))), fileView, deleteView), /*#__PURE__*/React.createElement("div", {
    className: style.reportContainer,
    onClick: stopPropagationHandler
  }, state === 'success' ? /*#__PURE__*/React.createElement(SuccessMessage, {
    message: message
  }) : null, state === 'error' ? /*#__PURE__*/React.createElement(ErrorMessage, {
    message: message,
    buttonTitle: buttonTitle,
    primaryColor: primaryColor
  }) : null, mode === 'edit' && !showMessage ? /*#__PURE__*/React.createElement("div", null, fieldsList) : null, mode === 'edit' && !showMessage ? /*#__PURE__*/React.createElement("span", {
    className: style.or
  }, orLabel) : null), !showMessage ? /*#__PURE__*/React.createElement("div", {
    className: style.drop
  }, /*#__PURE__*/React.createElement("p", {
    className: style.message
  }, message), /*#__PURE__*/React.createElement(Button, {
    "data-name": "cta",
    type: "link",
    submitValue: buttonTitle,
    className: style.selectButton,
    style: {
      backgroundColor: primaryColor
    }
  })) : null);
};
export default UploadReport;
UploadReport.propTypes = process.env.NODE_ENV !== "production" ? {
  state: PropTypes.string.isRequired,
  message: PropTypes.string.isRequired,
  warningMessage: PropTypes.string,
  orLabel: PropTypes.string,
  type: PropTypes.string,
  fields: PropTypes.arrayOf(PropTypes.shape({
    ...InputText.propTypes,
    type: PropTypes.oneOf(['text'])
  })),
  mode: PropTypes.oneOf(['edit', 'upload']),
  buttonTitle: PropTypes.string,
  primaryColor: PropTypes.string,
  onDelete: PropTypes.func
} : {};
//# sourceMappingURL=upload-report.js.map