import { ReactNode, createContext, useCallback, useContext, useState } from 'react'; import { Pressable, StyleSheet, View } from 'react-native'; import { BottomSheet } from './BottomSheet'; import { Text } from './Text'; import { font, useColors } from './styles'; type SelectOption = { label: string; value: string }; type SelectSheetConfig = { title: string; options: SelectOption[]; selected?: string; onSelect: (value: string) => void; }; type ActionSheetContextType = { showSelectSheet: (config: SelectSheetConfig) => void; }; const ActionSheetContext = createContext(null); export function useActionSheet() { const ctx = useContext(ActionSheetContext); if (!ctx) throw new Error('useActionSheet must be used within ActionSheetProvider'); return ctx; } export function ActionSheetProvider({ children }: { children: ReactNode }) { const [sheetConfig, setSheetConfig] = useState(null); const c = useColors(); const showSelectSheet = useCallback((config: SelectSheetConfig) => { setSheetConfig(config); }, []); const close = () => setSheetConfig(null); const handleSelect = (value: string) => { sheetConfig?.onSelect(value); close(); }; return ( {children} {sheetConfig && ( {sheetConfig.options.map(option => { const isSelected = option.value === sheetConfig.selected; return ( handleSelect(option.value)} style={({ pressed }) => [ styles.option, { borderBottomColor: c.borderSubtle }, pressed && { backgroundColor: c.tagBg }, ]} > {option.label} {isSelected && } ); })} )} ); } const styles = StyleSheet.create({ optionsList: {}, option: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', paddingVertical: 16, borderBottomWidth: StyleSheet.hairlineWidth, }, optionText: { fontSize: font.lg, }, check: { fontSize: font.lg, fontWeight: '600', }, });