import { TouchableOpacity, View } from "react-native"; import { type SelectedItem } from "./type"; import type ISelectSheetProps from "./type"; import stylesheet, { useStyles } from "./stylesheet"; import { NCoreUIKitLocalize, NCoreUIKitTheme } from "../../core/hooks"; import { CheckIcon } from "lucide-react-native"; import BottomSheet from "../bottomSheet"; import TextInput from "../textInput"; import Loading from "../loading"; import Button from "../button"; import Text from "../text"; import CheckBox from "../checkBox"; function SelectSheet({ LoadingIconComponentProp, isWorkWithRealtime, isShowTools = true, mainSelectedItems, moreLoadThreshold, isMultipleSelect, setIsMoreLoading, renderOptionIcon, bottomSheetProps, bottomSheetRef, customLocalize, setSearchText, isMoreLoading, selectBoxKey, setIsLoading, selectObject, keyExtractor, searchedData, isSearchable, customTheme, setIsActive, onMoreLoad, renderItem, searchText, maxChoice, minChoice, isLoading, selectAll, cleanAll, isActive, cancel, title, data, ok }: ISelectSheetProps) { const { radiuses, colors, spaces } = NCoreUIKitTheme.useContext(customTheme); const { localize } = NCoreUIKitLocalize.useContext(customLocalize); const { moreLoadingContainer: moreLoadingContainerDynamicStyle, checkIconContainer: checkIconContainerDynamicStyle, loadingContainer: loadingContainerDynamicStyle, contentContainer: contentContainerDynamicStyle, headerContainer: headerContainerDynamicStyle, bottomContainer: bottomContainerDynamicStyle, toolsContainer: toolsContainerDynamicStyle, itemContainer: itemContainerDynamicStyle, cancelButton: cancelButtonDynamicStyle, headerTitle: headerTitleDynamicStyle, okButton: okButtonDynamicStyle } = useStyles({ isSearchable, radiuses, spaces, colors }); const renderBottomSheetContent = () => { if(isLoading) { return {LoadingIconComponentProp ? : } ; } const currentData = searchText && searchText.length ? searchedData : data; return { currentData.map((item: T & SelectedItem | SelectedItem, index: number) => { const isSelected = mainSelectedItems.findIndex((sI: SelectedItem) => { return sI.__key === item.__key; }) !== -1; if(renderItem) { return renderItem({ key: keyExtractor(item as T & SelectedItem, index), onSelect: (sItem) => { selectObject(sItem); }, selectedItems: mainSelectedItems, setIsMoreLoading, setIsLoading, isSelected, searchText, index, item, data }); } let isDisabled = false; if(isMultipleSelect && !isSelected && maxChoice !== -1) { if(!maxChoice) { throw new Error("If you want to use the \"isMultipleSelect\" prop, you must be provide \"maxChoice\" prop."); } if(mainSelectedItems.length >= maxChoice) { isDisabled = true; } } return { if(isDisabled) { return; } selectObject(item); }} > {renderOptionIcon ? renderOptionIcon({ item, index }) : null} {item.__title} {isSelected ? : null} {isDisabled ? : null} ; }) } {renderMoreLoading()} ; }; const renderBottomSheetSearchInput = () => { if(!isSearchable) { return null; } return { setSearchText(text); }} />; }; const renderTools = () => { if(!isShowTools) { return null; } if(!isMultipleSelect) { return null; } if(minChoice && maxChoice !== -1) { return null; } return {!minChoice ? { cleanAll(); }} /> : null} {maxChoice === -1 ? { selectAll(); }} /> : null} ; }; const renderBottomSheetHeader = () => { return {title} {renderBottomSheetSearchInput()} {renderTools()} ; }; const renderBottomSheetBottom = () => { if(isWorkWithRealtime) { return null; } return