import { type FC, useState } from 'react'; import { StyleSheet, View, TouchableOpacity } from 'react-native'; import { moderateScale } from 'react-native-size-matters'; import ATypography from '../TTypography/TTypography'; import { defaultScale } from '../../utils/Common'; import { TypographyVariant } from '../TTypography/TTypographyEnum'; import { withTheme, useTheme } from '../../core/theming'; import type { Theme } from '../../utils/types'; interface Props { option1: string; option2: string; onSelectSwitch: any; width: number; theme: Theme; isDisabled?: boolean; } const TSwitchSelector: FC = ({ option1, option2, onSelectSwitch, width, isDisabled = false, }): any => { const { colors } = useTheme(); const [getSelectionMode, setSelectionMode] = useState(2); const stylesWithProp = styles({ colors, width, isDisabled }); const toggleSwitch = (val: any) => { if (isDisabled) { return; } setSelectionMode(val); onSelectSwitch(val); }; return ( toggleSwitch(1)} style={{ ...stylesWithProp.switchBtn, backgroundColor: getSelectionMode === 1 ? colors.primary : isDisabled ? '' : colors.lightgrey, }} > toggleSwitch(2)} style={{ ...stylesWithProp.switchBtn, backgroundColor: getSelectionMode === 2 ? colors.primary : colors.lightgrey, }} > ); }; const styles = (props: { colors: any; width: number; isDisabled: boolean }) => StyleSheet.create({ switchContainer: { height: moderateScale(52, defaultScale), backgroundColor: props.colors.lightgrey, borderRadius: 25, flexDirection: 'row', justifyContent: 'center', padding: moderateScale(2, defaultScale), width: props.width, opacity: props.isDisabled ? 0.5 : 1, }, switchBtn: { flex: 1, margin: moderateScale(5, defaultScale), width: moderateScale(109, defaultScale), height: moderateScale(40, defaultScale), borderRadius: 25, justifyContent: 'center', alignItems: 'center', }, text: { color: props.colors.black, }, }); export default withTheme(TSwitchSelector);