"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.parseItems = void 0;
var _locale = require("@mirai/locale");
var _parseRate = require("./parseRate");
var _Core = require("../../../../../Core.constants");
var _legacy = require("../../helpers/legacy");
const parseItems = function () {
  let {
    finder: {
      calendar = [],
      place: {
        id: [hotelId] = []
      } = {},
      promocode
    } = {},
    hotelInfo = {},
    id: instanceId,
    reservedExtras = {},
    reservedRooms = [],
    tracking: {
      bookingValues: {
        checkin,
        checkout,
        coupon
      } = {}
    } = {},
    type
  } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  const {
    currency: hotelCurrency,
    propertyName
  } = hotelInfo;
  const {
    days
  } = (0, _locale.dateDiff)(...(calendar.length ? calendar : [(0, _locale.parseDate)(checkin), (0, _locale.parseDate)(checkout)]));
  const rooms = reservedRooms.map(function () {
    let {
      averagePriceWithoutTaxes: totalPriceWithoutTaxes,
      defaultBoardDescription: boardName,
      numRoomsToReserve = 1,
      rateId: id,
      rateName,
      roomTypeName
    } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
    return (0, _parseRate.parseRate)({
      hotelId: type === _Core.TYPE.HOTEL ? instanceId : hotelId,
      hotelInfo,
      id,
      promocode: promocode || coupon || '',
      rate: {
        boardName,
        rateName,
        roomTypeName,
        totalPriceWithoutTaxes
      },
      quantity: numRoomsToReserve * days
    });
  });
  const extras = Object.keys(reservedExtras).map(key => reservedExtras[key]).map(_ref => {
    let {
      id,
      name,
      multiplierPrice,
      priceWithoutTaxes,
      type
    } = _ref;
    return {
      coupon: promocode || coupon || '',
      currency: hotelCurrency.code,
      item_brand: propertyName,
      item_category: 'Extra',
      item_category2: type,
      item_name: name,
      price: (0, _legacy.formatPrice)(priceWithoutTaxes, hotelCurrency),
      quantity: multiplierPrice,
      item_id: "".concat(id)
    };
  });
  return [...rooms, ...extras];
};
exports.parseItems = parseItems;
//# sourceMappingURL=parseItems.js.map