// Component con hiển thị thông tin chính của sản phẩm
const ProductPrimaryInfo = ({ product, lang, minPromotionPrice }) => {
    // Helper function to check if a value is truthy and not just whitespace
    const hasValue = (value) => value && String(value).trim() !== '';

    const itemCodeValue = product?.item_code;
    const brandValue = lang === 'vi' ? product?.brand_vi : product?.brand_en;
    const originValue = lang === 'vi' ? product?.country_vi : product?.country_en;
    const stockOnHandValue = parseInt(product?.stock_on_hand);

    const showItemCode = hasValue(itemCodeValue);
    const showBrand = hasValue(brandValue);
    const showOrigin = hasValue(originValue);
    const showStockOnHand = stockOnHandValue > 0;
    
    return (
        <>
            <h3 className="fw-bold mb-2">{lang === 'vi' ? product?.Short_Description_VI : product?.Short_Description_EN || product?.description}</h3>
            
            {/* Dòng Mã hàng và Thương hiệu */}
            {(showItemCode || showBrand) && (
                <div className="d-flex justify-content-between text-muted mb-1 small">
                    {showItemCode && (
                        <span><strong>{lang === 'vi' ? "Mã Hàng:" : "Item Code:"}</strong> {itemCodeValue}</span>
                    )}
                    {showBrand && (
                        <span><strong>{lang === 'vi' ? "Thương hiệu:" : "Brand:"}</strong> {brandValue}</span>
                    )}
                </div>
            )}

            {/* Dòng Xuất xứ và Tồn kho */}
            {(showOrigin || showStockOnHand) && (
                <div className="d-flex justify-content-between mb-3 small">
                    {showOrigin && (
                        <span className="text-muted"><strong>{lang === 'vi' ? "Xuất xứ:" : "Origin:"}</strong> {originValue}</span>
                    )}
                    {showStockOnHand && (
                        <span className="text-success"><strong>{lang === 'vi' ? "Tồn kho:" : "On hand:"}</strong> {commonFunc.formatNumber(stockOnHandValue)}</span>
                    )}
                </div>
            )}
            <div className="p-3 rounded" style={{ background: '#f8f9fa' }}>
                {minPromotionPrice && minPromotionPrice < product?.price ? (
                    <div>
                        <span className="text-muted text-decoration-line-through me-2" style={{ fontSize: '1.1rem' }}>
                            {commonFunc.formatNumber(parseInt(product?.price))}đ
                        </span>
                        <span className="fw-bold" style={{ fontSize: '1.8rem', color: '#ee4d2d' }}>
                            {commonFunc.formatNumber(parseInt(minPromotionPrice))}đ
                        </span>
                    </div>
                ) : (
                    <span className="fw-bold" style={{ fontSize: '1.8rem', color: '#333' }}>
                        {commonFunc.formatNumber(parseInt(product?.price))}đ
                    </span>
                )}
            </div>
        </>
    );
};