2026-01-05 13:50:16 +07:00
|
|
|
'use client';
|
2026-03-13 13:54:45 +07:00
|
|
|
|
2026-01-05 13:50:16 +07:00
|
|
|
import React, { useState } from 'react';
|
|
|
|
|
import { parse } from 'date-fns';
|
|
|
|
|
import Link from 'next/link';
|
|
|
|
|
import Image from 'next/image';
|
2026-03-13 13:54:45 +07:00
|
|
|
import CountDown from '@/components/Common/CountDown';
|
2026-01-05 13:50:16 +07:00
|
|
|
import { DealType } from '@/types';
|
|
|
|
|
import { formatCurrency } from '@/lib/formatPrice';
|
|
|
|
|
|
|
|
|
|
type ItemDealProps = {
|
2026-03-13 13:54:45 +07:00
|
|
|
item: DealType;
|
2026-01-05 13:50:16 +07:00
|
|
|
};
|
|
|
|
|
|
2026-03-13 13:54:45 +07:00
|
|
|
const ItemDeal: React.FC<ItemDealProps> = ({ item }) => {
|
2026-01-05 13:50:16 +07:00
|
|
|
const [now] = useState(() => Date.now());
|
2026-03-13 13:54:45 +07:00
|
|
|
const deadline = parse(item.to_time, 'dd-MM-yyyy, h:mm a', new Date()).getTime();
|
2026-01-05 13:50:16 +07:00
|
|
|
|
|
|
|
|
if (deadline <= now) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="product-item">
|
|
|
|
|
<div className="item-deal">
|
2026-03-13 13:54:45 +07:00
|
|
|
<Link href={item.product_info.productUrl} className="product-image position-relative">
|
2026-01-05 13:50:16 +07:00
|
|
|
<Image
|
2026-03-13 13:54:45 +07:00
|
|
|
src={item.product_info.productImage.large}
|
2026-01-05 13:50:16 +07:00
|
|
|
width={250}
|
|
|
|
|
height={250}
|
2026-03-13 13:54:45 +07:00
|
|
|
alt={item.product_info.productName}
|
2026-01-05 13:50:16 +07:00
|
|
|
/>
|
|
|
|
|
</Link>
|
|
|
|
|
<div className="product-info flex-1">
|
2026-03-13 13:54:45 +07:00
|
|
|
<Link href={item.product_info.productUrl}>
|
|
|
|
|
<h3 className="product-title line-clamp-3">{item.product_info.productName}</h3>
|
2026-01-05 13:50:16 +07:00
|
|
|
</Link>
|
|
|
|
|
<div className="product-martket-main flex items-center">
|
2026-03-13 13:54:45 +07:00
|
|
|
{Number(item.product_info.marketPrice) > 0 && (
|
2026-01-05 13:50:16 +07:00
|
|
|
<>
|
|
|
|
|
<p className="product-market-price">
|
2026-03-13 13:54:45 +07:00
|
|
|
{formatCurrency(item.product_info.marketPrice)} đ
|
2026-01-05 13:50:16 +07:00
|
|
|
</p>
|
2026-03-13 13:54:45 +07:00
|
|
|
<div className="product-percent-price">-{item.product_info.price_off || 0}%</div>
|
2026-01-05 13:50:16 +07:00
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
<div className="product-price-main font-bold">
|
2026-03-13 13:54:45 +07:00
|
|
|
{item.product_info.price > '0'
|
|
|
|
|
? `${formatCurrency(item.product_info.price)}đ`
|
2026-01-05 13:50:16 +07:00
|
|
|
: 'Liên hệ'}
|
|
|
|
|
</div>
|
|
|
|
|
<div className="p-quantity-sale">
|
|
|
|
|
<i className="sprite sprite-fire-deal"></i>
|
|
|
|
|
<div className="bg-gradient"></div>
|
|
|
|
|
{(() => {
|
|
|
|
|
const percentRemaining =
|
2026-03-13 13:54:45 +07:00
|
|
|
((Number(item.quantity) - Number(item.sale_quantity)) / Number(item.quantity)) *
|
2026-01-05 13:50:16 +07:00
|
|
|
100;
|
|
|
|
|
|
2026-03-13 13:54:45 +07:00
|
|
|
return <p className="js-line-deal-left" style={{ width: `${percentRemaining}%` }}></p>;
|
2026-01-05 13:50:16 +07:00
|
|
|
})()}
|
|
|
|
|
<span>
|
2026-03-13 13:54:45 +07:00
|
|
|
Còn {Number(item.quantity) - Number(item.sale_quantity)}/{Number(item.quantity)} sản
|
2026-01-05 13:50:16 +07:00
|
|
|
phẩm
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="js-item-deal-time js-item-time-25404">
|
|
|
|
|
<div className="time-deal-page flex items-center justify-center gap-2">
|
2026-03-13 13:54:45 +07:00
|
|
|
<div>Kết thúc sau:</div>
|
|
|
|
|
<CountDown deadline={item.to_time} />
|
2026-01-05 13:50:16 +07:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<a href="javascript:buyNow(25404)" className="buy-now-deal">
|
|
|
|
|
Mua giá sốc
|
|
|
|
|
</a>
|
|
|
|
|
<Link
|
|
|
|
|
href="/bts-gaming-02"
|
|
|
|
|
className="text-deal-item color-primary mt-3 hidden font-bold"
|
|
|
|
|
>
|
|
|
|
|
Xem sản phẩm
|
|
|
|
|
</Link>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default ItemDeal;
|