import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
import { _ as _object_without_properties } from "@swc/helpers/_/_object_without_properties";
import React from "react";
import { CSSTransition } from "react-transition-group";
import { Content, defaultContentProps } from "./content";
import { defaultOverlayProps } from "../overlay/overlay";
import Overlay from "../overlay";
export var defaultDialogWrapProps = _object_spread_props(_object_spread({}, defaultOverlayProps, defaultContentProps), {
    overlay: true,
    overlayStyle: {},
    overlayClassName: 'nut-dialog-overlay',
    onCancel: function() {},
    onClose: function() {},
    onOverlayClick: function() {
        return true;
    }
});
export var DialogWrap = function(props) {
    var _ref = _object_spread({}, defaultDialogWrapProps, props), visible = _ref.visible, overlay = _ref.overlay, overlayStyle = _ref.overlayStyle, overlayClassName = _ref.overlayClassName, closeOnOverlayClick = _ref.closeOnOverlayClick, lockScroll = _ref.lockScroll, zIndex = _ref.zIndex, onClose = _ref.onClose, onCancel = _ref.onCancel, onOverlayClick = _ref.onOverlayClick, restProps = _object_without_properties(_ref, [
        "visible",
        "overlay",
        "overlayStyle",
        "overlayClassName",
        "closeOnOverlayClick",
        "lockScroll",
        "zIndex",
        "onClose",
        "onCancel",
        "onOverlayClick"
    ]);
    var onHandleClickOverlay = function(e) {
        if (closeOnOverlayClick && visible && e.target === e.currentTarget) {
            var closed = onOverlayClick && onOverlayClick(e);
            closed && (onClose === null || onClose === void 0 ? void 0 : onClose());
            closed && (onCancel === null || onCancel === void 0 ? void 0 : onCancel());
        }
    };
    return /*#__PURE__*/ React.createElement(React.Fragment, null, overlay && /*#__PURE__*/ React.createElement(Overlay, {
        zIndex: zIndex,
        style: overlayStyle,
        className: overlayClassName,
        visible: visible,
        closeOnOverlayClick: closeOnOverlayClick,
        lockScroll: lockScroll,
        onClick: onHandleClickOverlay
    }), /*#__PURE__*/ React.createElement(CSSTransition, {
        in: visible,
        timeout: 300,
        classNames: "fadeDialog",
        unmountOnExit: true,
        appear: true
    }, /*#__PURE__*/ React.createElement(Content, _object_spread_props(_object_spread({}, restProps), {
        visible: visible
    }))));
};
DialogWrap.displayName = 'NutDialogWrap';
