'use strict';

var injectCss = require('./inject-css-B6qYtOJe.js');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
var jsxRuntime = require('react/jsx-runtime');
var React = require('react');
var reactI18next = require('react-i18next');
var classnames = require('classnames');
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
var i18next = require('i18next');
var ramda = require('ramda');
var uaParser = require('./ua-parser-E0eEtHJZ.js');

var css = ":root{--neeto-molecules-browser-support-callout-bg:#feecf0;--neeto-molecules-browser-support-border-color:#d7373f;--neeto-molecules-browser-support-text-color:#121212;--neeto-molecules-browser-support-link-color:#2d36d4}.neeto-molecules-browser-support-callout{background-color:#feecf0;background-color:var(--neeto-molecules-browser-support-callout-bg);display:flex;justify-content:center;line-height:1.5;padding:.3125rem .625rem}.neeto-molecules-browser-support-callout__message{color:#121212;color:var(--neeto-molecules-browser-support-text-color);font-size:.875rem}.neeto-molecules-browser-support-page{align-items:center;background-color:#fff;display:flex;flex-direction:column;height:100vh;height:100dvh;justify-content:center;overflow-y:auto}.neeto-molecules-browser-support-page__content{align-items:center;display:flex;flex-direction:column;justify-content:center;max-width:100%;padding-left:.9375rem;padding-right:.9375rem;width:45rem}.neeto-molecules-browser-support-page__header{color:#121212;color:var(--neeto-molecules-browser-support-text-color);font-size:1.5rem;margin:0 0 .5rem}.neeto-molecules-browser-support-page__desc{color:#121212;color:var(--neeto-molecules-browser-support-text-color);font-size:1rem;line-height:1.5;margin:0 0 1rem}.neeto-molecules-browser-support-callout__message,.neeto-molecules-browser-support-page__desc{text-align:center}.neeto-molecules-browser-support-callout__message a,.neeto-molecules-browser-support-page__desc a{color:#2d36d4;color:var(--neeto-molecules-browser-support-link-color)}.neeto-molecules-browser-support-callout__message a:hover,.neeto-molecules-browser-support-page__desc a:hover{text-decoration:underline}.neeto-molecules-browser-support__link-button{color:#2d36d4;color:var(--neeto-molecules-browser-support-link-color)}.neeto-molecules-browser-support__link-button:hover{text-decoration:underline}";
injectCss.n(css,{});

var DEFAULT_MINIMUM_SUPPORTED_BROWSER_VERSIONS = {
  Chrome: {
    softLimit: 108,
    hardLimit: 70
  },
  Edge: {
    softLimit: 108,
    hardLimit: 106
  },
  Firefox: {
    softLimit: 102,
    hardLimit: 90
  },
  IE: {
    softLimit: 11,
    hardLimit: 11
  },
  Opera: {
    softLimit: 93,
    hardLimit: 89
  },
  Safari: {
    softLimit: 11,
    hardLimit: 10
  },
  WebKit: {
    softLimit: 604,
    hardLimit: 600
  },
  MobileChrome: {
    softLimit: 109,
    hardLimit: 105
  },
  MobileFirefox: {
    softLimit: 109,
    hardLimit: 105
  },
  MobileSafari: {
    softLimit: 11,
    hardLimit: 10
  },
  UCBrowser: {
    softLimit: 13.4,
    hardLimit: 13.0
  },
  SamsungInternet: {
    softLimit: 18,
    hardLimit: 4
  },
  AndroidBrowser: {
    softLimit: 4,
    hardLimit: 3
  },
  Electron: {
    softLimit: 17,
    hardLimit: 16
  }
};
var UNSUPPORTED_BROWSERS = ["OperaMini"];
var BROWSER_UPGRADE_PAGE_LINKS = {
  Chrome: "https://www.google.com/chrome/update",
  Edge: "https://support.microsoft.com/en-us/topic/microsoft-edge-update-settings-af8aaca2-1b69-4870-94fe-18822dbb7ef1#:~:text=Update%20once,Download%20and%20install%20to%20proceed",
  Firefox: "https://support.mozilla.org/en-US/kb/update-firefox-latest-release",
  IE: "https://support.microsoft.com/en-us/topic/microsoft-edge-update-settings-af8aaca2-1b69-4870-94fe-18822dbb7ef1#:~:text=Update%20once,Download%20and%20install%20to%20proceed",
  Opera: "https://help.opera.com/en/latest/crashes-and-issues/#updateBrowser",
  Safari: "https://support.apple.com/HT204416",
  WebKit: "https://support.apple.com/HT204204",
  MobileChrome: "https://play.google.com/store/apps/details?id=com.android.chrome&hl=en_IN&gl=US",
  MobileFirefox: "https://play.google.com/store/apps/details?id=org.mozilla.firefox&hl=en_IN&gl=US",
  MobileSafari: "https://support.apple.com/HT204416",
  UCBrowser: "https://play.google.com/store/apps/details?id=com.UCMobile.intl&hl=en_IN&gl=US",
  SamsungInternet: "https://play.google.com/store/apps/details?id=com.sec.android.app.sbrowser&hl=en_IN&gl=US"
};
var TYPES = {
  INAPP: "inapp",
  MOBILE: "mobile"
};

