var _excluded = ["safeArea", "visible", "onVisibleChange", "portal", "animation", "maskProps", "title", "titleProps", "ok", "onOk", "okProps", "cancel", "onCancel", "cancelProps", "maskClosable", "children"];
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); }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
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; }
import React, { forwardRef, useRef, useImperativeHandle, useEffect } from 'react';
import { createPortal } from 'react-dom';
import NavBar from "./../NavBar";

// 内库使用-start
import DOMUtil from "./../../../utils/DOMUtil";
import SafeArea from "./../../SafeArea";
// 内库使用-end

/* 测试使用-start
import { DOMUtil, SafeArea } from 'seedsui-react'
测试使用-end */

// NavBarModal
var NavBarModal = /*#__PURE__*/forwardRef(function (_ref, ref) {
  var safeArea = _ref.safeArea,
    visible = _ref.visible,
    onVisibleChange = _ref.onVisibleChange,
    portal = _ref.portal,
    _ref$animation = _ref.animation,
    animation = _ref$animation === void 0 ? 'slideUp' : _ref$animation,
    maskProps = _ref.maskProps,
    title = _ref.title,
    titleProps = _ref.titleProps,
    ok = _ref.ok,
    onOk = _ref.onOk,
    okProps = _ref.okProps,
    cancel = _ref.cancel,
    onCancel = _ref.onCancel,
    cancelProps = _ref.cancelProps,
    _ref$maskClosable = _ref.maskClosable,
    maskClosable = _ref$maskClosable === void 0 ? true : _ref$maskClosable,
    children = _ref.children,
    props = _objectWithoutProperties(_ref, _excluded);
  // 节点
  var modalRef = useRef(null);
  useImperativeHandle(ref, function () {
    return {
      rootDOM: modalRef === null || modalRef === void 0 ? void 0 : modalRef.current,
      getRootDOM: function getRootDOM() {
        return modalRef.current;
      }
    };
  });
  useEffect(function () {
    if (visible) {
      if (onVisibleChange) onVisibleChange(visible);
    }
    // eslint-disable-next-line
  }, [visible]);

  // 事件
  function handleCancelClick(e) {
    onCancel && onCancel(e);
    onVisibleChange && onVisibleChange(false);
  }
  function handleMaskClick(e) {
    e.stopPropagation();
    if (!e.target.classList.contains('mask')) return;
    if (maskProps !== null && maskProps !== void 0 && maskProps.onClick) maskProps.onClick(e);
    if (maskClosable) {
      onVisibleChange && onVisibleChange(false);
    }
  }
  var Node = /*#__PURE__*/React.createElement("div", _extends({}, maskProps, {
    className: "mask modal-navbarmodal-mask".concat(maskProps !== null && maskProps !== void 0 && maskProps.className ? ' ' + maskProps.className : '').concat(visible ? ' active' : ''),
    onClick: handleMaskClick,
    ref: modalRef
  }), /*#__PURE__*/React.createElement("div", _extends({
    "data-animation": animation,
    onClick: function onClick(e) {
      e.stopPropagation();
    }
  }, props, {
    className: DOMUtil.classNames('modal-animation', 'modal-navbarmodal', SafeArea.getSafeAreaClassName(safeArea), props.className, visible ? ' active' : '')
  }), /*#__PURE__*/React.createElement(NavBar, {
    title: title,
    titleProps: titleProps,
    cancel: cancel,
    onCancel: handleCancelClick,
    cancelProps: cancelProps,
    ok: ok,
    onOk: typeof onOk === 'function' ? function () {
      onOk({
        close: function close() {
          return onVisibleChange && onVisibleChange(false);
        }
      });
    } : null,
    okProps: okProps
  }), children));
  if (portal === null || portal === false) {
    return Node;
  }
  return /*#__PURE__*/createPortal(Node, portal || document.getElementById('root') || document.body);
});
export default NavBarModal;