import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { useShallow } from 'zustand/shallow';
import { useEffect } from 'react';
import { Typography, Button } from '@bigbinary/neeto-atoms';
import { S as SvgInternalServerError, a as SvgUnauthorized, b as SvgPageNotFound, p as purify } from '../unauthorized-DLPyUaeK.js';
import { useErrorDisplayStore } from '@bigbinary/neeto-commons-frontend/v2/react-utils/useDisplayErrorPage';
import { Helmet } from 'react-helmet';
import { useTranslation, Trans } from 'react-i18next';
import { jsx, jsxs } from 'react/jsx-runtime';

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

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 = 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 = useTranslation(),
    t = _useTranslation.t;
  var _useErrorDisplayStore = useErrorDisplayStore(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;
  useEffect(function () {
    var pageLoader = document.getElementById("neeto-page-loader");
    if (pageLoader) pageLoader.remove();
    var onBackButtonPress = function onBackButtonPress() {
      if (!showErrorPage) return;
      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__*/jsx("div", {
    className: "@container/error-page flex min-h-dvh w-full flex-col items-center justify-center",
    "data-testid": "error-page-container",
    children: /*#__PURE__*/jsxs("div", {
      className: "flex w-[768px] max-w-full flex-col gap-8 p-4 @[768px]/error-page:flex-row @[768px]/error-page:gap-12 @[768px]/error-page:p-6",
      children: [/*#__PURE__*/jsx(Image, {
        className: "dark:[&_path]:fill-foreground w-full max-w-[180px] shrink-0 @[768px]/error-page:max-w-[240px]",
        "data-testid": "error-image"
      }), /*#__PURE__*/jsxs("div", {
        className: "flex flex-col justify-center md:min-w-0 md:flex-grow",
        children: [/*#__PURE__*/jsx(Helmet, {
          children: /*#__PURE__*/jsx("title", {
            children: t(titleKey)
          })
        }), /*#__PURE__*/jsx(Typography, {
          className: "mb-4",
          "data-testid": "title",
          variant: "h3",
          weight: "semibold",
          children: title || /*#__PURE__*/jsx(Trans, {
            i18nKey: errorKey
          })
        }), !!description && /*#__PURE__*/jsx(Typography, {
          className: "mb-4",
          dangerouslySetInnerHTML: {
            __html: sanitize(description)
          },
          "data-testid": "description",
          variant: "body1"
        }), showNeetoChatWidget && /*#__PURE__*/jsx(Typography, {
          className: "mb-6",
          "data-testid": "title",
          variant: "body1",
          children: /*#__PURE__*/jsx(Trans, {
            i18nKey: "neetoMolecules.errorPage.contactUs",
            components: {
              button: /*#__PURE__*/jsx(Button, {
                className: "h-auto p-0 text-[inherit]",
                variant: "link",
                onClick: openChatWidget
              })
            }
          })
        }), /*#__PURE__*/jsxs("div", {
          className: "flex flex-col items-start gap-3 [&_a]:no-underline",
          children: [!hideBackToHomeButton && /*#__PURE__*/jsx(Button, _objectSpread(_objectSpread({
            asChild: true,
            size: "lg",
            variant: "default"
          }, backToHomeButtonProps), {}, {
            children: /*#__PURE__*/jsx("a", {
              href: homeUrl,
              children: t("neetoMolecules.errorPage.backToHome")
            })
          })), children]
        })]
      })]
    })
  });
};

export { ErrorPage as default };
//# sourceMappingURL=ErrorPage.js.map
