import React from 'react'; import { ActivityIndicator, ScrollView, StyleSheet, View, ViewStyle, } from 'react-native'; import { useStyles, useTheme } from '../../hooks'; import { ComponentStyleProp, LLComponentStyleFn } from '../../types'; import { LLPickerEmptyComponent } from './LLPickerEmptyComponent'; export type LLBasePickerStyles = { pickerContainer: ViewStyle; pickerItemsScrollview: ViewStyle; pickerItemContainer: ViewStyle; pickerLoadingIndicator: ViewStyle; }; export type BasePickerData = { id: string; }; export type LLBasePickerProps = ComponentStyleProp & { visible: boolean; loading?: boolean; packItems: TItem[]; EmptyPickerComponent?: typeof LLPickerEmptyComponent; PickerItemComponent: ({ item }: { item: TItem }) => JSX.Element; PickerHeaderComponent?: () => JSX.Element; }; export function LLBasePicker({ visible, loading, packItems, styles: stylesProp, EmptyPickerComponent = LLPickerEmptyComponent, PickerItemComponent, PickerHeaderComponent, }: LLBasePickerProps) { const { theme } = useTheme(); const pickerStyles = useStyles({ componentStylesFn: getPickerStyles, stylesProp, }); if (!visible) { return null; } return ( {PickerHeaderComponent && PickerHeaderComponent()} {loading ? ( ) : ( {!packItems || packItems.length === 0 ? ( ) : ( packItems.map((item) => ( )) )} )} ); } const getPickerStyles: LLComponentStyleFn = ({ theme }) => StyleSheet.create({ pickerContainer: { minHeight: 300, maxHeight: 300, backgroundColor: theme.secondaryBackground, }, pickerItemsScrollview: { paddingTop: 10, }, pickerItemContainer: { position: 'relative', flexDirection: 'row', flexWrap: 'wrap', justifyContent: 'space-evenly', }, pickerLoadingIndicator: { flex: 1, }, });