import {useAnimatedStyle} from "react-native-reanimated"

import {useBottomSheetToolboxInternalContext} from "../context"

export function useAnimatedSheetStyle() {
    const {currentPositionSharedValue, wrapperHeightSharedValue} =
        useBottomSheetToolboxInternalContext()

    return useAnimatedStyle(() => {
        const wrapperHeight = wrapperHeightSharedValue.get()
        if (wrapperHeight === null) return {}

        const translateY = wrapperHeight - currentPositionSharedValue.get()

        return {
            opacity: 1,
            transform: [{translateY}],
        }
    }, [currentPositionSharedValue, wrapperHeightSharedValue])
}
