"use strict";

require("core-js/modules/es.weak-map.js");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.CoalitionBanner = void 0;
require("core-js/modules/web.dom-collections.iterator.js");
var _react = _interopRequireWildcard(require("react"));
var _utils = require("../../utils");
var _svgs = require("../../svgs");
require("./CoalitionBanner.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 CoalitionBanner = (item, index) => {
  const [imgDesktop, solveDesktop] = (0, _react.useState)();
  const [imgMobile, solveMobile] = (0, _react.useState)();
  (0, _react.useEffect)(() => {
    const testImgDesktop = url => {
      const klass = "coalition-banner-img coalition-banner-img-desktop";
      let i = new Image();
      i.onload = () => solveDesktop((0, _utils.getImg)(url, klass));
      i.onerror = () => solveDesktop( /*#__PURE__*/_react.default.createElement(NotUsable, {
        classes: klass
      }));
      i.src = url;
    };
    const testImgMobile = url => {
      const klass = "coalition-banner-img coalition-banner-img-mobile";
      let i = new Image();
      i.onload = () => solveMobile((0, _utils.getImg)(url, klass));
      i.onerror = () => solveMobile( /*#__PURE__*/_react.default.createElement(NotUsable, {
        classes: klass
      }));
      i.src = url;
    };
    testImgDesktop(item.desktop_image);
    testImgMobile(item.mobile_image);
  }, [item]);
  const NotUsable = _ref => {
    let {
      classes
    } = _ref;
    return /*#__PURE__*/_react.default.createElement("div", {
      className: "".concat(classes)
    }, /*#__PURE__*/_react.default.createElement(_svgs.ProductSvgNotFound, null));
  };
  return /*#__PURE__*/_react.default.createElement("div", {
    key: "".concat(index, "_").concat(item.id),
    className: "coalition-banner-item"
  }, /*#__PURE__*/_react.default.createElement("a", {
    href: item.url,
    target: "_blank",
    rel: "noopener noreferrer",
    className: "coalition-banner-link"
  }, imgDesktop, imgMobile));
};
exports.CoalitionBanner = CoalitionBanner;