'use strict';

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var shallow = require('zustand/shallow');
var React = require('react');
var unauthorized = require('./unauthorized-CI14HDQo.js');
var useDisplayErrorPage = require('@bigbinary/neeto-commons-frontend/react-utils/useDisplayErrorPage');
var Button = require('@bigbinary/neetoui/Button');
var Typography = require('@bigbinary/neetoui/Typography');
var reactHelmet = require('react-helmet');
var reactI18next = require('react-i18next');
var injectCss = require('./inject-css-B6qYtOJe.js');
var jsxRuntime = require('react/jsx-runtime');

var ERRORS = {
  404: {
    Image: unauthorized.SvgPageNotFound,
    errorKey: "neetoMolecules.errorPage.cantBeFound",
    titleKey: "neetoMolecules.errorPage.title.cantBeFound"
  },
  403: {
    Image: unauthorized.SvgUnauthorized,
    errorKey: "neetoMolecules.errorPage.unauthorized",
    titleKey: "neetoMolecules.errorPage.title.unauthorized"
  },
  500: {
    Image: unauthorized.SvgInternalServerError,
    errorKey: "neetoMolecules.errorPage.internalServerError",
    titleKey: "neetoMolecules.errorPage.title.internalServerError"
  }
};

var css = ".neeto-molecules-error-page__wrapper{align-items:center;container-name:error-page-wrapper;container-type:inline-size;display:flex;flex-direction:column;justify-content:center;min-height:100vh;min-height:100dvh;width:100%}.neeto-molecules-error-page__container{display:flex;flex-direction:column;gap:32px;max-width:100%;padding:16px;width:768px}@container error-page-wrapper (min-width: 768px){.neeto-molecules-error-page__container{flex-direction:row;gap:48px;padding:24px}}.neeto-molecules-error-page__image{flex-shrink:0;max-width:180px;width:100%}@container error-page-wrapper (min-width: 768px){.neeto-molecules-error-page__image{max-width:240px}}.neeto-molecules-error-page__action-btn{align-items:flex-start;display:flex;flex-direction:column;gap:12px}.neeto-molecules-error-page__action-btn a{text-decoration:none}.neeto-ui-theme--dark .neeto-molecules-error-code path{fill:rgb(var(--neeto-ui-black))}";
injectCss.n(css,{});

function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var sanitize = unauthorized.purify.sanitize;
var ErrorPage = function ErrorPage(_ref) {
  var _ref$homeUrl = _ref.homeUrl,
    homeUrl = _ref$homeUrl === void 0 ? "/" : _ref$homeUrl,
    status = _ref.status,
    backToHomeButtonProps = _ref.backToHomeButtonProps,
    children = _ref.children,
    _ref$showNeetoChatWid = _ref.showNeetoChatWidget,
    showNeetoChatWidget = _ref$showNeetoChatWid === void 0 ? true : _ref$showNeetoChatWid,
    description = _ref.description,
    title = _ref.title,
    _ref$hideBackToHomeBu = _ref.hideBackToHomeButton,
    hideBackToHomeButton = _ref$hideBackToHomeBu === void 0 ? false : _ref$hideBackToHomeBu;
  var _useTranslation = reactI18next.useTranslation(),
    t = _useTranslation.t;
  var _useErrorDisplayStore = useDisplayErrorPage.useErrorDisplayStore(shallow.useShallow(function (store) {
      return {
        statusCode: store["statusCode"],
        showErrorPage: store["showErrorPage"]
      };
    })),
    storeStatusCode = _useErrorDisplayStore.statusCode,
    showErrorPage = _useErrorDisplayStore.showErrorPage;
  status = status || storeStatusCode;
  var _ref2 = ERRORS[status] || ERRORS[404],
    Image = _ref2.Image,
    errorKey = _ref2.errorKey,
    titleKey = _ref2.titleKey;
  React.useEffect(function () {
    var pageLoader = document.getElementById("neeto-page-loader");
    if (pageLoader) pageLoader.remove();
    var onBackButtonPress = function onBackButtonPress() {
      if (!showErrorPage) return;
      useDisplayErrorPage.useErrorDisplayStore.setState({
        showErrorPage: false
      });
    };
    window.addEventListener("popstate", onBackButtonPress);
    return function () {
      window.removeEventListener("popstate", onBackButtonPress);
    };
  }, []);
  var openChatWidget = function openChatWidget() {
    var _window$NeetoChat, _window$NeetoChat2;
    (_window$NeetoChat = window.NeetoChat) === null || _window$NeetoChat === void 0 || (_window$NeetoChat = _window$NeetoChat.contextualHelp) === null || _window$NeetoChat === void 0 || _window$NeetoChat.maximizeWidget();
    (_window$NeetoChat2 = window.NeetoChat) === null || _window$NeetoChat2 === void 0 || (_window$NeetoChat2 = _window$NeetoChat2.contextualHelp) === null || _window$NeetoChat2 === void 0 || _window$NeetoChat2.openWidget();
  };
  return /*#__PURE__*/jsxRuntime.jsx("div", {
    className: "neeto-molecules-error-page__wrapper",
    "data-testid": "error-page-container",
    children: /*#__PURE__*/jsxRuntime.jsxs("div", {
      className: "neeto-molecules-error-page__container",
      children: [/*#__PURE__*/jsxRuntime.jsx(Image, {
        className: "neeto-molecules-error-code neeto-molecules-error-page__image",
        "data-testid": "error-image"
      }), /*#__PURE__*/jsxRuntime.jsxs("div", {
        className: "neeto-ui-flex neeto-ui-flex-col justify-center md:min-w-0 md:flex-grow",
        children: [/*#__PURE__*/jsxRuntime.jsx(reactHelmet.Helmet, {
          children: /*#__PURE__*/jsxRuntime.jsx("title", {
            children: t(titleKey)
          })
        }), /*#__PURE__*/jsxRuntime.jsx(Typography, {
          className: "neeto-ui-mb-4",
          "data-testid": "title",
          style: "h2",
          weight: "semibold",
          children: title || /*#__PURE__*/jsxRuntime.jsx(reactI18next.Trans, {
            i18nKey: errorKey
          })
        }), !!description && /*#__PURE__*/jsxRuntime.jsx(Typography, {
          className: "neeto-ui-mb-4",
          dangerouslySetInnerHTML: {
            __html: sanitize(description)
          },
          "data-testid": "description",
          style: "body1"
        }), showNeetoChatWidget && /*#__PURE__*/jsxRuntime.jsx(Typography, {
          className: "neeto-ui-mb-6",
          "data-testid": "title",
          style: "body1",
          children: /*#__PURE__*/jsxRuntime.jsx(reactI18next.Trans, {
            i18nKey: "neetoMolecules.errorPage.contactUs",
            components: {
              button: /*#__PURE__*/jsxRuntime.jsx(Button, {
                className: "neeto-ui-font-size-inherit",
                size: "large",
                style: "link",
                onClick: openChatWidget
              })
            }
          })
        }), /*#__PURE__*/jsxRuntime.jsxs("div", {
          className: "neeto-molecules-error-page__action-btn",
          children: [!hideBackToHomeButton && /*#__PURE__*/jsxRuntime.jsx(Button, _objectSpread({
            href: homeUrl,
            label: t("neetoMolecules.errorPage.backToHome"),
            size: "large",
            style: "primary"
          }, backToHomeButtonProps)), children]
        })]
      })]
    })
  });
};

module.exports = ErrorPage;
//# sourceMappingURL=ErrorPage.js.map
