<?php
require_once __DIR__ . '/../config/topup.php';
require_once __DIR__ . '/../config/whatsapp.php';

$topupAgentName = agent_public_name((array)$data_admin);
$topupWhatsapp = wa_get_verified_agent_whatsapp($call, $topupAgentName);
if ($topupWhatsapp === '') {
    $topupWhatsapp = wa_get_agent_whatsapp($call, $topupAgentName);
}
$topupWhatsappLabel = $topupWhatsapp !== '' ? wa_mask_number($topupWhatsapp) : 'Nomor WhatsApp belum terdaftar';
?>
<div class="app-page-shell">
    <div class="row g-4">
        <div class="col-lg-7">
            <div class="card app-form-panel">
                <div class="card-header">
                    <h4 class="card-title mb-1">Detail Topup</h4>
                    <p class="text-muted mb-0">Nominal akan otomatis dikonversi ke coin.</p>
                </div>
            <div class="card-body">
                <form action="function/process_topup.php" method="POST">
                    <div class="row g-3">
                        <div class="col-md-6">
                            <label for="AgentReq" class="form-label">Agent Name</label>
                            <input type="text" class="form-control" id="AgentReq" name="AgentReq" value="<?= htmlspecialchars($topupAgentName !== '' ? $topupAgentName : 'Data tidak tersedia', ENT_QUOTES, 'UTF-8') ?>" readonly>
                        </div>
                        <div class="col-md-6">
                            <label for="payment_method" class="form-label">Payment Method</label>
                            <select class="form-select" id="payment_method" name="payment_method" required onchange="updatePaymentInfo()">
                                <option value="<?= topup_qris_method_value() ?>" data-nama="QRIS Otomatis" data-nomor="Scan QR setelah submit" data-qris="1" selected>
                                    QRIS Otomatis
                                </option>
                            </select>
                        </div>
                        <div class="col-12">
                            <label class="form-label">Nomor WhatsApp Agent</label>
                            <div class="form-control bg-light">
                                <?= htmlspecialchars($topupWhatsappLabel, ENT_QUOTES, 'UTF-8') ?>
                            </div>
                            <small class="text-muted">Notifikasi topup akan dikirim ke nomor agent yang sudah terdaftar.</small>
                        </div>
                        <div class="col-md-6">
                            <label for="amount" class="form-label">Amount IDR</label>
                            <input type="number" class="form-control" id="amount" name="amount" placeholder="Enter Amount" required>
                        </div>
                        <div class="col-md-6">
                            <label for="coin" class="form-label">Coin Amount</label>
                            <input type="text" class="form-control" id="coin" name="balance" value="0" readonly>
                        </div>
                    </div>

                    <input type="hidden" id="hidden_nama_rekening" name="nama_rekening">
                    <input type="hidden" id="hidden_nomor_rekening" name="nomor_rekening">

                    <div class="d-grid mt-4">
                        <button class="btn btn-primary" name="topup_pro" type="submit">Buat Invoice QRIS</button>
                    </div>
                </form>
            </div>
        </div>
        </div>
        <div class="col-lg-5">
            <div class="app-side-panel">
                <div class="app-page-icon mb-3">
                    <i class="bi bi-lightning-charge"></i>
                </div>
                <h5>Alur Topup Cepat</h5>
                <p class="text-muted mb-0">Setelah submit, sistem langsung membuat invoice dan QRIS otomatis.</p>
                <ul class="app-check-list">
                    <li><i class="bi bi-check-circle-fill"></i><span>QRIS dibuat otomatis setelah request valid.</span></li>
                    <li><i class="bi bi-check-circle-fill"></i><span>Status pembayaran bisa dipantau dari invoice.</span></li>
                    <li><i class="bi bi-check-circle-fill"></i><span>Saldo masuk setelah pembayaran sukses.</span></li>
                </ul>
            </div>
        </div>
    </div>
</div>
