"use strict";

require("core-js/modules/es.weak-map.js");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.CoalitionCardStamps = void 0;
require("core-js/modules/web.dom-collections.iterator.js");
var _react = _interopRequireWildcard(require("react"));
var _svgs = require("./../../svgs");
var _utils = require("../../utils");
var _CoalitionStampsProgress = require("../CoalitionStampsProgress");
require("./CoalitionCardStamps.css");
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 CoalitionCardStamps = _ref => {
  let {
    id,
    logo,
    product,
    title,
    used,
    needed,
    availableToRedeem,
    showModal,
    buttonRef
  } = _ref;
  const ready = availableToRedeem >= 1 || used >= needed;
  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(product);
  }, [product]);
  return /*#__PURE__*/_react.default.createElement("div", {
    className: "coalition-card-stamps",
    ref: buttonRef,
    onClick: () => showModal(id)
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: "coalition-card-stamps-main ".concat(ready ? "b-success" : ""),
    style: {
      borderBottom: "none"
    }
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: "coalition-card-stamps-main-product"
  }, productImg), /*#__PURE__*/_react.default.createElement("div", {
    className: "coalition-card-stamps-main-title"
  }, /*#__PURE__*/_react.default.createElement("span", null, (0, _utils.fixContent)(title, 48)))), /*#__PURE__*/_react.default.createElement("div", {
    className: "coalition-card-stamps-footer ".concat(ready ? "b-success bg-success" : ""),
    style: {
      borderTop: "none"
    }
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: "static-space"
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: "coalition-card-stamps-footer-logo"
  }, /*#__PURE__*/_react.default.createElement("img", {
    src: logo,
    alt: "logo"
  })), /*#__PURE__*/_react.default.createElement(_svgs.Splitter, null)), /*#__PURE__*/_react.default.createElement(Progress, {
    used: used,
    needed: needed,
    ready: ready
  })));
};
exports.CoalitionCardStamps = CoalitionCardStamps;
const Progress = _ref2 => {
  let {
    used,
    needed,
    ready
  } = _ref2;
  const balance = "".concat(used, " de ").concat(needed);
  const color = ready ? "#FFFFFF" : "#101010";
  return /*#__PURE__*/_react.default.createElement("div", {
    className: "dinamyc-space"
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: "coalition-card-stamps-footer-dots"
  }, /*#__PURE__*/_react.default.createElement(_CoalitionStampsProgress.CoalitionStampsProgress, {
    used: used,
    needed: needed
  })), /*#__PURE__*/_react.default.createElement("div", {
    className: "coalition-card-stamps-footer-counter",
    style: {
      color: color
    }
  }, balance));
};