"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getForwarderUrl = void 0;
var _locale = require("@mirai/locale");
var _Core = require("../../../Core.constants");
var _helpers = require("../../helpers");
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), !0).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; }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
const getForwarderUrl = function () {
  let {
    calendar: [checkIn, checkOut] = [],
    occupation = [],
    place: {
      id: ids = [],
      isHotel,
      value
    } = {},
    promocode: clientCode = '',
    locale = _locale.DEFAULT_LOCALE,
    currency = _locale.DEFAULT_CURRENCY,
    forwarder: {
      rates: url
    } = {},
    store: {
      hotel: {
        id
      } = {},
      id: idchain,
      origin: {
        commissionCode: hsri = ''
      } = {},
      urlParams: {
        miraiId,
        uid
      } = {}
    } = {},
    type
  } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  const dateCheckIn = checkIn instanceof Date ? checkIn : (0, _locale.parseDate)(checkIn);
  const dateCheckOut = checkOut instanceof Date ? checkOut : (0, _locale.parseDate)(checkOut);
  const hotelId = ids.length === 1 ? ids[0] : id;
  const params = _objectSpread(_objectSpread(_objectSpread({
    chainSelectorValue: value,
    checkin: (0, _locale.dateFormat)(dateCheckIn, {
      format: 'DD/MM/YYYY'
    })
  }, value && !isHotel ? {
    hotelIds: ids.join(',')
  } : {
    idtokenprovider: hotelId,
    currency
  }), type === _Core.TYPE.CHAIN ? {
    idchain
  } : undefined), {}, {
    clientCode,
    hsri,
    lang: locale.split('-')[0],
    miraiId,
    nights: (0, _locale.dateDiff)(dateCheckIn, dateCheckOut).days,
    parties: (0, _helpers.parseToParties)(occupation),
    type,
    uid
  });
  return "".concat(url).concat((0, _helpers.toUrlParams)(params));
};
exports.getForwarderUrl = getForwarderUrl;
//# sourceMappingURL=getForwarderUrl.js.map