"use strict";

require("core-js/modules/es.weak-map.js");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.AwardsBlock = 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 _CoalitionSection = require("../CoalitionSection");
var _CoalitionModal = require("..//CoalitionModal");
var _CoalitionCardAwards = require("../CoalitionCardAwards");
var _CoalitionCardAwardsDetail = require("../CoalitionCardAwardsDetail");
var _svgs = require("../../svgs");
var _EmptyBlock = require("./EmptyBlock");
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; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
class AwardsBlock extends _react.Component {
  constructor() {
    super(...arguments);
    _defineProperty(this, "state", {
      isShown: false,
      activeCard: null
    });
    _defineProperty(this, "toggleModal", cardId => {
      this.setState({
        isShown: Boolean(cardId),
        activeCard: this.getCardDetail(cardId)
      });
      this.toggleScrollLock();
    });
    _defineProperty(this, "onClickOutside", e => this.modal && this.modal.contains(e.target) ? null : this.toggleModal());
    _defineProperty(this, "onKeyDown", e => e.keyCode === 27 ? this.toggleModal() : null);
    _defineProperty(this, "toggleScrollLock", () => document.querySelector("html").classList.toggle("modal-scroll-lock"));
    _defineProperty(this, "getCardDetail", cardId => this.props.awards.find(award => award.id === cardId));
  }
  render() {
    return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, !this.props.awards || this.props.awards.length === 0 ? /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_EmptyBlock.EmptyBlock, {
      title: "Premios disponibles",
      description: "Muy pronto podrás cambiar tus puntos por tus productos favoritos",
      desktop: /*#__PURE__*/_react.default.createElement(_svgs.EmptyAwards, {
        desktop: true
      }),
      mobile: /*#__PURE__*/_react.default.createElement(_svgs.EmptyAwards, null),
      svgLeft: true
    })) : /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_CoalitionSection.CoalitionSection, {
      title: "Premios disponibles",
      subtitle: "Cambia tus puntos por productos"
    }, this.props.awards.map((i, k) => /*#__PURE__*/_react.default.createElement(_CoalitionCardAwards.CoalitionCardAwards, {
      key: k,
      id: i.id,
      product: i.image,
      title: i.title,
      pointsRequired: i.pay_in_points,
      points: this.props.balance,
      showModal: cardId => this.toggleModal(cardId)
    }))), this.state.isShown ? /*#__PURE__*/_react.default.createElement(_CoalitionModal.CoalitionModal, {
      modalRef: n => this.modal = n,
      closeModal: () => this.toggleModal(),
      onKeyDown: this.onKeyDown,
      onClickOutside: this.onClickOutside,
      title: "Todo sobre tus premios",
      footer: this.state.activeCard.valid_until
    }, /*#__PURE__*/_react.default.createElement(_CoalitionCardAwardsDetail.CoalitionCardAwardsDetail, {
      card: this.state.activeCard,
      balance: this.props.balance,
      origin: "home",
      gtmId: this.props.gtmId
    })) : null));
  }
}
exports.AwardsBlock = AwardsBlock;