<?php
include 'header.php';

if (!isset($_SESSION['user_id'])) {
    header("Location: login.php");
    exit;
}

require_once 'db/config.php';
$db = db();
$stmt = $db->prepare("SELECT * FROM users WHERE id = ?");
$stmt->execute([$_SESSION['user_id']]);
$user = $stmt->fetch();

$kyc_status = $user['kyc_status'] ?? 0;
$kyc_labels = [
    0 => __('kyc_none', '未认证'),
    1 => __('kyc_pending', '审核中'),
    2 => __('kyc_approved', '已认证'),
    3 => __('kyc_rejected', '未通过'),
];
$kyc_colors = [0 => '#888', 1 => '#f0b90b', 2 => 'var(--success-color)', 3 => 'var(--danger-color)'];
?>

<main style="padding: 40px 20px; background: #0b0e11; min-height: 100vh;">
    <div style="max-width: 1200px; margin: 0 auto;">
        
        <a href="index.php" class="back-btn"><i class="fas fa-arrow-left"></i> <?php echo __('nav_home', '首页'); ?></a>

        <div style="display: grid; grid-template-columns: 350px 1fr; gap: 30px;">
            <!-- Left Panel -->
            <div>
                <div style="background: var(--card-bg); padding: 40px; border-radius: 24px; border: 1px solid var(--border-color); text-align: center;">
                    <div style="width: 100px; height: 100px; background: linear-gradient(135deg, #4facfe, #00f2fe); border-radius: 50%; display: flex; align-items: center; justify-content: center; margin: 0 auto 20px; font-size: 2.5rem; font-weight: bold; color: white; box-shadow: 0 10px 20px rgba(79,172,254,0.2);">
                        <?php echo strtoupper(substr($user['username'], 0, 1)); ?>
                    </div>
                    <h2 style="margin-bottom: 5px; color: white;"><?php echo $user['username']; ?></h2>
                    <div style="background: rgba(255,255,255,0.05); display: inline-block; padding: 4px 15px; border-radius: 20px; color: var(--text-muted); font-size: 0.85rem; margin-bottom: 25px;">UID: <?php echo $user['uid'] ?: '618120'; ?></div>
                    
                    <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 15px; padding-top: 25px; border-top: 1px solid var(--border-color);">
                        <div>
                            <div style="color: var(--text-muted); font-size: 0.8rem; margin-bottom: 5px;"><?php echo __('credit_score', '信用分'); ?></div>
                            <div style="font-weight: bold; font-size: 1.2rem; color: var(--success-color);"><?php echo $user['credit_score'] ?? 100; ?></div>
                        </div>
                        <div style="border-left: 1px solid var(--border-color);">
                            <div style="color: var(--text-muted); font-size: 0.8rem; margin-bottom: 5px;"><?php echo __('level', '等级'); ?></div>
                            <div style="font-weight: bold; font-size: 1.2rem; color: #f0b90b;">VIP 0</div>
                        </div>
                    </div>
                </div>

                <div style="margin-top: 25px; display: flex; flex-direction: column; gap: 15px;">
                    <div style="background: var(--card-bg); padding: 20px; border-radius: 16px; border: 1px solid var(--border-color);">
                        <a href="kyc.php" style="display: flex; align-items: center; justify-content: space-between; text-decoration: none; color: white;">
                            <div style="display: flex; align-items: center; gap: 15px;">
                                <div style="width: 40px; height: 40px; background: rgba(79,172,254,0.1); border-radius: 10px; display: flex; align-items: center; justify-content: center; color: var(--primary-color);">
                                    <i class="fas fa-id-card"></i>
                                </div>
                                <span style="font-weight: 500;"><?php echo __('kyc_status', '实名认证'); ?></span>
                            </div>
                            <span style="font-size: 0.85rem; font-weight: bold; color: <?php echo $kyc_colors[$kyc_status]; ?>"><?php echo $kyc_labels[$kyc_status]; ?> <i class="fas fa-chevron-right" style="margin-left: 5px; font-size: 10px;"></i></span>
                        </a>
                    </div>

                    <div style="background: var(--card-bg); padding: 20px; border-radius: 16px; border: 1px solid var(--border-color);">
                        <a href="security.php" style="display: flex; align-items: center; justify-content: space-between; text-decoration: none; color: white;">
                            <div style="display: flex; align-items: center; gap: 15px;">
                                <div style="width: 40px; height: 40px; background: rgba(14,203,129,0.1); border-radius: 10px; display: flex; align-items: center; justify-content: center; color: var(--success-color);">
                                    <i class="fas fa-shield-alt"></i>
                                </div>
                                <span style="font-weight: 500;"><?php echo __('security_settings', '安全设置'); ?></span>
                            </div>
                            <i class="fas fa-chevron-right" style="color: var(--text-muted); font-size: 10px;"></i>
                        </a>
                    </div>
                </div>
            </div>

            <!-- Right Panel -->
            <div style="background: var(--card-bg); padding: 40px; border-radius: 24px; border: 1px solid var(--border-color);">
                <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 40px;">
                    <div>
                        <div style="color: var(--text-muted); margin-bottom: 10px; font-size: 14px;"><?php echo __('total_balance', '总资产'); ?> (USDT)</div>
                        <div style="font-size: 3rem; font-weight: bold; letter-spacing: -1px; color: white;">
                            <?php echo number_format($user['balance'] ?? 0, 2); ?>
                        </div>
                        <div style="color: var(--text-muted); font-size: 1rem; margin-top: 5px;">≈ $ <?php echo number_format($user['balance'] ?? 0, 2); ?></div>
                    </div>
                    <div style="display: flex; gap: 15px;">
                        <a href="deposit.php" class="btn-primary" style="padding: 12px 30px; border-radius: 10px; font-weight: bold;"><i class="fas fa-arrow-down" style="margin-right: 10px;"></i> <?php echo __('nav_deposit', '充值'); ?></a>
                        <a href="withdraw.php" class="btn-primary" style="background: #2b3139; padding: 12px 30px; border-radius: 10px; font-weight: bold;"><i class="fas fa-arrow-up" style="margin-right: 10px;"></i> <?php echo __('nav_withdraw', '提现'); ?></a>
                    </div>
                </div>

                <div style="margin-top: 50px;">
                    <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 25px;">
                        <h3 style="margin: 0; font-size: 1.5rem; color: white;"><?php echo __('asset_details', '资产详情'); ?></h3>
                        <a href="#" style="color: var(--primary-color); text-decoration: none; font-size: 14px;"><?php echo __('transaction_records', '账单明细'); ?> <i class="fas fa-history" style="margin-left: 5px;"></i></a>
                    </div>
                    
                    <div style="display: flex; flex-direction: column; gap: 10px;">
                        <?php
                        $coins = [
                            ['symbol' => 'USDT', 'name' => 'Tether', 'balance' => $user['balance'] ?? 0, 'price' => 1.00],
                            ['symbol' => 'BTC', 'name' => 'Bitcoin', 'balance' => 0.0000, 'price' => 65432.10],
                            ['symbol' => 'ETH', 'name' => 'Ethereum', 'balance' => 0.0000, 'price' => 3456.78],
                            ['symbol' => 'BNB', 'name' => 'Binance Coin', 'balance' => 0.0000, 'price' => 589.20],
                            ['symbol' => 'SOL', 'name' => 'Solana', 'balance' => 0.0000, 'price' => 145.60],
                        ];
                        foreach ($coins as $coin):
                        ?>
                        <div style="display: flex; align-items: center; justify-content: space-between; padding: 20px; background: rgba(255,255,255,0.02); border-radius: 16px; border: 1px solid transparent; transition: 0.2s;" onmouseover="this.style.borderColor='var(--border-color)'; this.style.background='rgba(255,255,255,0.04)'" onmouseout="this.style.borderColor='transparent'; this.style.background='rgba(255,255,255,0.02)'">
                            <div style="display: flex; align-items: center; gap: 15px;">
                                <img src="https://raw.githubusercontent.com/spothq/cryptocurrency-icons/master/128/color/<?php echo strtolower($coin['symbol']); ?>.png" width="40" height="40" onerror="this.src='https://cdn-icons-png.flaticon.com/512/2585/2585274.png'">
                                <div>
                                    <div style="font-weight: bold; font-size: 1.1rem; color: white;"><?php echo $coin['symbol']; ?></div>
                                    <div style="font-size: 0.8rem; color: var(--text-muted);"><?php echo $coin['name']; ?></div>
                                </div>
                            </div>
                            <div style="text-align: right;">
                                <div style="font-weight: bold; font-family: monospace; font-size: 1.1rem; color: white;"><?php echo number_format($coin['balance'], $coin['symbol'] === 'USDT' ? 2 : 4); ?></div>
                                <div style="font-size: 0.8rem; color: var(--text-muted);">$ <?php echo number_format($coin['balance'] * $coin['price'], 2); ?></div>
                            </div>
                        </div>
                        <?php endforeach; ?>
                    </div>
                </div>
            </div>
        </div>
    </div>
</main>

<?php include 'footer.php'; ?>
