import React, { useEffect } from 'react';
import { StyleSheet, Alert } from 'react-native';
import { CouponControl as CouponController, useLanguage } from 'ordering-components/native';
import {
CContainer,
CCWrapper,
CCButton
} from './styles';
import { OInput, OButton, OAlert, OText } from '../shared';
import { useTheme } from 'styled-components/native';
const CouponControlUI = (props: any) => {
const {
couponDefault,
couponInput,
handleButtonApplyClick,
handleRemoveCouponClick,
onChangeInputCoupon,
confirm,
setConfirm
} = props
const theme = useTheme();
const styles = StyleSheet.create({
inputsStyle: {
borderColor: theme.colors.secundaryContrast,
borderRadius: 0,
flex: 1,
marginRight: 30,
height: 42
},
});
const [, t] = useLanguage()
const handleOnAccept = () => {
if (!confirm.error) {
handleRemoveCouponClick && handleRemoveCouponClick()
}
onChangeInputCoupon('')
}
const cleanSetConfirm = () => {
setConfirm({ ...confirm, open: false, error: false })
}
useEffect(() => {
if (confirm.content) {
Alert.alert(
t('COUPON_ERROR', 'Coupon Error'),
confirm.content[0],
[
{
text: t('CANCEL', 'cancel'),
onPress: () => cleanSetConfirm(),
style: 'cancel'
},
{
text: t('ACCEPT', 'Accept'),
onPress: () => cleanSetConfirm()
}
],
{ cancelable: false }
)
}
}, [confirm])
return (
{couponDefault ? (
handleOnAccept()}
>
{`${t('REMOVE_COUPON', 'Remove Coupon')} ${couponDefault}`}
) : (
onChangeInputCoupon(e)}
style={styles.inputsStyle}
/>
handleButtonApplyClick()}
bgColor={theme.colors.primary}
borderColor={theme.colors.primary}
textStyle={{color: 'white'}}
imgRightSrc={null}
text={t('APPLY', 'Apply')}
style={{ borderRadius: 0, height: 42 }}
isDisabled={!couponInput}
/>
)}
)
}
export const CouponControl = (props: any) => {
const couponProp = {
...props,
UIComponent: CouponControlUI
}
return (
)
}