"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getPrivacyPolicy = void 0;
var _Chat = require("../Chat/Chat.constants");
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
const getFeatureName = feature => (feature === null || feature === void 0 ? void 0 : feature.legalName) || (feature === null || feature === void 0 ? void 0 : feature.name);
const getFeatureUrl = function (feature) {
  var _Object$entries$find;
  let locale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
  const _ref = feature || {},
    privacy = _ref.privacy;
  if (!privacy) return undefined;
  const _locale$split = locale.split('-'),
    _locale$split2 = _slicedToArray(_locale$split, 1),
    language = _locale$split2[0];
  return privacy[locale] || ((_Object$entries$find = Object.entries(privacy).find(_ref2 => {
    let _ref3 = _slicedToArray(_ref2, 1),
      key = _ref3[0];
    return key.startsWith("".concat(language, "-"));
  })) === null || _Object$entries$find === void 0 ? void 0 : _Object$entries$find[1]) || privacy[_Chat.PRIVACY_FALLBACK_LOCALE];
};
const getPrivacyPolicy = function () {
  let _ref4 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
    chainId = _ref4.chainId,
    _ref4$features = _ref4.features,
    features = _ref4$features === void 0 ? {} : _ref4$features,
    genericName = _ref4.genericName,
    hotelId = _ref4.hotelId,
    isChain = _ref4.isChain,
    language = _ref4.language,
    locale = _ref4.locale;
  const feature = features === null || features === void 0 ? void 0 : features[hotelId];
  const defaultUrl = "".concat(_Chat.DEFAULT_PRIVACY_URL, "?idtokenprovider=").concat(_Chat.DEFAULT_PRIVACY_ID).concat(language ? "&language=".concat(language) : '');
  if (isChain) {
    const chainFeature = features === null || features === void 0 ? void 0 : features[chainId];
    const chainName = chainFeature === null || chainFeature === void 0 ? void 0 : chainFeature.legalName;
    const chainUrl = getFeatureUrl(chainFeature, locale);
    if (chainName || chainUrl) return {
      name: chainName || genericName,
      url: chainUrl || defaultUrl
    };
    const hotelFeature = Object.values(features).find(item => (item === null || item === void 0 ? void 0 : item.legalName) && getFeatureUrl(item, locale));
    if (hotelFeature) return {
      name: hotelFeature.legalName,
      url: getFeatureUrl(hotelFeature, locale)
    };
    return {
      name: genericName,
      url: defaultUrl
    };
  }
  const activeUrl = getFeatureUrl(feature, locale);
  if (activeUrl) return {
    name: getFeatureName(feature) || genericName,
    url: activeUrl
  };
  return {
    name: getFeatureName(feature) || genericName,
    url: defaultUrl
  };
};
exports.getPrivacyPolicy = getPrivacyPolicy;
//# sourceMappingURL=getPrivacyPolicy.js.map