"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 bottomSheetConfig () {
        return bottomSheetConfig;
    },
    get bottomSheetRoot () {
        return bottomSheetRoot;
    }
});
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
const _Overlay = require("../Overlay");
const _Icon = require("../_Icon");
const _utils = require("../../utils");
const _utils1 = require("./utils");
const _BottomSheettokens = require("./BottomSheet.tokens");
const _useBottomSheet = require("./hooks/useBottomSheet");
const _base = require("./variations/_view/base");
const _base1 = require("./variations/_size/base");
const _BottomSheetstyles = require("./BottomSheet.styles");
function _getRequireWildcardCache(nodeInterop) {
    if (typeof WeakMap !== "function") return null;
    var cacheBabelInterop = new WeakMap();
    var cacheNodeInterop = new WeakMap();
    return (_getRequireWildcardCache = function(nodeInterop) {
        return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
    })(nodeInterop);
}
function _interop_require_wildcard(obj, nodeInterop) {
    if (!nodeInterop && obj && obj.__esModule) {
        return obj;
    }
    if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
        return {
            default: obj
        };
    }
    var cache = _getRequireWildcardCache(nodeInterop);
    if (cache && cache.has(obj)) {
        return cache.get(obj);
    }
    var newObj = {
        __proto__: null
    };
    var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
    for(var key in obj){
        if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
            var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
            if (desc && (desc.get || desc.set)) {
                Object.defineProperty(newObj, key, desc);
            } else {
                newObj[key] = obj[key];
            }
        }
    }
    newObj.default = obj;
    if (cache) {
        cache.set(obj, newObj);
    }
    return newObj;
}
const noop = ()=>{};
const bottomSheetRoot = (Root)=>/*#__PURE__*/ (0, _react.forwardRef)(({ opened = false, children, contentBeforeHeader, contentHeader, contentFooter, handlePlacement = 'inner', hasClose = true, hasHandle = true, withOverlay = true, withBlur = true, withTransition = true, maxHeight = '66dvh', zIndex = 1000, onClose = noop, className, view, size, ...rest }, ref)=>{
        const content = (0, _react.useMemo)(()=>[
                contentBeforeHeader,
                contentHeader,
                children,
                contentFooter
            ], [
            contentBeforeHeader,
            contentHeader,
            children,
            contentFooter
        ]);
        const { panelRef, bodyRef, handleRef, overflows, headerDivider, footerDivider } = (0, _useBottomSheet.useBottomSheet)({
            opened,
            content,
            onClose,
            hasHandle
        });
        const panelClassName = (0, _utils.cx)(_BottomSheettokens.classes.panel, withTransition && _BottomSheettokens.classes.animated, !opened && _BottomSheettokens.classes.closed);
        return /*#__PURE__*/ _react.default.createElement(Root, {
            ref: ref,
            className: className,
            view: view,
            size: size,
            ...rest
        }, withOverlay && opened && /*#__PURE__*/ _react.default.createElement(_Overlay.Overlay, {
            zIndex: String(zIndex),
            backgroundColorProperty: withBlur ? `var(${_BottomSheettokens.tokens.overlayWithBlurColor})` : `var(${_BottomSheettokens.tokens.overlayColor})`,
            withBlur: withBlur,
            isClickable: true,
            onOverlayClick: onClose
        }), /*#__PURE__*/ _react.default.createElement(_BottomSheetstyles.Panel, {
            ref: panelRef,
            className: panelClassName,
            style: {
                maxHeight,
                zIndex: (0, _utils1.getPanelZIndex)(zIndex)
            }
        }, hasHandle && /*#__PURE__*/ _react.default.createElement(_BottomSheetstyles.Handler, {
            ref: handleRef,
            $placement: handlePlacement,
            className: _BottomSheettokens.classes.hasHandle
        }), hasClose && /*#__PURE__*/ _react.default.createElement(_BottomSheetstyles.CloseButton, {
            view: "clear",
            onClick: onClose,
            "aria-label": "Закрыть"
        }, /*#__PURE__*/ _react.default.createElement(_Icon.IconClose, {
            size: "s",
            color: "inherit"
        })), /*#__PURE__*/ _react.default.createElement(_BottomSheetstyles.PanelContent, null, contentBeforeHeader && /*#__PURE__*/ _react.default.createElement(_BottomSheetstyles.BeforeHeader, {
            className: _BottomSheettokens.classes.beforeHeaderSlot
        }, contentBeforeHeader), contentHeader && /*#__PURE__*/ _react.default.createElement(_BottomSheetstyles.Header, {
            className: (0, _utils.cx)(_BottomSheettokens.classes.headerSlot, headerDivider && _BottomSheettokens.classes.headerDividerVisible)
        }, contentHeader), children && /*#__PURE__*/ _react.default.createElement(_BottomSheetstyles.StyledBody, {
            ref: bodyRef,
            className: (0, _utils.cx)(_BottomSheettokens.classes.bodySlot, overflows && _BottomSheettokens.classes.scrollable)
        }, children), contentFooter && /*#__PURE__*/ _react.default.createElement(_BottomSheetstyles.Footer, {
            className: (0, _utils.cx)(_BottomSheettokens.classes.footerSlot, footerDivider && _BottomSheettokens.classes.footerDividerVisible)
        }, contentFooter))));
    });
const bottomSheetConfig = {
    name: 'BottomSheet',
    tag: 'div',
    layout: bottomSheetRoot,
    base: '',
    variations: {
        view: {
            css: _base.base
        },
        size: {
            css: _base1.base
        }
    },
    defaults: {
        view: 'default',
        size: 'm'
    }
};
