import {useSafeAreaInsets} from 'react-native-safe-area-context'

import {IS_LIQUID_GLASS} from '@/env'

// mirrors bluesky's composer offset: the avoiding view measures from the
// sheet's frame, but native sheets don't start at the top of the screen,
// so ios needs the sheet offset added back. the container keeps
// safe-area bottom padding while the keyboard is closed; subtract it
// when open so the toolbar sits flush above the keyboard
export const useKeyboardVerticalOffset = () => {
  const insets = useSafeAreaInsets()
  let offset = insets.bottom * -1
  // ios 26 ditched the sheet gap
  if (IS_LIQUID_GLASS) offset += insets.top
  // iphone se
  else if (insets.top === 20) offset += 40
  // all other iphones on <26
  else offset += insets.top + 10
  return offset
}