var _excluded = ["children"];
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 Callout = function Callout(_ref) {
  var children = _ref.children,
    props = _objectWithoutProperties(_ref, _excluded);
  return /*#__PURE__*/jsxRuntime.jsx("div", _objectSpread(_objectSpread({
    className: "neeto-molecules-browser-support-callout",
    "data-testid": "browser-support-callout"
  }, props), {}, {
    children: /*#__PURE__*/jsxRuntime.jsx("p", {
      className: "neeto-molecules-browser-support-callout__message",
      children: children
    })
  }));
};

var ContactUs = function ContactUs(_ref) {
  var _ref$className = _ref.className,
    className = _ref$className === void 0 ? "" : _ref$className;
  return /*#__PURE__*/jsxRuntime.jsx(reactI18next.Trans, {
    i18nKey: "neetoMolecules.browserSupport.contactUs.main",
    components: {
      button: /*#__PURE__*/jsxRuntime.jsx("button", {
        className: classnames("neeto-molecules-browser-support__link-button", className),
        onClick: function onClick() {
          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();
        }
      })
    }
  });
};

var DownloadLink = function DownloadLink(_ref) {
  var _ref$className = _ref.className,
    className = _ref$className === void 0 ? "" : _ref$className,
    link = _ref.link;
  return /*#__PURE__*/jsxRuntime.jsx(reactI18next.Trans, {
    components: {
      button: /*#__PURE__*/jsxRuntime.jsx("a", {
        className: className,
        href: link
      })
    },
    i18nKey: "neetoMolecules.browserSupport.downloadLink.main"
  });
};

var UnsupportedVersionMessage = function UnsupportedVersionMessage(_ref) {
  var browserName = _ref.browserName,
    browserVersion = _ref.browserVersion,
    _ref$className = _ref.className,
    className = _ref$className === void 0 ? "" : _ref$className,
    downloadPageLink = _ref.downloadPageLink,
    requiredMinBrowserVersion = _ref.requiredMinBrowserVersion;
  return /*#__PURE__*/jsxRuntime.jsx(reactI18next.Trans, {
    i18nKey: "neetoMolecules.browserSupport.unsupportedBrowserVersion.description",
    components: {
      downloadLink: /*#__PURE__*/jsxRuntime.jsx(DownloadLink, {
        className: className,
        link: downloadPageLink
      }),
      contactUs: /*#__PURE__*/jsxRuntime.jsx(ContactUs, {
        className: className
      })
    },
    values: {
      browserName: browserName,
      browserVersion: browserVersion,
      requiredMinBrowserVersion: requiredMinBrowserVersion === null || requiredMinBrowserVersion === void 0 ? void 0 : requiredMinBrowserVersion.softLimit
    }
  });
};
var UnsupportedVersionMessage$1 = /*#__PURE__*/React.memo(UnsupportedVersionMessage);

