var __assign = this && this.__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);
};

import { jsx as _jsx } from "react/jsx-runtime";
import React from 'react';
import map from 'lodash/map';
import Icon from "../../../icon";
import "./media-list.css";
import videoCamLight from "../../asserts/video-cam-light.svg";
import videoCamDark from "../../asserts/video-cam-dark.svg";
import pdfSvg from "../../asserts/pdf.svg";
import { getTheme } from "../../../style/themes";
import openMediaPreviewDialog from "../../../preview-media";
import { imgTypes, videoTypes, pdfTypes } from "../../../preview-media/PreviewMedia";

var Thumbnail = function Thumbnail(props) {
  var index = props.index,
      prefixCls = props.prefixCls,
      onClick = props.onClick,
      img = props.img;
  return _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(Icon, {
      icon: "maximize",
      size: 40
    }, void 0)
  }), void 0);
};

var MediaList = /*#__PURE__*/React.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;
    openMediaPreviewDialog({
      getPreviewPopupContainer: getPreviewPopupContainer,
      list: list,
      defaultSelectIndex: numericImgIndex
    });
  };

  return _jsx("div", __assign({
    className: prefixCls + "-media-list"
  }, {
    children: map(list, function (item, index) {
      var type = item.type;
      var theme = getTheme() || 'dark';
      var img = videoCamDark;

      if (imgTypes.includes(type)) {
        img = item.value;
      } else if (videoTypes.includes(type)) {
        img = theme === 'dark' ? videoCamDark : videoCamLight;
      } else if (pdfTypes.includes(type)) {
        img = pdfSvg;
      }

      return _jsx(Thumbnail, {
        type: type,
        index: index,
        prefixCls: prefixCls,
        onClick: handlePreview,
        img: img
      }, index);
    })
  }), void 0);
});
export default MediaList;

