import { useEffect, useMemo, useState, type ReactNode } from 'react'; import { Modal, Pressable, ScrollView, StyleSheet, View } from 'react-native'; import { FONT, RADIUS, withAlpha } from '../theme/palette'; import { useTheme } from '../theme/ThemeProvider'; import { Button } from './Button'; import { Icon } from './Icon'; import { Input } from './Input'; import { Text } from './Text'; export interface SheetOption { value: string; label: string; detail?: string; leading?: ReactNode; } /** * Native page sheet with a searchable list of options that toggle on tap, * styled like the web client's multi-select dropdown. */ export function MultiSelectSheet({ visible, title, options, selected, onCancel, onDone, saving, error, emptyMessage = 'Nothing to choose from', }: { visible: boolean; title: string; options: SheetOption[]; selected: string[]; onCancel: () => void; onDone: (values: string[]) => void; saving?: boolean; error?: string | null; emptyMessage?: string; }) { const theme = useTheme(); const [values, setValues] = useState(selected); const [query, setQuery] = useState(''); useEffect(() => { if (visible) { setValues(selected); setQuery(''); } }, [visible, selected]); const filtered = useMemo(() => { const q = query.trim().toLowerCase(); if (!q) return options; return options.filter((o) => o.label.toLowerCase().includes(q) || o.value.toLowerCase().includes(q)); }, [options, query]); const toggle = (v: string) => setValues((prev) => (prev.includes(v) ? prev.filter((x) => x !== v) : [...prev, v])); return ( Cancel {title}