"use strict";

exports.__esModule = true;
exports.default = void 0;

var _react = _interopRequireDefault(require("react"));

var _styles = require("@mui/material/styles");

var _reactLazyload = _interopRequireDefault(require("react-lazyload"));

var _CentralProgress = _interopRequireDefault(require("../../CentralProgress"));

var _Box = _interopRequireDefault(require("@mui/material/Box"));

var _Image = _interopRequireDefault(require("../Image"));

var _ZoomIn = _interopRequireDefault(require("@mui/icons-material/ZoomIn"));

var _Media = require("../../../constants/Media");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

const PREFIX = 'SCPreviewMediaDocument';
const Root = (0, _styles.styled)(_Box.default, {
  name: PREFIX,
  slot: 'Root',
  overridesResolver: (props, styles) => styles.root
})(({
  theme
}) => ({}));

var _default = props => {
  // PROPS
  const {
    medias = [],
    GridImageProps = {},
    adornment = null
  } = props;
  /**
   * Handles click on pdf
   * @param doc
   */

  const handleClickOnPdf = doc => {
    if (doc && doc.index >= _Media.MAX_GRID_IMAGES - 1) {// Open the post/discussion
      // history.push(url(threadType, {id: thread.id, slug: thread.slug})());
    } else if (doc.src && doc.src.url) {
      // Open file in target blank
      let win = window.open(doc.src.url, '_blank');
      win.focus();
    }
  };
  /**
   * Renders document preview
   */


  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, medias.length > 0 && /*#__PURE__*/_react.default.createElement(_reactLazyload.default, {
    height: 360,
    placeholder: /*#__PURE__*/_react.default.createElement(_CentralProgress.default, {
      size: 20
    })
  }, /*#__PURE__*/_react.default.createElement(Root, null, adornment, /*#__PURE__*/_react.default.createElement(_Image.default.previewComponent, _extends({
    medias: medias,
    title: true,
    renderOverlay: () => /*#__PURE__*/_react.default.createElement(_ZoomIn.default, null),
    onClickEach: handleClickOnPdf
  }, GridImageProps, {
    adornment: adornment
  })))));
};

exports.default = _default;