import React, { useState, useEffect } from 'react' import { useUtils, useLanguage, ProductOptionSuboption as ProductSubOptionController } from 'ordering-components/native' import { StyleSheet, I18nManager, Text } from 'react-native' import MaterialCommunityIcon from 'react-native-vector-icons/MaterialCommunityIcons' import { Container, IconControl, QuantityControl, Checkbox, PositionControl, Circle } from './styles' import { OText } from '../shared' import { useTheme } from 'styled-components/native' export const ProductOptionSubOptionUI = (props: any) => { const { state, increment, decrement, balance, option, suboption, toggleSelect, changePosition, disabled } = props const theme = useTheme(); const [, t] = useLanguage() const [{ parsePrice }] = useUtils() const [showMessage, setShowMessage] = useState(false) const handleSuboptionClick = () => { toggleSelect() if (balance === option?.max && option?.suboptions?.length > balance && !(option?.min === 1 && option?.max === 1)) { setShowMessage(true) } } useEffect(() => { if (!(balance === option?.max && option?.suboptions?.length > balance && !(option?.min === 1 && option?.max === 1))) { setShowMessage(false) } }, [balance]) const disableIncrement = option?.limit_suboptions_by_max ? (balance === option?.max || state.quantity === suboption.max) : state.quantity === suboption?.max || (!state.selected && balance === option?.max) const price = option?.with_half_option && suboption?.half_price && state.position !== 'whole' ? suboption?.half_price : suboption?.price return ( handleSuboptionClick()}> {((option?.min === 0 && option?.max === 1) || option?.max > 1) ? ( state?.selected ? ( ) : ( ) ) : ( state?.selected ? ( ) : ( ) )} {suboption?.name} {showMessage && {`${t('OPTIONS_MAX_LIMIT', 'Maximum options to choose')}: ${option?.max}`}} {option?.allow_suboption_quantity && ( {state.quantity} )} {option?.with_half_option && ( changePosition('left')}> changePosition('whole')}> changePosition('right')}> ) } + {parsePrice(price)} ) } const styles = StyleSheet.create({ inverse: { transform: [{ rotateY: '180deg' }] } }) export const ProductOptionSubOption = (props: any) => { const productOptionSubOptionProps = { ...props, UIComponent: ProductOptionSubOptionUI } return ( ) }