"use strict";

exports.__esModule = true;
exports.default = void 0;
var _getOr2 = _interopRequireDefault(require("lodash/fp/getOr"));
var _react = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _novaIcons = require("@coorpacademy/nova-icons");
var _button = _interopRequireDefault(require("../../atom/button"));
var _loader = _interopRequireDefault(require("../../atom/loader"));
var _style = _interopRequireDefault(require("./style.css"));
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 _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const Popin = (props, context) => {
  const {
    skin
  } = context;
  const primaryColor = (0, _getOr2.default)('#00B0FF', 'common.primary', skin);
  const {
    header,
    content,
    firstButtonLabel,
    onFirstButtonClick,
    secondeButtonLabel,
    onSecondeButtonClick,
    onClose,
    type,
    isLoading = false,
    backgroundImageUrl
  } = props;
  const logo = {
    hiddenStateManagment: _novaIcons.NovaLineContentEditionHide,
    deleteContent: _novaIcons.NovaLineContentEditionBin,
    videoTranslate: _novaIcons.NovaCompositionCoorpacademyLocales
  };
  const LogoComponent = logo[type];
  const backgroundImageStyle = backgroundImageUrl ? {
    backgroundImage: `url(${backgroundImageUrl})`
  } : {};
  const [value, setValue] = (0, _react.useState)({
    object: '',
    message: '',
    email: ''
  });
  const handleChange = (0, _react.useMemo)(() => event => {
    setValue({
      ...value,
      [event.target.name]: event.target.value
    });
  }, [value]);
  const isAssistancePopin = type === 'assistance';
  const handleClickOnSecondButton = (0, _react.useMemo)(() => {
    return type === 'assistance' ? onSecondeButtonClick(value) : onSecondeButtonClick;
  }, [value, type, onSecondeButtonClick]);
  return /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.background,
    style: backgroundImageStyle
  }, isLoading ? /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.loader
  }, /*#__PURE__*/_react.default.createElement(_loader.default, {
    "data-name": "cockpit-popin-loader"
  })) : /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.popin
  }, /*#__PURE__*/_react.default.createElement("header", {
    className: _style.default.popinHeader
  }, /*#__PURE__*/_react.default.createElement(_novaIcons.NovaSolidStatusClose, {
    onClick: onClose,
    className: _style.default.headerCloseIcon
  })), LogoComponent ? /*#__PURE__*/_react.default.createElement(LogoComponent, {
    className: _style.default.icon,
    style: {
      color: primaryColor
    }
  }) : null, /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.header,
    "data-name": `cockpit-popin-header-${type}`
  }, header), /*#__PURE__*/_react.default.createElement("p", {
    className: _style.default.content,
    "data-name": `cockpit-popin-content-${type}`
    // eslint-disable-next-line react/no-danger
    ,
    dangerouslySetInnerHTML: {
      __html: content
    }
  }), isAssistancePopin ? /*#__PURE__*/_react.default.createElement("div", {
    style: {
      width: '70%'
    }
  }, /*#__PURE__*/_react.default.createElement("input", {
    "data-name": "contact-object",
    className: _style.default.inputText,
    name: "object",
    type: "text",
    placeholder: "Object",
    value: value.object,
    onChange: handleChange
  }), /*#__PURE__*/_react.default.createElement("textarea", {
    className: (_style.default.inputText, _style.default.inputTextArea),
    "data-name": "contact-message",
    name: "message",
    type: "text",
    placeholder: "Message",
    value: value.message,
    onChange: handleChange
  }), /*#__PURE__*/_react.default.createElement("input", {
    className: _style.default.lastInputText,
    "data-name": "contact-email",
    name: "email",
    type: "text",
    placeholder: "Email",
    value: value.email,
    onChange: handleChange
  })) : null, /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.buttonContainer
  }, firstButtonLabel ? /*#__PURE__*/_react.default.createElement(_button.default, {
    submitValue: firstButtonLabel,
    onClick: onFirstButtonClick,
    name: `cockpit-popin-cta-${type}`,
    className: _style.default.button,
    style: {
      backgroundColor: 'white',
      color: 'gray'
    }
  }) : null, secondeButtonLabel ? /*#__PURE__*/_react.default.createElement(_button.default, {
    submitValue: secondeButtonLabel,
    onClick: handleClickOnSecondButton,
    name: `cockpit-popin-cta-${type}`,
    className: _style.default.button,
    style: {
      backgroundColor: primaryColor
    },
    disabled: isAssistancePopin && !value.message
  }) : null)));
};
Popin.propTypes = process.env.NODE_ENV !== "production" ? {
  header: _propTypes.default.string,
  content: _propTypes.default.string,
  firstButtonLabel: _propTypes.default.string,
  onFirstButtonClick: _propTypes.default.func,
  secondeButtonLabel: _propTypes.default.string,
  onSecondeButtonClick: _propTypes.default.func,
  onClose: _propTypes.default.func,
  type: _propTypes.default.oneOf(['videoTranslate', 'hiddenStateManagment', 'deleteContent', 'assistance']),
  isLoading: _propTypes.default.bool,
  backgroundImageUrl: _propTypes.default.string
} : {};
var _default = exports.default = Popin;
//# sourceMappingURL=index.js.map