"use strict";

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

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

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

var _PreviewComponent = _interopRequireDefault(require("../Image/PreviewComponent"));

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

const _excluded = ["medias"];

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); }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

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

var _default = props => {
  // PROPS
  const {
    medias = []
  } = props,
        rest = _objectWithoutPropertiesLoose(props, _excluded);
  /**
   * 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
   */


  if (medias.length > 0) {
    return /*#__PURE__*/_react.default.createElement(Root, _extends({
      medias: medias
    }, rest, {
      onClick: handleClickOnPdf
    }));
  }

  return null;
};

exports.default = _default;