"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
function _export(target, all) {
    for(var name in all)Object.defineProperty(target, name, {
        enumerable: true,
        get: Object.getOwnPropertyDescriptor(all, name).get
    });
}
_export(exports, {
    get Overlay () {
        return Overlay;
    },
    get defaultOverlayProps () {
        return defaultOverlayProps;
    }
});
var _interop_require_default = require("@swc/helpers/_/_interop_require_default");
var _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
var _object_spread = require("@swc/helpers/_/_object_spread");
var _object_spread_props = require("@swc/helpers/_/_object_spread_props");
var _object_without_properties = require("@swc/helpers/_/_object_without_properties");
var _sliced_to_array = require("@swc/helpers/_/_sliced_to_array");
var _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
var _classnames = /*#__PURE__*/ _interop_require_default._(require("classnames"));
var _components = require("@tarojs/components");
var _typings = require("../../utils/typings");
var _uselockscoll = require("../../hooks/taro/use-lock-scoll");
var _ConfigurableCSSTransition = /*#__PURE__*/ _interop_require_default._(require("../../utils/taro/ConfigurableCSSTransition"));
var defaultOverlayProps = (0, _object_spread_props._)((0, _object_spread._)({}, _typings.ComponentDefaults), {
    zIndex: 1000,
    duration: 300,
    closeOnOverlayClick: true,
    visible: false,
    lockScroll: true,
    onClick: function onClick() {},
    afterShow: function afterShow() {},
    afterClose: function afterClose() {}
});
var Overlay = function Overlay(props) {
    var _ref = (0, _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 = (0, _object_without_properties._)(_ref, [
        "children",
        "zIndex",
        "duration",
        "className",
        "closeOnOverlayClick",
        "visible",
        "lockScroll",
        "style",
        "afterShow",
        "afterClose",
        "onClick"
    ]);
    var classPrefix = 'nut-overlay';
    var _useState = (0, _sliced_to_array._)((0, _react.useState)(visible), 2), innerVisible = _useState[0], setInnerVisible = _useState[1];
    var nodeRef = (0, _uselockscoll.useLockScrollTaro)(!!lockScroll && innerVisible);
    (0, _react.useEffect)(function() {
        setInnerVisible(visible);
    }, [
        visible
    ]);
    var classes = (0, _classnames.default)(classPrefix, className);
    var styles = (0, _object_spread._)({
        zIndex: zIndex
    }, style);
    var handleClick = function handleClick(e) {
        if (closeOnOverlayClick) {
            onClick && onClick(e);
        }
    };
    var renderOverlay = function renderOverlay() {
        return /*#__PURE__*/ _react.default.createElement(_components.View, (0, _object_spread_props._)((0, _object_spread._)({
            ref: nodeRef,
            className: classes,
            style: styles
        }, rest), {
            catchMove: lockScroll,
            onClick: handleClick
        }), children);
    };
    return /*#__PURE__*/ _react.default.createElement(_ConfigurableCSSTransition.default, {
        nodeRef: nodeRef,
        classNames: "".concat(classPrefix, "-slide"),
        unmountOnExit: true,
        timeout: Number(duration),
        in: innerVisible,
        onEntered: afterShow,
        onExited: afterClose
    }, renderOverlay());
};
Overlay.displayName = 'NutOverlay';
