<?php
include_once 'config.php';
check_auth();
$account = get_account($_SESSION['user_id']);

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $amount = (float)($_POST['amount'] ?? 0);
    $tx_hash = $_POST['tx_hash'] ?? '';
    
    if ($amount > 0 && $tx_hash) {
        $stmt = db()->prepare("INSERT INTO transactions (account_id, transaction_type, amount, tx_hash, status) VALUES (?, 'deposit', ?, ?, 'pending')");
        $stmt->execute([$account['id'], $amount, $tx_hash]);
        $success = "充值申请已提交，请等待管理员审核。";
    } else {
        $error = "请填写完整信息。";
    }
}

include 'header.php';
?>
<div class="container py-5">
    <div class="row justify-content-center">
        <div class="col-md-6">
            <div class="glass-card p-4 bg-dark">
                <h4 class="text-white mb-4"><i class="bi bi-box-arrow-in-down text-warning me-2"></i> USDT 充值 (TRC20)</h4>
                
                <?php if(isset($success)): ?><div class="alert alert-success"><?php echo $success; ?></div><?php endif; ?>
                <?php if(isset($error)): ?><div class="alert alert-danger"><?php echo $error; ?></div><?php endif; ?>

                <div class="mb-4 text-center p-3 bg-black rounded">
                    <div class="text-secondary small mb-2">转账地址</div>
                    <div class="text-warning fw-bold">TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t</div>
                    <img src="https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t" class="mt-3">
                </div>

                <form method="POST">
                    <div class="mb-3">
                        <label class="form-label text-secondary">充值金额 (USDT)</label>
                        <input type="number" name="amount" step="0.01" class="form-control bg-dark text-white border-secondary" required>
                    </div>
                    <div class="mb-3">
                        <label class="form-label text-secondary">交易哈希 (TxID)</label>
                        <input type="text" name="tx_hash" class="form-control bg-dark text-white border-secondary" placeholder="请输入转账哈希" required>
                    </div>
                    <button type="submit" class="btn btn-warning w-100 fw-bold py-2 mt-3">确认提交</button>
                </form>
                
                <div class="mt-4 small text-secondary">
                    <p class="mb-1">温馨提示：</p>
                    <ul>
                        <li>请勿向上述地址充值任何非 USDT 资产，否则资产将不可找回。</li>
                        <li>最低充值金额 10 USDT。</li>
                        <li>转账完成后请务必填写 TxID。</li>
                    </ul>
                </div>
            </div>
        </div>
    </div>
</div>
<?php include 'footer.php'; ?>
