/**
 * TabataFit Haptics Hook
 * Centralized haptic feedback respecting user settings
 */

import { useCallback } from 'react'
import * as Haptics from 'expo-haptics'
import { useUserStore } from '../stores'

export function useHaptics() {
  const haptics = useUserStore((s) => s.settings.haptics)

  const phaseChange = useCallback(() => {
    if (!haptics) return
    Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Heavy)
  }, [haptics])

  const buttonTap = useCallback(() => {
    if (!haptics) return
    Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Medium)
  }, [haptics])

  const countdownTick = useCallback(() => {
    if (!haptics) return
    Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light)
  }, [haptics])

  const workoutComplete = useCallback(() => {
    if (!haptics) return
    Haptics.notificationAsync(Haptics.NotificationFeedbackType.Success)
  }, [haptics])

  const selection = useCallback(() => {
    if (!haptics) return
    Haptics.selectionAsync()
  }, [haptics])

  return {
    phaseChange,
    buttonTap,
    countdownTick,
    workoutComplete,
    selection,
  }
}
