Files
nguyencongpc_nextjs/src/components/Deal/ItemDeal.tsx

86 lines
2.7 KiB
TypeScript
Raw Normal View History

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;
}
2026-03-13 17:23:37 +07:00
const remainingQuantity = Number(item.quantity) - Number(item.sale_quantity);
const percentRemaining = (remainingQuantity / Number(item.quantity)) * 100;
2026-01-05 13:50:16 +07:00
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>
2026-03-13 17:23:37 +07:00
2026-01-05 13:50:16 +07:00
<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>
2026-03-13 17:23:37 +07:00
2026-01-05 13:50:16 +07:00
<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>
2026-03-13 17:23:37 +07:00
2026-01-05 13:50:16 +07:00
<div className="product-price-main font-bold">
2026-03-13 13:54:45 +07:00
{item.product_info.price > '0'
2026-03-13 17:23:37 +07:00
? `${formatCurrency(item.product_info.price)} đ`
2026-01-05 13:50:16 +07:00
: 'Liên hệ'}
</div>
2026-03-13 17:23:37 +07:00
2026-01-05 13:50:16 +07:00
<div className="p-quantity-sale">
<i className="sprite sprite-fire-deal"></i>
<div className="bg-gradient"></div>
2026-03-13 17:23:37 +07:00
<p className="js-line-deal-left" style={{ width: `${percentRemaining}%` }}></p>
2026-01-05 13:50:16 +07:00
<span>
2026-03-13 17:23:37 +07:00
Còn {remainingQuantity}/{Number(item.quantity)} sản phẩm
2026-01-05 13:50:16 +07:00
</span>
</div>
2026-03-13 17:23:37 +07:00
2026-01-05 13:50:16 +07:00
<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>
2026-03-13 17:23:37 +07:00
<Link href={item.product_info.productUrl} className="buy-now-deal">
2026-01-05 13:50:16 +07:00
Mua giá sốc
</Link>
</div>
</div>
</div>
);
};
export default ItemDeal;