'use client'; import React, { useState } from 'react'; import { parse } from 'date-fns'; import Link from 'next/link'; import Image from 'next/image'; import CounDown from '@/components/Common/CounDown'; import { DealType } from '@/types'; import { formatCurrency } from '@/lib/formatPrice'; type ItemDealProps = { Item: DealType; }; const ItemDeal: React.FC = ({ Item }) => { const [now] = useState(() => Date.now()); // ép kiểu to_time sang số (timestamp) hoặc Date const deadline = parse(Item.to_time, 'dd-MM-yyyy, h:mm a', new Date()).getTime(); // chỉ hiển thị nếu deadline còn lớn hơn thời gian hiện tại if (deadline <= now) { return null; } return (
{Item.product_info.productName}

{Item.product_info.productName}

{Item.product_info.marketPrice > 0 && ( <>

{Item.product_info.marketPrice.toLocaleString()} ₫

-{Item.product_info.price_off || 0}%
)}
{Item.product_info.price > '0' ? `${formatCurrency(Item.product_info.price)}đ` : 'Liên hệ'}
{(() => { const percentRemaining = ((Number(Item.quantity) - Number(Item.sale_quantity)) / Number(Item.quantity)) * 100; return ( <>

); })()} Còn {Number(Item.quantity) - Number(Item.sale_quantity)}/{Number(Item.quantity)} sản phẩm
Kết thúc sau:
Mua giá sốc Xem sản phẩm
); }; export default ItemDeal;