"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.sendTagNew = exports.detailTag = exports.cardTag = void 0;
var _utils = require("../../utils");
const sendTagNew = (gtmId, general, benefit, origin) => {
  if (!gtmId) return;
  const body = {
    event: "".concat(gtmId, "-click-").concat(origin),
    eventProps: {
      dataLayer: {
        general,
        benefit
      }
    }
  };
  if (!window.dataLayer) window.dataLayer = [];
  window.dataLayer.push(body);
  console.log(gtmId, body, window.dataLayer);
};
exports.sendTagNew = sendTagNew;
const cardTag = (card, origin, type) => {
  const general = createGeneral(card);
  const benefit = createBenefit(card, origin, type);
  return {
    general,
    benefit
  };
};
exports.cardTag = cardTag;
const detailTag = (card, origin, type) => {
  const general = createGeneral(card, true);
  const benefit = createBenefit(card, origin, type);
  return {
    general,
    benefit
  };
};
exports.detailTag = detailTag;
const createGeneral = function createGeneral(card) {
  var _card$click_id, _card$user_id, _card$session_id, _card$hash_id, _card$device_id, _card$source, _card$medium, _card$campaign;
  let detail = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  let e = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  let res = {
    pwa_ally: "oxxo_premia",
    click_id: (_card$click_id = card.click_id) !== null && _card$click_id !== void 0 ? _card$click_id : e,
    user_id: (_card$user_id = card.user_id) !== null && _card$user_id !== void 0 ? _card$user_id : e,
    session_id: (_card$session_id = card.session_id) !== null && _card$session_id !== void 0 ? _card$session_id : e,
    hash_id: (_card$hash_id = card.hash_id) !== null && _card$hash_id !== void 0 ? _card$hash_id : e,
    device_type: (0, _utils.isPortable)() ? "mobile" : "desktop",
    timestamp: Date.now(),
    device_id: (_card$device_id = card.device_id) !== null && _card$device_id !== void 0 ? _card$device_id : e,
    source: (_card$source = card.source) !== null && _card$source !== void 0 ? _card$source : e,
    medium: (_card$medium = card.medium) !== null && _card$medium !== void 0 ? _card$medium : e,
    campaign: (_card$campaign = card.campaign) !== null && _card$campaign !== void 0 ? _card$campaign : e
  };
  if (detail) res.drop_down_clicked = "terminos_y_condiciones";
  return res;
};
const createBenefit = function createBenefit(card, origin, type) {
  var _card$sponsor_name, _card$sponsor_id, _card$product_id, _card$position;
  let e = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
  return {
    benefit_name: card.title,
    benefit_type: type,
    benefit_id: card.id,
    ally: (_card$sponsor_name = card.sponsor_name) !== null && _card$sponsor_name !== void 0 ? _card$sponsor_name : e,
    ally_id: (_card$sponsor_id = card.sponsor_id) !== null && _card$sponsor_id !== void 0 ? _card$sponsor_id : e,
    product_id: (_card$product_id = card.product_id) !== null && _card$product_id !== void 0 ? _card$product_id : e,
    screen: origin,
    benefit_position: (_card$position = card.position) !== null && _card$position !== void 0 ? _card$position : e,
    benefit_page_number: 1,
    benefit_status: "launched",
    benefit_percentage_complete: drawableBalance(card.balance, card.required_balance, card.available_to_redeem)
  };
};
const drawableBalance = function drawableBalance() {
  let balance = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
  let needed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  let ready = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
  const totalBalance = balance += ready ? ready * needed : 0;
  return "".concat(totalBalance, "/").concat(needed);
};