var PartialSupportedBrowserVersion = function PartialSupportedBrowserVersion(_ref) {
  var browserName = _ref.browserName,
    browserVersion = _ref.browserVersion,
    requiredMinBrowserVersion = _ref.requiredMinBrowserVersion,
    downloadPageLink = _ref.downloadPageLink,
    children = _ref.children;
  return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
    children: [/*#__PURE__*/jsxRuntime.jsx(Callout, {
      children: /*#__PURE__*/jsxRuntime.jsx(UnsupportedVersionMessage$1, {
        browserName: browserName,
        browserVersion: browserVersion,
        downloadPageLink: downloadPageLink,
        requiredMinBrowserVersion: requiredMinBrowserVersion
      })
    }), children]
  });
};

var UnsupportedBrowserMessage = function UnsupportedBrowserMessage(_ref) {
  var browserName = _ref.browserName,
    browserVersion = _ref.browserVersion,
    _ref$className = _ref.className,
    className = _ref$className === void 0 ? "" : _ref$className;
  return /*#__PURE__*/jsxRuntime.jsx(reactI18next.Trans, {
    components: {
      contactUs: /*#__PURE__*/jsxRuntime.jsx(ContactUs, {
        className: className
      })
    },
    i18nKey: "neetoMolecules.browserSupport.unsupportedBrowser.description",
    values: {
      browserName: browserName,
      browserVersion: browserVersion
    }
  });
};
var UnsupportedBrowserMessage$1 = /*#__PURE__*/React.memo(UnsupportedBrowserMessage);

var UnknownBrowser = function UnknownBrowser(_ref) {
  var browserName = _ref.browserName,
    browserVersion = _ref.browserVersion,
    children = _ref.children;
  return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
    children: [/*#__PURE__*/jsxRuntime.jsx(Callout, {
      children: /*#__PURE__*/jsxRuntime.jsx(UnsupportedBrowserMessage$1, {
        browserName: browserName,
        browserVersion: browserVersion
      })
    }), children]
  });
};

var UnsupportedBrowser = function UnsupportedBrowser(_ref) {
  var browserName = _ref.browserName,
    browserVersion = _ref.browserVersion;
  return /*#__PURE__*/jsxRuntime.jsx("div", {
    className: "neeto-molecules-browser-support-page",
    "data-testid": "browser-support-page",
    children: /*#__PURE__*/jsxRuntime.jsxs("div", {
      className: "neeto-molecules-browser-support-page__content",
      children: [/*#__PURE__*/jsxRuntime.jsx("h1", {
        className: "neeto-molecules-browser-support-page__header",
        children: /*#__PURE__*/jsxRuntime.jsx(reactI18next.Trans, {
          i18nKey: "neetoMolecules.browserSupport.unsupportedBrowser.title"
        })
      }), /*#__PURE__*/jsxRuntime.jsx("p", {
        className: "neeto-molecules-browser-support-page__desc",
        children: /*#__PURE__*/jsxRuntime.jsx(UnsupportedBrowserMessage$1, {
          browserName: browserName,
          browserVersion: browserVersion,
          className: "neeto-ui-text-body1"
        })
      })]
    })
  });
};
var UnsupportedBrowser$1 = /*#__PURE__*/React.memo(UnsupportedBrowser);

