<?php
header('Content-Type: application/json');
require_once __DIR__ . '/../includes/lang.php';
require_once __DIR__ . '/../db/config.php';

if (!isset($_SESSION['user_id'])) {
    echo json_encode(['success' => false, 'error' => 'Unauthorized']);
    exit;
}

$symbol = $_GET['symbol'] ?? 'USDT';
$symbol = strtoupper($symbol);

$stmt = db()->prepare("SELECT available FROM user_balances WHERE user_id = ? AND symbol = ?");
$stmt->execute([$_SESSION['user_id'], $symbol]);
$balance = $stmt->fetch();

echo json_encode([
    'success' => true,
    'available' => $balance ? (float)$balance['available'] : 0.00
]);
