function _extends() { _extends = Object.assign ? Object.assign.bind() : 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); }
import React, { useEffect, forwardRef } from 'react';
import { createPortal } from 'react-dom';
import PreviewMain from "./../PreviewMain";

// 内库使用-start
import SelectModal from "./../../Modal/NavBarModal";
// 内库使用-end

/* 测试使用-start
import { Modal } from 'seedsui-react'
const SelectModal = Modal.NavBarModal
测试使用-end */

var PreviewModal = /*#__PURE__*/forwardRef(function (_ref, ref) {
  var visible = _ref.visible,
    type = _ref.type,
    current = _ref.current,
    onVisibleChange = _ref.onVisibleChange,
    _ref$allowChoose = _ref.allowChoose,
    allowChoose = _ref$allowChoose === void 0 ? false : _ref$allowChoose,
    _ref$allowClear = _ref.allowClear,
    allowClear = _ref$allowClear === void 0 ? false : _ref$allowClear,
    modal = _ref.modal,
    portal = _ref.portal,
    count = _ref.count,
    _ref$sourceType = _ref.sourceType,
    sourceType = _ref$sourceType === void 0 ? ['album', 'camera'] : _ref$sourceType,
    _ref$sizeType = _ref.sizeType,
    sizeType = _ref$sizeType === void 0 ? ['compressed'] : _ref$sizeType,
    maxWidth = _ref.maxWidth,
    list = _ref.list,
    onBeforeChoose = _ref.onBeforeChoose,
    onChoose = _ref.onChoose,
    onFileChange = _ref.onFileChange,
    onUpload = _ref.onUpload,
    onChange = _ref.onChange,
    modalProps = _ref.modalProps,
    mainProps = _ref.mainProps;
  // 在预览页面, 列表被删除完成时, 隐藏modal
  useEffect(function () {
    if (!list || !list.length || !list[0].src) {
      if (visible) {
        onVisibleChange && onVisibleChange(false);
      }
    }
    // eslint-disable-next-line
  }, [list]);

  // 图片单击隐藏, 视频单击无反应, 显示不能触发
  function handleVisibleChange(visible) {
    if (!visible) {
      if (onVisibleChange) onVisibleChange(false);
    }
  }
  if (modal === 'page') {
    return /*#__PURE__*/createPortal( /*#__PURE__*/React.createElement(PreviewMain, _extends({
      safeArea: true
    }, mainProps, {
      ref: ref,
      visible: visible,
      type: type,
      list: list,
      current: current
      // Style
      ,
      className: "image-preview-main-page",
      allowClose: true,
      allowChoose: allowChoose,
      allowClear: allowClear
      // Config
      ,
      count: count,
      sourceType: sourceType,
      sizeType: sizeType,
      maxWidth: maxWidth
      // Events
      ,
      onBeforeChoose: onBeforeChoose,
      onChoose: onChoose,
      onFileChange: onFileChange,
      onUpload: onUpload,
      onChange: onChange,
      onVisibleChange: onVisibleChange
    })), portal || document.getElementById('root') || document.body);
  }
  return /*#__PURE__*/React.createElement(SelectModal, _extends({}, modalProps, {
    visible: visible,
    animation: "slideUp",
    className: "image-preview-modal",
    onVisibleChange: handleVisibleChange,
    ok: false
  }), /*#__PURE__*/React.createElement(PreviewMain, _extends({}, mainProps, {
    ref: ref,
    visible: visible,
    type: type,
    list: list,
    current: current
    // Style
    ,
    allowClose: false,
    allowChoose: allowChoose,
    allowClear: allowClear
    // Config
    ,
    count: count,
    sourceType: sourceType,
    sizeType: sizeType,
    maxWidth: maxWidth
    // Events
    ,
    onBeforeChoose: onBeforeChoose,
    onChoose: onChoose,
    onFileChange: onFileChange,
    onUpload: onUpload,
    onChange: onChange,
    onVisibleChange: onVisibleChange
  })));
});
export default PreviewModal;