import CountDown2 from '@/core/components/elements/CountDown/CountDown2'
import Image from '@/core/components/elements/Image/Image'
import Link from '@/core/components/elements/Link/Link'
import currencyFormat from '@/core/utils/currencyFormat'
import { createSlug } from '@/core/utils/slug'
import whatsappUrl from '@/core/utils/whatsappUrl'
import ImageNext from 'next/image'
import Product from './Product/Product'
import { useRouter } from 'next/router'
import { useEffect, useState } from 'react'
import odooApi from '@/core/api/odooApi'
const ProductCard = ({ product, simpleTitle, variant = 'vertical' }) => {
const router = useRouter()
const [backgorundFlashSale, setBackgorundFlashSale] = useState(null)
const callForPriceWhatsapp = whatsappUrl('product', {
name: product.name,
url: createSlug('/shop/product/', product.name, product.id, true)
})
useEffect(() => {
const getBackgound = async () => {
const get = await odooApi('GET', '/api/v1/banner?type=flash-sale-background-banner')
setBackgorundFlashSale(get[0].image)
}
getBackgound()
}, [])
if (variant == 'vertical') {
return (
{router.pathname != '/' && product?.flashSale?.id > 0 && (
{product?.lowestPrice.discountPercentage}%
{product?.flashSale?.tag}
)}
{product.variantTotal > 1 && (
{product.variantTotal} Varian
)}
{product?.manufacture?.name ? (
{product.manufacture.name}
) : (
-
)}
{product?.name}
{product?.lowestPrice.discountPercentage > 0 && (
{currencyFormat(product.lowestPrice.price)}
{product?.lowestPrice.discountPercentage}%
)}
{product?.lowestPrice.priceDiscount > 0 ? (
currencyFormat(product?.lowestPrice.priceDiscount)
) : (
Call for price
)}
{product?.stockTotal > 0 && (
Ready Stock
{product?.stockTotal > 5 ? '> 5' : '< 5'}
)}
)
}
if (variant == 'horizontal') {
return (
{product.variantTotal > 1 && (
{product.variantTotal} Varian
)}
{product.flashSale.id > 0 && (
FLASH SALE
)}
{product?.manufacture?.name ? (
{product.manufacture.name}
) : (
-
)}
{product?.name}
{product?.lowestPrice?.discountPercentage > 0 && (
{product?.lowestPrice?.discountPercentage}%
{currencyFormat(product?.lowestPrice?.price)}
)}
{product?.lowestPrice?.priceDiscount > 0 ? (
currencyFormat(product?.lowestPrice?.priceDiscount)
) : (
Call for price
)}
{product?.stockTotal > 0 && (
Ready Stock
{product?.stockTotal > 5 ? '> 5' : '< 5'}
)}
)
}
}
export default ProductCard