var UnsupportedBrowserVersion = function UnsupportedBrowserVersion(_ref) {
  var browserName = _ref.browserName,
    browserVersion = _ref.browserVersion,
    requiredMinBrowserVersion = _ref.requiredMinBrowserVersion,
    downloadPageLink = _ref.downloadPageLink;
  return /*#__PURE__*/jsxRuntime.jsx("div", {
    className: "neeto-molecules-browser-support-page",
    "data-testid": "browser-support-page",
    children: /*#__PURE__*/jsxRuntime.jsxs("div", {
      className: "neeto-molecules-browser-support-page__content",
      children: [/*#__PURE__*/jsxRuntime.jsx("h1", {
        className: "neeto-molecules-browser-support-page__header",
        children: /*#__PURE__*/jsxRuntime.jsx(reactI18next.Trans, {
          i18nKey: "neetoMolecules.browserSupport.unsupportedBrowserVersion.title"
        })
      }), /*#__PURE__*/jsxRuntime.jsx("p", {
        className: "neeto-molecules-browser-support-page__desc",
        children: /*#__PURE__*/jsxRuntime.jsx(UnsupportedVersionMessage$1, {
          browserName: browserName,
          browserVersion: browserVersion,
          downloadPageLink: downloadPageLink,
          requiredMinBrowserVersion: requiredMinBrowserVersion
        })
      })]
    })
  });
};
var UnsupportedBrowserVersion$1 = /*#__PURE__*/React.memo(UnsupportedBrowserVersion);

var convertToPlatformBrowserName = function convertToPlatformBrowserName(browserName) {
  return browserName.replace(/\s/g, "");
};
var getRequiredMinBrowserVersion = function getRequiredMinBrowserVersion(browserName, supportedBrowserVersionsMap) {
  return supportedBrowserVersionsMap[convertToPlatformBrowserName(browserName)];
};
var convertSemverToFloat = function convertSemverToFloat(browserVersion) {
  var _browserVersion$split = browserVersion.split("."),
    _browserVersion$split2 = _slicedToArray(_browserVersion$split, 2),
    majorVersion = _browserVersion$split2[0],
    minorVersion = _browserVersion$split2[1];
  return parseFloat("".concat(majorVersion, ".").concat(minorVersion)) || "";
};
var isVersionSupported = function isVersionSupported(browserVersion, requiredMinBrowserVersion) {
  var isBrowserFullySupported = browserVersion >= (requiredMinBrowserVersion === null || requiredMinBrowserVersion === void 0 ? void 0 : requiredMinBrowserVersion.softLimit);
  var isBrowserPartiallySupported = browserVersion >= (requiredMinBrowserVersion === null || requiredMinBrowserVersion === void 0 ? void 0 : requiredMinBrowserVersion.hardLimit);
  return {
    isBrowserFullySupported: isBrowserFullySupported,
    isBrowserPartiallySupported: isBrowserPartiallySupported
  };
};
var buildDownloadPageLink = function buildDownloadPageLink(browserName) {
  return BROWSER_UPGRADE_PAGE_LINKS[convertToPlatformBrowserName(browserName)];
};
var isBrowserUnsupported = function isBrowserUnsupported(browserName, unsupportedBrowsersList) {
  return unsupportedBrowsersList.includes(convertToPlatformBrowserName(browserName));
};
var isBrowserSupported = function isBrowserSupported(browserName, supportedBrowserVersionsMap) {
  return !!supportedBrowserVersionsMap[convertToPlatformBrowserName(browserName)];
};
var getBrowserStatus = function getBrowserStatus(overrides, additionalUnsupported) {
  var _UAParser$getResult = new uaParser.UAParser(navigator.userAgent).getResult(),
    browser = _UAParser$getResult.browser,
    device = _UAParser$getResult.device;
  var browserName = browser.name || i18next.t("neetoMolecules.browserSupport.unknownBrowserMsg");
  var browserVersion = convertSemverToFloat(browser.version || "");
  var browserType = browser.type;
  var deviceType = device.type;
  var supportedBrowserVersionsMap = ramda.mergeDeepLeft(overrides, DEFAULT_MINIMUM_SUPPORTED_BROWSER_VERSIONS);
  var unsupportedBrowsersList = ramda.uniq(ramda.concat(UNSUPPORTED_BROWSERS, additionalUnsupported));
  var isUnsupportedBrowser = isBrowserUnsupported(browserName, unsupportedBrowsersList);
  var isKnownBrowser = isBrowserSupported(browserName, supportedBrowserVersionsMap);
  var requiredMinBrowserVersion = isKnownBrowser ? getRequiredMinBrowserVersion(browserName, supportedBrowserVersionsMap) : null;
  var _ref = isKnownBrowser ? isVersionSupported(browserVersion, requiredMinBrowserVersion) : {
      isBrowserFullySupported: false,
      isBrowserPartiallySupported: false
    },
    isBrowserFullySupported = _ref.isBrowserFullySupported,
    isBrowserPartiallySupported = _ref.isBrowserPartiallySupported;
  var downloadPageLink = isKnownBrowser ? buildDownloadPageLink(browserName) : null;
  return {
    browserName: browserName,
    browserVersion: browserVersion,
    browserType: browserType,
    deviceType: deviceType,
    isUnsupportedBrowser: isUnsupportedBrowser,
    isKnownBrowser: isKnownBrowser,
    requiredMinBrowserVersion: requiredMinBrowserVersion,
    isBrowserFullySupported: isBrowserFullySupported,
    isBrowserPartiallySupported: isBrowserPartiallySupported,
    downloadPageLink: downloadPageLink
  };
};

