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 { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
import React, { useEffect, useState } from "react";
import classNames from "classnames";
import { View } from "@tarojs/components";
import { ComponentDefaults } from "../../utils/typings";
import { useLockScrollTaro } from "../../hooks/taro/use-lock-scoll";
import ConfigurableCSSTransition from "../../utils/taro/ConfigurableCSSTransition";
export var defaultOverlayProps = _object_spread_props(_object_spread({}, ComponentDefaults), {
    zIndex: 1000,
    duration: 300,
    closeOnOverlayClick: true,
    visible: false,
    lockScroll: true,
    onClick: function() {},
    afterShow: function() {},
    afterClose: function() {}
});
export var Overlay = function(props) {
    var _ref = _object_spread({}, defaultOverlayProps, props), children = _ref.children, zIndex = _ref.zIndex, duration = _ref.duration, className = _ref.className, closeOnOverlayClick = _ref.closeOnOverlayClick, visible = _ref.visible, lockScroll = _ref.lockScroll, style = _ref.style, afterShow = _ref.afterShow, afterClose = _ref.afterClose, onClick = _ref.onClick, rest = _object_without_properties(_ref, [
        "children",
        "zIndex",
        "duration",
        "className",
        "closeOnOverlayClick",
        "visible",
        "lockScroll",
        "style",
        "afterShow",
        "afterClose",
        "onClick"
    ]);
    var classPrefix = 'nut-overlay';
    var _useState = _sliced_to_array(useState(visible), 2), innerVisible = _useState[0], setInnerVisible = _useState[1];
    var nodeRef = useLockScrollTaro(!!lockScroll && innerVisible);
    useEffect(function() {
        setInnerVisible(visible);
    }, [
        visible
    ]);
    var classes = classNames(classPrefix, className);
    var styles = _object_spread({
        zIndex: zIndex
    }, style);
    var handleClick = function(e) {
        if (closeOnOverlayClick) {
            onClick && onClick(e);
        }
    };
    var renderOverlay = function() {
        return /*#__PURE__*/ React.createElement(View, _object_spread_props(_object_spread({
            ref: nodeRef,
            className: classes,
            style: styles
        }, rest), {
            catchMove: lockScroll,
            onClick: handleClick
        }), children);
    };
    return /*#__PURE__*/ React.createElement(ConfigurableCSSTransition, {
        nodeRef: nodeRef,
        classNames: "".concat(classPrefix, "-slide"),
        unmountOnExit: true,
        timeout: Number(duration),
        in: innerVisible,
        onEntered: afterShow,
        onExited: afterClose
    }, renderOverlay());
};
Overlay.displayName = 'NutOverlay';
