"use client"; import { useEffect, useState } from "react"; import Image from "next/image"; import { useApp } from "@/contexts/AppContext"; import { useYTPrice } from "@/hooks/useCollateral"; import { fetchLendingStats } from "@/lib/api/lending"; import { useTokenBySymbol } from "@/hooks/useTokenBySymbol"; const GRADIENT_COLORS: Record = { 'YT-A': 'linear-gradient(135deg, #FF8904 0%, #F54900 100%)', 'YT-B': 'linear-gradient(135deg, #00BBA7 0%, #007A55 100%)', 'YT-C': 'linear-gradient(135deg, #667EEA 0%, #764BA2 100%)', }; const DEFAULT_GRADIENT = 'linear-gradient(135deg, #6B7280 0%, #374151 100%)'; interface RepayHeaderProps { tokenType: string; } export default function RepayHeader({ tokenType }: RepayHeaderProps) { const { t } = useApp(); const [mounted, setMounted] = useState(false); const [availableUsd, setAvailableUsd] = useState(null); const ytToken = useTokenBySymbol(tokenType); const { formattedPrice, isLoading: isPriceLoading } = useYTPrice(ytToken); useEffect(() => { setMounted(true); fetchLendingStats().then((stats) => { if (stats) { const available = stats.totalSuppliedUsd - stats.totalBorrowedUsd; setAvailableUsd(available > 0 ? available.toLocaleString('en-US', { maximumFractionDigits: 0 }) : '0'); } }); }, []); const displayPrice = !mounted || isPriceLoading ? '--' : `$${parseFloat(formattedPrice).toFixed(4)}`; const displayAvailable = availableUsd !== null ? `$${availableUsd}` : '--'; return (
{/* Left Section - Token Icons and Title */}
{/* Overlapping Token Icons */}
{ytToken?.iconUrl ? ( {tokenType} ) : ( tokenType.replace('YT-', '') )}
USDC
{/* Title and Subtitle */}

{tokenType} / USDC

{t("repay.supplyToBorrow")}

{/* Right Section - Stats */}
{/* Price */}
{t("repay.price")} {displayPrice}
{/* Available */}
{t("repay.available")} {displayAvailable}
); }