var BrowserSupport = function BrowserSupport(_ref) {
  var _ref$overrides = _ref.overrides,
    overrides = _ref$overrides === void 0 ? {} : _ref$overrides,
    _ref$unsupportedBrows = _ref.unsupportedBrowsers,
    unsupportedBrowsers = _ref$unsupportedBrows === void 0 ? [] : _ref$unsupportedBrows,
    children = _ref.children;
  var _getBrowserStatus = getBrowserStatus(overrides, unsupportedBrowsers),
    browserName = _getBrowserStatus.browserName,
    browserVersion = _getBrowserStatus.browserVersion,
    browserType = _getBrowserStatus.browserType,
    deviceType = _getBrowserStatus.deviceType,
    isUnsupportedBrowser = _getBrowserStatus.isUnsupportedBrowser,
    isKnownBrowser = _getBrowserStatus.isKnownBrowser,
    isBrowserFullySupported = _getBrowserStatus.isBrowserFullySupported,
    isBrowserPartiallySupported = _getBrowserStatus.isBrowserPartiallySupported,
    requiredMinBrowserVersion = _getBrowserStatus.requiredMinBrowserVersion,
    downloadPageLink = _getBrowserStatus.downloadPageLink;
  if (browserType === TYPES.INAPP || deviceType === TYPES.MOBILE) {
    return /*#__PURE__*/jsxRuntime.jsx(jsxRuntime.Fragment, {
      children: children
    });
  }
  if (isUnsupportedBrowser) {
    return /*#__PURE__*/jsxRuntime.jsx(UnsupportedBrowser$1, {
      browserName: browserName,
      browserVersion: browserVersion
    });
  }
  if (!isKnownBrowser) {
    return /*#__PURE__*/jsxRuntime.jsx(UnknownBrowser, {
      browserName: browserName,
      browserVersion: browserVersion,
      children: children
    });
  }
  if (isBrowserFullySupported) return /*#__PURE__*/jsxRuntime.jsx(jsxRuntime.Fragment, {
    children: children
  });
  if (isBrowserPartiallySupported) {
    return /*#__PURE__*/jsxRuntime.jsx(PartialSupportedBrowserVersion, {
      browserName: browserName,
      browserVersion: browserVersion,
      downloadPageLink: downloadPageLink,
      requiredMinBrowserVersion: requiredMinBrowserVersion,
      children: children
    });
  }
  return /*#__PURE__*/jsxRuntime.jsx(UnsupportedBrowserVersion$1, {
    browserName: browserName,
    browserVersion: browserVersion,
    downloadPageLink: downloadPageLink,
    requiredMinBrowserVersion: requiredMinBrowserVersion
  });
};

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