"use strict";

require("core-js/modules/es.weak-map.js");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.CoalitionCardAwardsDetail = void 0;
require("core-js/modules/web.dom-collections.iterator.js");
require("core-js/modules/es.symbol.description.js");
var _react = _interopRequireWildcard(require("react"));
var _CoalitionProgressBar = require("../CoalitionProgressBar");
var _svgs = require("../../svgs");
var _utils = require("../../utils");
require("./CoalitionCardAwardsDetail.css");
var _CoalitionCollapsible = require("../CoalitionCollapsible");
var _CoalitionGtm = require("./../CoalitionGtm");
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
const CoalitionCardAwardsDetail = _ref => {
  let {
    gtmId = null,
    card,
    balance,
    origin
  } = _ref;
  const promoType = "premios";
  const redeemable = balance >= card.pay_in_points;
  const [productImg, solveImg] = (0, _react.useState)();
  (0, _react.useEffect)(() => {
    const testImg = url => {
      let i = new Image();
      i.onload = () => solveImg((0, _utils.getImg)(url));
      i.onerror = () => solveImg( /*#__PURE__*/_react.default.createElement(_svgs.ProductSvgNotFound, null));
      i.src = url;
    };
    testImg(card.image);
    (() => {
      const {
        general,
        benefit
      } = (0, _CoalitionGtm.cardTag)(card, origin, promoType);
      (0, _CoalitionGtm.sendTagNew)(gtmId, general, benefit, "card");
    })();
  }, [card, gtmId, origin]);
  return /*#__PURE__*/_react.default.createElement("div", {
    className: "coalition-card-available-prizes-detail"
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: "coalition-card-available-prizes-detail-main"
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: "coalition-card-available-prizes-detail-product"
  }, productImg), /*#__PURE__*/_react.default.createElement("div", {
    className: "coalition-card-available-prizes-detail-specs"
  }, /*#__PURE__*/_react.default.createElement("h3", {
    className: "coalition-card-available-prizes-detail-title"
  }, card.title), redeemable ? /*#__PURE__*/_react.default.createElement(Ready, null) : null, /*#__PURE__*/_react.default.createElement("h4", {
    className: "coalition-card-available-prizes-detail-description"
  }, card.description), /*#__PURE__*/_react.default.createElement(InProgress, {
    required: card.pay_in_points,
    balance: balance
  }))), /*#__PURE__*/_react.default.createElement(_CoalitionCollapsible.CoalitionCollapsible, {
    terms: card.terms_and_conditions,
    sendGtm: opened => {
      if (!opened) return;
      const {
        general,
        benefit
      } = (0, _CoalitionGtm.detailTag)(card, origin, promoType);
      (0, _CoalitionGtm.sendTagNew)(gtmId, general, benefit, "detail");
    }
  }));
};
exports.CoalitionCardAwardsDetail = CoalitionCardAwardsDetail;
const InProgress = _ref2 => {
  let {
    required,
    balance
  } = _ref2;
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("div", {
    className: "coalition-card-available-prizes-detail-progress"
  }, /*#__PURE__*/_react.default.createElement(_CoalitionProgressBar.CoalitionProgressBar, {
    current: balance,
    max: required,
    changeColor: true
  })), /*#__PURE__*/_react.default.createElement("h6", {
    className: "coalition-card-available-prizes-detail-progress-text"
  }, "Por ", required, " puntos"));
};
const Ready = () => {
  return /*#__PURE__*/_react.default.createElement("div", {
    className: "coalition-card-available-prizes-detail-ready"
  }, /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement(_svgs.GiftIcon, null)), /*#__PURE__*/_react.default.createElement("h4", null, "\xA1Ya puedes cambiar tu premio!"));
};