import React, { forwardRef, useRef } from "react";
import { Overlay } from "../Overlay";
import { cx } from "../../utils";
import { useOverflow, useSheetSwipe } from "./hooks";
import { classes, tokens } from "./Sheet.tokens";
import { StyledContentWrapper, StyledSheetBody, StyledSheetContent, StyledSheetFooter, StyledSheetHandle, StyledSheetHeader } from "./Sheet.styles";
import { base as viewCSS } from "./variations/_view/base";
import { base as handlePlacementCSS } from "./variations/_handlePlacement/base";
import { DEFAULT_Z_INDEX } from "./utils";
/**
 * Открывает окно-шторку поверх основного экрана.
 */ export const sheetRoot = (Root)=>/*#__PURE__*/ forwardRef(({ opened, children, onClose, hasHandle = true, handlePlacement, contentHeader, isHeaderFixed = false, contentFooter, isFooterFixed = false, withOverlay = true, withBlur = false, withTransition = true, hasScrollEvents = true, throttleMs, className, view, ...restProps }, rootRef)=>{
        const contentWrapperRef = useRef(null);
        const contentRef = useRef(null);
        const handleRef = useRef(null);
        useOverflow({
            opened
        });
        useSheetSwipe({
            contentWrapperRef,
            contentRef,
            handleRef,
            throttleMs,
            hasScrollEvents,
            onClose
        });
        const hasHeader = Boolean(contentHeader);
        const hasFooter = Boolean(contentFooter);
        const closedClass = opened ? undefined : `${classes.closed}`;
        const overlayBackgroundToken = withBlur ? `var(${tokens.sheetOverlayWithBlurColor})` : `var(${tokens.sheetOverlayColor})`;
        return /*#__PURE__*/ React.createElement(Root, {
            opened: opened,
            onClose: onClose,
            view: view,
            handlePlacement: handlePlacement,
            ref: rootRef
        }, /*#__PURE__*/ React.createElement(StyledContentWrapper, {
            opened: opened,
            withTransition: withTransition,
            className: cx(closedClass, className),
            ref: contentWrapperRef,
            ...restProps
        }, hasHandle && /*#__PURE__*/ React.createElement(StyledSheetHandle, {
            ref: handleRef
        }), /*#__PURE__*/ React.createElement(StyledSheetContent, {
            hasHeader: hasHeader,
            hasFooter: hasFooter,
            ref: contentRef
        }, hasHeader && /*#__PURE__*/ React.createElement(StyledSheetHeader, {
            isHeaderFixed: isHeaderFixed
        }, contentHeader), /*#__PURE__*/ React.createElement(StyledSheetBody, null, children), hasFooter && /*#__PURE__*/ React.createElement(StyledSheetFooter, {
            isFooterFixed: isFooterFixed
        }, contentFooter))), withOverlay && opened && /*#__PURE__*/ React.createElement(Overlay, {
            zIndex: DEFAULT_Z_INDEX,
            backgroundColorProperty: overlayBackgroundToken,
            withBlur: withBlur,
            isClickable: true,
            onOverlayClick: onClose
        }));
    });
export const sheetConfig = {
    name: 'Sheet',
    tag: 'div',
    layout: sheetRoot,
    base: '',
    variations: {
        view: {
            css: viewCSS
        },
        handlePlacement: {
            css: handlePlacementCSS
        }
    },
    defaults: {
        view: 'default',
        handlePlacement: 'outer'
    }
};
