"use strict";

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

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

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

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

var _Document = _interopRequireDefault(require("../Media/Document"));

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

var _Link = _interopRequireDefault(require("../Media/Link"));

var _Share = _interopRequireDefault(require("../Media/Share"));

const _excluded = ["medias", "mediaObjectTypes"];

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 = 'SCMedias';
const Root = (0, _styles.styled)(_Box.default, {
  name: PREFIX,
  slot: 'Root',
  overridesResolver: (props, styles) => styles.root
})(({
  theme
}) => ({
  position: 'relative',
  marginTop: 0,
  marginBottom: theme.spacing(),
  marginLeft: -2,
  marginRight: -2
}));

var _default = props => {
  //PROPS
  const {
    medias,
    mediaObjectTypes = [_Image.default, _Document.default, _Link.default, _Share.default]
  } = props,
        rest = _objectWithoutPropertiesLoose(props, _excluded);

  if (!medias.length) {
    /**
     * Feed without any medias:
     * don't render anything
     */
    return null;
  }
  /**
   * Renders list of media preview
   * The adornment prop is used to insert the controls
   * for re-editing the media at the top of the group of elements
   */


  return /*#__PURE__*/_react.default.createElement(Root, rest, mediaObjectTypes.map(mediaObject => {
    const {
      previewProps = {}
    } = mediaObject;
    return /*#__PURE__*/_react.default.createElement("div", {
      key: mediaObject.name
    }, /*#__PURE__*/_react.default.createElement(mediaObject.previewComponent, _extends({
      medias: medias.filter(mediaObject.filter)
    }, previewProps)));
  }));
};

exports.default = _default;