import { AnimatePresence, Motion } from '@legendapp/motion'
import { useKeyboard } from '@react-native-community/hooks'
import { useCallback, useEffect, useState } from 'react'
import { Keyboard, StyleSheet } from 'react-native'
import BottomSheet from './BottomSheet'
import useLayoutType from '../hooks/useLayoutType'
import { Palette } from '../styles'
export default ({
children,
bottomSheetRef,
snapPoints = ['25%', '50%'],
handleStyle = {},
...rest
}) => {
const [currentSnapPointIndex, setCurrentSnapPointIndex] = useState(0)
const { keyboardShown = false } = useKeyboard()
const { isWeb } = useLayoutType()
const handleSheetChanges = useCallback((index) => {
setCurrentSnapPointIndex(index)
if (index <= 0) {
Keyboard.dismiss()
}
}, [])
useEffect(() => {
if (bottomSheetRef.current && !isWeb && currentSnapPointIndex > 0) {
if (keyboardShown) {
bottomSheetRef.current.expand()
} else {
bottomSheetRef.current.snapToIndex(1)
}
}
}, [keyboardShown])
return (
<>
{currentSnapPointIndex > 0 ? (
bottomSheetRef?.current?.close()}
>
) : null}
{children}
>
)
}