/*! © 2026 Yahoo, Inc. UDS v0.0.0-development */
"use client";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
require("../../../_virtual/_rolldown/runtime.cjs");
const require_styles_styler = require("../../../styles/styler.cjs");
const require_components_Box = require("../../Box.cjs");
const require_components_Scrim = require("../../Scrim.cjs");
const require_utils_exposeAriakitScrollbarWidth = require("../../../utils/exposeAriakitScrollbarWidth.cjs");
const require_components_client_BottomSheet_BottomSheetHandle = require("./BottomSheetHandle.cjs");
const require_components_client_BottomSheet_BottomSheetInternalContext = require("./BottomSheetInternalContext.cjs");
const require_components_client_BottomSheet_getBottomSheetSnapTransition = require("./getBottomSheetSnapTransition.cjs");
const require_components_client_BottomSheet_UDSBottomSheetConfigProvider = require("./UDSBottomSheetConfigProvider.cjs");
const require_components_client_BottomSheet_useBottomSheetDrag = require("./useBottomSheetDrag.cjs");
const require_components_client_BottomSheet_useBottomSheetSnapModel = require("./useBottomSheetSnapModel.cjs");
const require_components_client_BottomSheet_useBottomSheetStore = require("./useBottomSheetStore.cjs");
const require_components_client_BottomSheet_useExpansionMargins = require("./useExpansionMargins.cjs");
const require_components_client_BottomSheet_useViewportHeight = require("./useViewportHeight.cjs");
const require_components_client_BottomSheet_useVirtualKeyboard = require("./useVirtualKeyboard.cjs");
let react = require("react");
let react_jsx_runtime = require("react/jsx-runtime");
let _ariakit_react = require("@ariakit/react");
let motion_react = require("motion/react");
//#region src/components/client/BottomSheet/BottomSheet.tsx
/**
* Drag-to-dismiss distance threshold as a ratio of the lowest snap point's
* visible height. Dragging down past this fraction of the height dismisses
* the sheet (regardless of velocity).
*
* Velocity and distance are OR conditions — exceeding either one triggers dismissal.
*/
const DRAG_DISMISS_THRESHOLD_RATIO = .25;
/**
* Top inset reserved when calculating max sheet height.
* Keeps a visible sliver of page content so the fully expanded state still reads as a bottom sheet.
*/
const SHEET_MAX_HEIGHT_TOP_OFFSET_PX = 26;
require_utils_exposeAriakitScrollbarWidth.exposeAriakitScrollbarWidth();
function BottomSheet({ children, className: sheetClassName, controller: controllerProp, variant = "default", snapPoints: snapPointsProp, defaultSnapPointIndex = 0, snapPointIndex: snapPointIndexProp, onSnapPointChange, height, modal = true, portal = true, portalElement, dismissible = true, enableDrag = true, showHandleIndicator = true, hideOnEscape = true, onClose, reduceMotion: forceReduceMotion = false, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy, backdrop, preventBodyScroll, slotProps, fullWidthAtMaxSnap = false }) {
	const storeFromContext = (0, _ariakit_react.useDialogContext)();
	const dialogStore = controllerProp ? require_components_client_BottomSheet_useBottomSheetStore.getBottomSheetInternal(controllerProp) : storeFromContext;
	const { backgroundColor: configBackgroundColor } = require_components_client_BottomSheet_UDSBottomSheetConfigProvider.useBottomSheetConfig();
	if (!dialogStore) throw new Error("BottomSheet must be wrapped in BottomSheetProvider or provided a controller prop.");
	const isOpen = dialogStore.useState().open;
	const keyboardHeightPx = require_components_client_BottomSheet_useVirtualKeyboard.useVirtualKeyboard(isOpen);
	const viewportHeightPx = require_components_client_BottomSheet_useViewportHeight.useViewportHeight();
	const prefersReducedMotion = (0, motion_react.useReducedMotion)() ?? false;
	const reducedMotion = forceReduceMotion || prefersReducedMotion;
	const isDraggingRef = (0, react.useRef)(false);
	const forceZeroMarginsRef = (0, react.useRef)(false);
	forceZeroMarginsRef.current = keyboardHeightPx > 0;
	const sheetRef = (0, react.useRef)(null);
	const maxSnapPxRef = (0, react.useRef)(0);
	const sheetHeightRef = (0, react.useRef)(void 0);
	const wasOpenRef = (0, react.useRef)(false);
	if (isOpen && !wasOpenRef.current) sheetHeightRef.current = void 0;
	wasOpenRef.current = isOpen;
	const maxHeightPx = Math.max(viewportHeightPx - SHEET_MAX_HEIGHT_TOP_OFFSET_PX, 0);
	const applySheetHeight = (0, react.useCallback)((el, h) => {
		el.style.height = h;
		sheetHeightRef.current = h;
	}, []);
	const rootVariantClass = require_styles_styler.getStyles({ bottomsheetVariantRoot: variant });
	const { applyExpansionMargins, thresholdRef: expansionThresholdRef } = require_components_client_BottomSheet_useExpansionMargins.useExpansionMargins({
		sheetRef,
		maxSnapPxRef,
		fullWidthAtMaxSnap,
		snapPointsLength: snapPointsProp?.length ?? 1,
		isOpen,
		forceZeroRef: forceZeroMarginsRef
	});
	/**
	* Applies drag-time position updates with no animation.
	* We model the sheet by height, so translate is converted to height:
	* `height = maxSnapPointPx - translatePx`.
	*/
	const setTranslateImmediate = (0, react.useCallback)((nextTranslatePx) => {
		const el = sheetRef.current;
		if (!el) return;
		applySheetHeight(el, `${maxSnapPxRef.current - nextTranslatePx}px`);
		applyExpansionMargins(el, nextTranslatePx);
	}, [applySheetHeight, applyExpansionMargins]);
	const { resolvedSnapPoints, snapPointsPx, maxSnapPointPx, snapPointTranslatesPx, activeSnapIndex, restTranslatePx, emitSnapPointChange, openTimeRef, lastTimeDragPreventedRef, isEnteringRef } = require_components_client_BottomSheet_useBottomSheetSnapModel.useBottomSheetSnapModel({
		isOpen,
		snapPointsProp,
		height,
		defaultSnapPointIndex,
		snapPointIndexProp,
		onSnapPointChange,
		viewportHeightPx,
		maxHeightPx,
		setTranslateAnimated: (0, react.useCallback)((nextTranslatePx) => {
			const el = sheetRef.current;
			if (!el) return;
			const h = `${maxSnapPxRef.current - nextTranslatePx}px`;
			if (!el.style.height) {
				applySheetHeight(el, h);
				applyExpansionMargins(el, nextTranslatePx);
			} else if (reducedMotion) {
				el.style.removeProperty("transition");
				applySheetHeight(el, h);
				applyExpansionMargins(el, nextTranslatePx);
			} else {
				const transition = require_components_client_BottomSheet_getBottomSheetSnapTransition.getBottomSheetSnapTransition({
					prefersReducedMotion: reducedMotion,
					animateExpansionMargins: expansionThresholdRef.current != null
				});
				if (!transition) {
					applySheetHeight(el, h);
					applyExpansionMargins(el, nextTranslatePx);
					return;
				}
				el.style.transition = transition;
				applySheetHeight(el, h);
				applyExpansionMargins(el, nextTranslatePx);
				const cleanup = () => {
					el.style.removeProperty("transition");
					el.removeEventListener("transitionend", cleanup);
				};
				el.addEventListener("transitionend", cleanup);
			}
		}, [
			applySheetHeight,
			applyExpansionMargins,
			expansionThresholdRef,
			reducedMotion
		]),
		isDraggingRef
	});
	maxSnapPxRef.current = maxSnapPointPx;
	expansionThresholdRef.current = fullWidthAtMaxSnap && (snapPointsProp?.length ?? 1) >= 2 ? snapPointsPx[snapPointsPx.length - 2] ?? 0 : null;
	const visibleTranslatePx = isOpen && !isEnteringRef.current ? 0 : viewportHeightPx;
	const resolvedDismissThresholdPx = (snapPointsPx[0] ?? maxSnapPointPx) * DRAG_DISMISS_THRESHOLD_RATIO;
	const shouldShowHandleIndicator = showHandleIndicator && enableDrag;
	const isAtMaxSnapPoint = activeSnapIndex === resolvedSnapPoints.length - 1;
	const scrollLocked = !isAtMaxSnapPoint;
	const internalContextValue = (0, react.useMemo)(() => ({ scrollLocked }), [scrollLocked]);
	const shouldHideEdgeBordersAtMaxSnap = fullWidthAtMaxSnap && resolvedSnapPoints.length >= 2 && isAtMaxSnapPoint;
	const handleHandleIndicatorKeyDown = (0, react.useCallback)((event) => {
		if (!shouldShowHandleIndicator || resolvedSnapPoints.length <= 1) return;
		if (event.key === "ArrowUp") {
			event.preventDefault();
			emitSnapPointChange(activeSnapIndex + 1);
		}
		if (event.key === "ArrowDown") {
			event.preventDefault();
			if (activeSnapIndex === 0 && dismissible) {
				dialogStore.hide();
				return;
			}
			emitSnapPointChange(activeSnapIndex - 1);
		}
	}, [
		activeSnapIndex,
		dismissible,
		emitSnapPointChange,
		resolvedSnapPoints.length,
		shouldShowHandleIndicator,
		dialogStore
	]);
	const { onPointerDown, onPointerMove, onPointerUp, onPointerCancel } = require_components_client_BottomSheet_useBottomSheetDrag.useBottomSheetDrag({
		enableDrag,
		dismissible,
		store: dialogStore,
		sheetRef,
		isDraggingRef,
		activeSnapIndex,
		snapPointTranslatesPx,
		maxSnapPointPx,
		resolvedSnapPointsLength: resolvedSnapPoints.length,
		resolvedDismissThresholdPx,
		emitSnapPointChange,
		setTranslateImmediate,
		openTimeRef,
		lastTimeDragPreventedRef
	});
	(0, react.useEffect)(() => {
		if (!fullWidthAtMaxSnap || !isOpen) return;
		const el = sheetRef.current;
		if (!el || !el.style.height) return;
		applyExpansionMargins(el, restTranslatePx);
	}, [
		restTranslatePx,
		fullWidthAtMaxSnap,
		isOpen,
		applyExpansionMargins
	]);
	(0, react.useLayoutEffect)(() => {
		const el = sheetRef.current;
		if (!el || !sheetHeightRef.current) return;
		if (!el.style.height) el.style.height = sheetHeightRef.current;
	});
	const dialogBackdrop = modal ? backdrop ?? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_components_Scrim.Scrim, {
		className: slotProps?.scrim?.className,
		animateOpacity: true
	}) : false;
	const hideOnInteractOutside = modal && dismissible ? void 0 : false;
	const isElevationBackgroundColor = configBackgroundColor[variant].startsWith("elevation-");
	return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_ariakit_react.Dialog, {
		ref: sheetRef,
		store: dialogStore,
		modal,
		unmountOnHide: true,
		hideOnEscape: dismissible ? hideOnEscape : false,
		hideOnInteractOutside,
		onClose,
		"aria-label": ariaLabel,
		"aria-labelledby": ariaLabelledBy,
		"aria-describedby": ariaDescribedBy,
		backdrop: dialogBackdrop,
		portal,
		portalElement,
		preventBodyScroll: preventBodyScroll ?? (modal ? void 0 : false),
		"data-testid": "bottom-sheet",
		className: require_styles_styler.cx("fixed overflow-hidden inset-x-0 bottom-0 z-50", keyboardHeightPx > 0 ? void 0 : "bottom-0", scrollLocked ? "[will-change:transform] touch-none" : "[will-change:transform]", "[transform:translate3d(0,var(--uds-bottomsheet-hidden-translate),0)]", "data-[enter]:[transform:translate3d(0,var(--uds-bottomsheet-visible-translate),0)]", "transition-transform duration-500 ease-[cubic-bezier(0.32,0.72,0,1)]", "motion-reduce:transition-none", sheetClassName, rootVariantClass),
		style: {
			height: sheetHeightRef.current,
			maxHeight: maxHeightPx ? `${maxHeightPx}px` : void 0,
			...shouldHideEdgeBordersAtMaxSnap ? {
				borderBottomWidth: 0,
				borderLeftWidth: 0,
				borderRightWidth: 0
			} : {},
			["--uds-bottomsheet-hidden-translate"]: `${viewportHeightPx}px`,
			["--uds-bottomsheet-visible-translate"]: `${visibleTranslatePx}px`,
			...isElevationBackgroundColor && {
				backdropFilter: `var(--uds-background-blur-radius-${configBackgroundColor[variant]})`,
				WebkitBackdropFilter: `var(--uds-background-blur-radius-${configBackgroundColor[variant]})`
			}
		},
		onPointerDown,
		onPointerMove,
		onPointerUp,
		onPointerCancel,
		children: [shouldShowHandleIndicator && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_components_Box.Box, {
			display: "block",
			position: "absolute",
			className: require_styles_styler.cx("inset-x-0 top-[-4px] z-[1] touch-pan-y"),
			children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_components_client_BottomSheet_BottomSheetHandle.BottomSheetHandle, {
				onKeyDown: handleHandleIndicatorKeyDown,
				ariaLabel: "Resize sheet",
				className: slotProps?.handleIndicator?.className,
				variant
			})
		}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_components_client_BottomSheet_BottomSheetInternalContext.BottomSheetInternalContext.Provider, {
			value: internalContextValue,
			children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_components_Box.Box, {
				display: "flex",
				flexDirection: "column",
				className: "absolute inset-0 min-h-0 p-[inherit]",
				children
			})
		})]
	});
}
BottomSheet.displayName = "BottomSheet";
//#endregion
exports.BottomSheet = BottomSheet;
