import React from 'react' import { useLanguage, useUtils } 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 }, products: Array } export const TaxInformation = (props: taxInformationParams) => { const { data, products } = props const [, t] = useLanguage() const [{ parsePrice }] = useUtils() const isTax = typeof data?.rate === 'number' const TaxFeeString = isTax ? 'tax' : 'fee' const includedOnPriceString = data?.type === 1 ? `(${t('INCLUDED_ON_PRICE', 'Included on price')})` : `(${t('NOT_INCLUDED_ON_PRICE', 'Not included on price')})` return ( {`${data?.name || t('INHERIT_FROM_BUSINESS', 'Inherit from business')} (${typeof data?.rate === 'number' ? `${data?.rate}%` : `${parsePrice(data?.fixed ?? 0)} + ${data?.percentage}%`})`} {data?.description && ( {t('DESCRIPTION', 'Description')}: {data?.description} {data?.type && includedOnPriceString} )} {t(`OTHER_PRODUCTS_WITH_THIS_${TaxFeeString.toUpperCase()}`, `Other products with this ${TaxFeeString}`)}: { products.filter((product: any) => isTax ? (product.tax?.id ? product.tax?.id === data?.id : product.tax?.id === null && data?.id === null) : (product.fee?.id ? product.fee?.id === data?.id : (product.fee?.id === null && data?.id === null))).map(product => ( )) } ) }