import React from 'react' import { useLanguage } from 'ordering-components/native' import { SingleProductCard } from '../SingleProductCard' import { TaxInformationContainer, ProductContainer } from './styles' import { OText } from '../shared' interface taxInformationParams { data: { name: string, description?: string, rate: string | number, type: number, fixed?: number, percentage?: number, id: number, discounts?: any }, products: Array, type: string } export const TaxInformation = (props: taxInformationParams) => { const { data, products, type } = props const [, t] = useLanguage() const includedOnPriceString = data?.type === 1 ? `(${t('INCLUDED_ON_PRICE', 'Included on price')})` : `(${t('NOT_INCLUDED_ON_PRICE', 'Not included on price')})` const getFilterValidation = (product: any) => { return ( type === 'tax' ? (product.tax?.id ? product.tax?.id === data?.id : product.tax?.id === null && data?.id === null) : type === 'fee' ? (product.fee?.id ? product.fee?.id === data?.id : (product.fee?.id === null && data?.id === null)) : Object.keys(data?.discounts ?? {}).map(code => code.includes(product?.code)) && product?.offers?.find(offer => offer?.name === data?.name) ) } const getTypeString = () => { return ( type === 'offer_target_1' ? t('PRODUCT_DISCOUNT', 'Product discount') : type === 'tax' ? t('TAX', 'Tax') : t('Fee', 'Fee') ) } return ( {!!data?.description ? ( {t('DESCRIPTION', 'Description')}: {data?.description} {data?.type && !type?.includes('offer') && includedOnPriceString} ) : ( {t('WITHOUT_DESCRIPTION', 'Without description')} )} {!(type === 'offer_target_2' || type === 'offer_target_3') && ( <> {t('OTHER_PRODUCTS_WITH_THIS', 'Other products with this')} {getTypeString()}: { products.filter((product: any) => getFilterValidation(product)).map(product => ( )) } )} ) }