/**
 * useNativeActionSheet — Cross-Platform Action-Sheet mit garantiert nativem iOS-Bottom-Sheet.
 *
 * Problem: `@expo/react-native-action-sheet`'s Auto-Detection bricht in pnpm-Monorepo wegen
 * `unstable_enablePackageExports: true` in metro.config — Metro resolved auf JS-Fallback
 * (centered pills) statt iOS-native bottom-sheet.
 *
 * Fix: Platform.OS === 'ios' → ActionSheetIOS direkt aus react-native core (immer native).
 * Android → @expo/react-native-action-sheet's Material-Style Custom-Sheet.
 */
import { Platform, ActionSheetIOS } from 'react-native';
import { useActionSheet as usePackageActionSheet } from '@expo/react-native-action-sheet';
import type { ActionSheetIOSOptions } from 'react-native';

type Options = {
  title?: string;
  message?: string;
  options: string[];
  cancelButtonIndex?: number;
  destructiveButtonIndex?: number;
  tintColor?: string;
};

type Callback = (idx: number | undefined) => void;

export function useNativeActionSheet(): {
  showActionSheetWithOptions: (options: Options, callback: Callback) => void;
} {
  const { showActionSheetWithOptions: showPackageSheet } = usePackageActionSheet();

  return {
    showActionSheetWithOptions: (options, callback) => {
      if (Platform.OS === 'ios') {
        const iosOptions: ActionSheetIOSOptions = {
          options: options.options,
          cancelButtonIndex: options.cancelButtonIndex,
          destructiveButtonIndex: options.destructiveButtonIndex,
          title: options.title,
          message: options.message,
          tintColor: options.tintColor,
        };
        ActionSheetIOS.showActionSheetWithOptions(iosOptions, callback);
      } else {
        showPackageSheet(options, callback);
      }
    },
  };
}
