<?php
session_start();

header("Access-Control-Allow-Origin: https://enerliths.com");
header("Access-Control-Allow-Credentials: true");
header("Content-Type: application/json");

include("../config/db.php");

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

$user_id = $_SESSION['user_id'];

$result = $conn->query("SELECT balance, demo_balance FROM users WHERE id = $user_id");
$user = $result->fetch_assoc();

echo json_encode([
    "success" => true,
    "balance" => $user['balance'],
    "demo_balance" => $user['demo_balance']
]);
