"use strict";

var __assign = void 0 && (void 0).__assign || function () {
  __assign = Object.assign || function (t) {
    for (var s, i = 1, n = arguments.length; i < n; i++) {
      s = arguments[i];

      for (var p in s) {
        if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
      }
    }

    return t;
  };

  return __assign.apply(this, arguments);
};

var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
  return mod && mod.__esModule ? mod : {
    "default": mod
  };
};

Object.defineProperty(exports, "__esModule", {
  value: true
});

var jsx_runtime_1 = require("react/jsx-runtime");

var react_1 = __importDefault(require("react"));

var map_1 = __importDefault(require("lodash/map"));

var icon_1 = __importDefault(require("../../../icon"));

require("./media-list.css");

var video_cam_light_svg_1 = __importDefault(require("../../asserts/video-cam-light.svg"));

var video_cam_dark_svg_1 = __importDefault(require("../../asserts/video-cam-dark.svg"));

var themes_1 = require("../../../style/themes");

var preview_media_1 = __importDefault(require("../../../preview-media"));

var PreviewMedia_1 = require("../../../preview-media/PreviewMedia");

var Thumbnail = function Thumbnail(props) {
  var index = props.index,
      prefixCls = props.prefixCls,
      onClick = props.onClick,
      img = props.img;
  return jsx_runtime_1.jsx("div", __assign({
    "data-index": index,
    className: prefixCls + "-media-list-item",
    style: {
      backgroundPosition: 'center',
      backgroundSize: 'contain',
      backgroundImage: "url(" + img + ")",
      backgroundRepeat: 'no-repeat'
    },
    onClick: onClick
  }, {
    children: jsx_runtime_1.jsx(icon_1["default"], {
      icon: "maximize",
      size: 40
    }, void 0)
  }), void 0);
};

var MediaList = react_1["default"].memo(function (props) {
  var _a = props.list,
      list = _a === void 0 ? [] : _a,
      prefixCls = props.prefixCls,
      getPreviewPopupContainer = props.getPreviewPopupContainer; // eslint-disable-next-line no-console

  console.log(getPreviewPopupContainer, 'getPreviewPopupContainer');

  var handlePreview = function handlePreview(e) {
    var _a;

    var imgIndex = (_a = e.currentTarget) === null || _a === void 0 ? void 0 : _a.dataset.index;
    var v = Number.parseInt(imgIndex || '0', 10);
    var numericImgIndex = isNaN(v) ? 0 : v;
    preview_media_1["default"]({
      getPreviewPopupContainer: getPreviewPopupContainer,
      list: list,
      defaultSelectIndex: numericImgIndex
    });
  };

  return jsx_runtime_1.jsx("div", __assign({
    className: prefixCls + "-media-list"
  }, {
    children: map_1["default"](list, function (item, index) {
      var type = item.type;
      var theme = themes_1.getTheme() || 'dark';
      var img = video_cam_dark_svg_1["default"];

      if (PreviewMedia_1.imgTypes.includes(type)) {
        img = item.value;
      } else if (PreviewMedia_1.videoTypes.includes(type)) {
        img = theme === 'dark' ? video_cam_dark_svg_1["default"] : video_cam_light_svg_1["default"];
      }

      return jsx_runtime_1.jsx(Thumbnail, {
        type: type,
        index: index,
        prefixCls: prefixCls,
        onClick: handlePreview,
        img: img
      }, index);
    })
  }), void 0);
});
exports["default"] = MediaList;

