import React from 'react'; import { StyleSheet } from 'react-native'; import { Option } from './interface'; import createStyles from './styles/FlatSelect.style'; import Checkbox from '../Checkbox'; type StylesType = ReturnType; const CheckboxItem = React.memo( ({ item, multiple, currentVal, testID, searchValue, itemFullContainer, styles, onDisabledPress, onChangeFn, rowHeight, }: { item: Option; multiple: boolean; currentVal: string | string[] | undefined; testID: string; searchValue: string; itemFullContainer: boolean; styles: StylesType; onDisabledPress?: (option: Option) => void; onChangeFn: (values: string | string[]) => void; rowHeight: number; }) => { const isSelected = multiple ? Array.isArray(currentVal) && currentVal.includes(item.value) : currentVal === item.value; const onItemChange = (_value: string | null) => { if (item?.disabled) { onDisabledPress?.(item); return; } if (multiple) { const oldVals = Array.isArray(currentVal) ? currentVal : []; const newVals = _value === item.value ? [item.value, ...oldVals.filter((v) => v !== item.value)] : oldVals.filter((v) => v !== item.value); onChangeFn(newVals); } else { const newVal = _value === item.value ? item.value : undefined; onChangeFn(newVal as string); } }; return ( onDisabledPress?.(item)} /> ); } ); export default CheckboxItem;