// Metro module 5391 (f5392).
import _slicedToArray from "./_slicedToArray";
import * as _Module19 from "react";
import Module19, { createElement, useCallback, useImperativeHandle, useMemo, useRef, useState } from "react";
import * as _Module5392 from "./Module5392";
import { useBottomSheetModalInternal } from "./Module5250";
import { usePortal, Portal } from "./Module4060";
import { id } from "./Module5393";
import { print } from "./Module5262";
import Module5247 from "./Module5247";
const _excluded = ["name", "stackBehavior", "enableDismissOnClose", "onDismiss", "onAnimate", "index", "snapPoints", "enablePanDownToClose", "animateOnMount", "containerComponent", "onChange", "children"];
const { forwardRef, memo: memo2 } = _Module19;
let c3292_14 = {
mount: false,
data: void 0
};
let c3292_15 = memo2(forwardRef(function BottomSheetModalComponent(props, a1) {
let callback, callback2, callback3, callback4, callback5, callback6, callback7, callback8, callback9, callback10, callback11, callback12, resetVariables2;
let c14842_0 = a1;
const { name, stackBehavior = _Module5392.DEFAULT_STACK_BEHAVIOR } = props;
const DEFAULT_STACK_BEHAVIOR = stackBehavior;
let enableDismissOnClose = props.enableDismissOnClose;
if (enableDismissOnClose === void 0) {
enableDismissOnClose = _Module5392.DEFAULT_ENABLE_DISMISS_ON_CLOSE;
}
const DEFAULT_ENABLE_DISMISS_ON_CLOSE = enableDismissOnClose;
const { onDismiss, onAnimate, index = 0, snapPoints, enablePanDownToClose = true, animateOnMount: animateOnMount2 = true, containerComponent: ContainerComponent = Module19.Fragment, onChange, children: Children, ...rest } = props;
const r54 = _slicedToArray(useState(c3292_14), 2);
const r55 = r54[0];
const { mount, data: data2 } = r55;
const setState = r54[1];
const bottomSheetModalInternal = useBottomSheetModalInternal();
const { hostName, containerHeight, containerOffset, mountSheet, unmountSheet, willUnmountSheet } = bottomSheetModalInternal;
const removePortal = usePortal(hostName).removePortal;
const ref = useRef(null);
const ref2 = useRef(animateOnMount2 ? -1 : index);
const ref3 = useRef(null);
const ref4 = useRef(-1);
const ref5 = useRef(false);
const ref6 = useRef(false);
const ref7 = useRef(false);
ref7.current = mount;
const memo = useMemo(() => {
let r5 = name;
if (!name) {
r5 = `bottom-sheet-modal-${id()}`;
}
return r5;
}, [name]);
resetVariables2 = function resetVariables() {
print({
component: c3292_15.name,
method: resetVariables2.name
});
ref2.current = -1;
ref4.current = -1;
ref5.current = false;
ref7.current = false;
ref6.current = false;
};
callback = useCallback(resetVariables2, []);
callback2 = useCallback(function unmount() {
const current = ref7.current;
callback();
unmountSheet(memo);
removePortal(memo);
if (current) {
setState(c3292_14);
}
if (onDismiss) {
onDismiss();
}
}, [memo, callback, unmountSheet, removePortal, onDismiss]);
callback3 = useCallback(function(...args) {
if (!ref5.current) {
const current = ref.current;
if (current != null) {
current.snapToIndex.apply(current, [...args]);
}
}
}, []);
callback4 = useCallback(function(...args) {
if (!ref5.current) {
const current = ref.current;
if (current != null) {
current.snapToPosition.apply(current, [...args]);
}
}
}, []);
callback5 = useCallback(function(...args) {
if (!ref5.current) {
const current = ref.current;
if (current != null) {
current.expand.apply(current, [...args]);
}
}
}, []);
callback6 = useCallback(function(...args) {
if (!ref5.current) {
const current = ref.current;
if (current != null) {
current.collapse.apply(current, [...args]);
}
}
}, []);
callback7 = useCallback(function(...args) {
if (!ref5.current) {
const current = ref.current;
if (current != null) {
current.close.apply(current, [...args]);
}
}
}, []);
callback8 = useCallback(function(...args) {
if (!ref5.current) {
const current = ref.current;
if (current != null) {
current.forceClose.apply(current, [...args]);
}
}
}, []);
callback9 = useCallback(function handlePresent(data) {
requestAnimationFrame(() => {
setState({
mount: true,
data
});
mountSheet(memo, c14842_0, DEFAULT_STACK_BEHAVIOR);
});
}, [memo, DEFAULT_STACK_BEHAVIOR, mountSheet]);
callback10 = useCallback(function handleDismiss(a0) {
const r2 = ref3.current != null;
const r1 = ref2.current !== -1 || ref5.current !== false || r2;
L12: {
if (r1) {
L10: {
if (!r2) {
if (!ref5.current) {
if (ref2.current !== -1) {
break L10;
}
if (!enablePanDownToClose) {
break L10;
}
}
callback2();
break L12;
}
}
willUnmountSheet(memo);
ref6.current = true;
const current = ref.current;
if (current != null) {
current.forceClose(a0);
}
}
}
}, [willUnmountSheet, callback2, memo, enablePanDownToClose]);
callback11 = useCallback(function handleMinimize() {
if (!ref5.current) {
ref5.current = true;
if (ref2.current === -1) {
ref4.current = index;
} else {
ref4.current = ref2.current;
}
const current = ref.current;
if (current != null) {
current.close();
}
}
}, [index]);
callback12 = useCallback(function handleRestore() {
if (ref5.current && !ref6.current) {
ref5.current = false;
const current = ref.current;
if (current != null) {
current.snapToIndex(ref4.current);
}
}
}, []);
const callback13 = useCallback(function handlePortalOnUnmount() {
if (!(ref2.current === -1 && ref5.current === false)) {
ref7.current = false;
ref6.current = true;
if (ref5.current) {
callback2();
} else {
willUnmountSheet(memo);
const current = ref.current;
if (current != null) {
current.close();
}
}
}
}, [memo, callback2, willUnmountSheet]);
const callback14 = useCallback(function handlePortalRender(a0) {
if (ref7.current) {
a0();
}
}, []);
const callback15 = useCallback(function handleBottomSheetOnChange(a0, a1, a2) {
ref2.current = a0;
ref3.current = null;
if (onChange) {
onChange(a0, a1, a2);
}
}, [onChange]);
const callback16 = useCallback((a0, a1, a2, a3, a4) => {
ref3.current = a1;
if (onAnimate) {
onAnimate(a0, a1, a2, a3, a4);
}
}, [onAnimate]);
const callback17 = useCallback(function handleBottomSheetOnClose() {
if (!ref5.current && DEFAULT_ENABLE_DISMISS_ON_CLOSE) {
callback2();
}
}, [DEFAULT_ENABLE_DISMISS_ON_CLOSE, callback2]);
useImperativeHandle(a1, () => ({
snapToIndex: callback3,
snapToPosition: callback4,
expand: callback5,
collapse: callback6,
close: callback7,
forceClose: callback8,
dismiss: callback10,
present: callback9,
minimize: callback11,
restore: callback12
}));
let r133 = null;
if (mount) {
const r143 = {
...rest,
ref,
key: memo,
index,
snapPoints,
enablePanDownToClose,
animateOnMount: animateOnMount2,
containerHeight,
containerOffset,
onChange: callback15,
onClose: callback17,
onAnimate: callback16,
$modal: true
};
let r146 = Children;
if (typeof r146 === "function") {
r146 = ;
}
r133 =
{createElement(Module5247, r143, r146)}
;
}
return r133;
}));
c3292_15.displayName = "BottomSheetModal";
export default c3292_15;