<?php
require_once __DIR__ . '/auth.php';

$msg = '';

$default_routing = [
    'gateways' => [
        'lg_pay' => [
            'status' => 'active',
            'methods' => [
                'easypaisa' => ['status' => 'active', 'code' => 'PKRPH-EASY', 'label' => 'Easypaisa'],
                'jazzcash' => ['status' => 'active', 'code' => 'PKRPH', 'label' => 'Jazz Cash'],
                'usdt' => ['status' => 'maintenance', 'code' => 'usdt', 'label' => 'USDT']
            ]
        ],
        'io_pay' => [
            'status' => 'active',
            'methods' => [
                'easypaisa' => ['status' => 'active', 'code' => 'PKRPH-EASY', 'label' => 'Easypaisa'],
                'jazzcash' => ['status' => 'active', 'code' => 'PKRPH', 'label' => 'Jazz Cash']
            ]
        ],
        'go_pay' => [
            'status' => 'active',
            'methods' => [
                'easypaisa' => ['status' => 'active', 'code' => 'easypaisa', 'label' => 'Easypaisa', 'payin_code' => 'easypaisa', 'payout_code' => 'easypaisa'],
                'jazzcash' => ['status' => 'active', 'code' => 'jazzcash', 'label' => 'Jazz Cash', 'payin_code' => 'jazzcash', 'payout_code' => 'jazzcash']
            ]
        ]
    ],
    'default_deposit_gateway' => 'lg_pay',
    'payout_gateway' => 'lg_pay'
];

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $lg_app_id = $_POST['lg_app_id'] ?? '';
    $lg_key = $_POST['lg_key'] ?? '';
    $io_app_id = $_POST['io_app_id'] ?? '';
    $io_key = $_POST['io_key'] ?? '';
    $io_payout_key = $_POST['io_payout_key'] ?? '';
    $io_withdraw_pin = $_POST['io_withdraw_pin'] ?? '';
    $base_domain = $_POST['base_domain'] ?? 'https://pakclub24.club';
    
    // GoPay credentials
    $gopay_merchant_id = $_POST['gopay_merchant_id'] ?? '';
    $gopay_payin_api_key = $_POST['gopay_payin_api_key'] ?? '';
    $gopay_payin_api_secret = $_POST['gopay_payin_api_secret'] ?? '';
    $gopay_payout_api_key = $_POST['gopay_payout_api_key'] ?? '';
    $gopay_payout_api_secret = $_POST['gopay_payout_api_secret'] ?? '';
    $gopay_webhook_secret = $_POST['gopay_webhook_secret'] ?? '';
    
    // Construct Routing JSON from form data
    $routing = $default_routing;
    
    // Global Routing config
    $routing['default_deposit_gateway'] = $_POST['default_deposit_gateway'] ?? 'lg_pay';
    $routing['payout_gateway'] = $_POST['payout_gateway'] ?? 'lg_pay';
    
    // LG Pay Method Statuses
    $routing['gateways']['lg_pay']['status'] = $_POST['lg_pay_status'] ?? 'active';
    $routing['gateways']['lg_pay']['methods']['easypaisa']['status'] = $_POST['lg_pay_easypaisa_status'] ?? 'active';
    $routing['gateways']['lg_pay']['methods']['jazzcash']['status'] = $_POST['lg_pay_jazzcash_status'] ?? 'active';
    $routing['gateways']['lg_pay']['methods']['usdt']['status'] = $_POST['lg_pay_usdt_status'] ?? 'active';
    
    // IO Pay Method Statuses
    $routing['gateways']['io_pay']['status'] = $_POST['io_pay_status'] ?? 'active';
    $routing['gateways']['io_pay']['methods']['easypaisa']['status'] = $_POST['io_pay_easypaisa_status'] ?? 'active';
    $routing['gateways']['io_pay']['methods']['jazzcash']['status'] = $_POST['io_pay_jazzcash_status'] ?? 'active';
    
    // GoPay Method Statuses + Editable Trade Type Codes
    $routing['gateways']['go_pay']['status'] = $_POST['go_pay_status'] ?? 'active';
    $routing['gateways']['go_pay']['methods']['easypaisa']['status'] = $_POST['go_pay_easypaisa_status'] ?? 'active';
    $routing['gateways']['go_pay']['methods']['easypaisa']['payin_code'] = $_POST['go_pay_easypaisa_payin_code'] ?? 'easypaisa';
    $routing['gateways']['go_pay']['methods']['easypaisa']['payout_code'] = $_POST['go_pay_easypaisa_payout_code'] ?? 'easypaisa';
    $routing['gateways']['go_pay']['methods']['easypaisa']['code'] = $_POST['go_pay_easypaisa_payin_code'] ?? 'easypaisa';
    $routing['gateways']['go_pay']['methods']['jazzcash']['status'] = $_POST['go_pay_jazzcash_status'] ?? 'active';
    $routing['gateways']['go_pay']['methods']['jazzcash']['payin_code'] = $_POST['go_pay_jazzcash_payin_code'] ?? 'jazzcash';
    $routing['gateways']['go_pay']['methods']['jazzcash']['payout_code'] = $_POST['go_pay_jazzcash_payout_code'] ?? 'jazzcash';
    $routing['gateways']['go_pay']['methods']['jazzcash']['code'] = $_POST['go_pay_jazzcash_payin_code'] ?? 'jazzcash';
    
    $routing_json = json_encode($routing);
    
    $st = $pdo->prepare("INSERT INTO admin_settings (setting_key, setting_value) VALUES (?, ?) ON DUPLICATE KEY UPDATE setting_value = VALUES(setting_value)");
    $st->execute(['lg_app_id', $lg_app_id]);
    $st->execute(['lg_key', $lg_key]);
    $st->execute(['io_app_id', $io_app_id]);
    $st->execute(['io_key', $io_key]);
    $st->execute(['io_payout_key', $io_payout_key]);
    $st->execute(['io_withdraw_pin', $io_withdraw_pin]);
    $st->execute(['base_domain', $base_domain]);
    $st->execute(['gopay_merchant_id', $gopay_merchant_id]);
    $st->execute(['gopay_payin_api_key', $gopay_payin_api_key]);
    $st->execute(['gopay_payin_api_secret', $gopay_payin_api_secret]);
    $st->execute(['gopay_payout_api_key', $gopay_payout_api_key]);
    $st->execute(['gopay_payout_api_secret', $gopay_payout_api_secret]);
    $st->execute(['gopay_webhook_secret', $gopay_webhook_secret]);
    $st->execute(['payment_routing', $routing_json]);
    
    $msg = "Payment Configuration and Routing updated successfully!";
}

// Fetch current
$settings_rows = $pdo->query("SELECT setting_key, setting_value FROM admin_settings WHERE setting_key IN ('lg_app_id', 'lg_key', 'io_app_id', 'io_key', 'io_payout_key', 'io_withdraw_pin', 'base_domain', 'payment_routing', 'gopay_merchant_id', 'gopay_payin_api_key', 'gopay_payin_api_secret', 'gopay_payout_api_key', 'gopay_payout_api_secret', 'gopay_webhook_secret')")->fetchAll(PDO::FETCH_KEY_PAIR);

$lg_app_id = $settings_rows['lg_app_id'] ?? 'PKR3245';
$lg_key = $settings_rows['lg_key'] ?? 'LqpUftaBfNNyOh7YrMSXVlro7zIOj5um';
$io_app_id = $settings_rows['io_app_id'] ?? 'APP47be5aa3465a';
$io_key = $settings_rows['io_key'] ?? '977da4ba9d370ba24e20f73337ed17c7';
$io_payout_key = $settings_rows['io_payout_key'] ?? '2D0B68F4496049956B6E259662FE0155';
$io_withdraw_pin = $settings_rows['io_withdraw_pin'] ?? 'YourSecretWithdrawPin';
$base_domain = $settings_rows['base_domain'] ?? 'https://pakclub24.club';
$gopay_merchant_id = $settings_rows['gopay_merchant_id'] ?? '';
$gopay_payin_api_key = $settings_rows['gopay_payin_api_key'] ?? '';
$gopay_payin_api_secret = $settings_rows['gopay_payin_api_secret'] ?? '';
$gopay_payout_api_key = $settings_rows['gopay_payout_api_key'] ?? '';
$gopay_payout_api_secret = $settings_rows['gopay_payout_api_secret'] ?? '';
$gopay_webhook_secret = $settings_rows['gopay_webhook_secret'] ?? '';
$routing = json_decode($settings_rows['payment_routing'] ?? '{}', true);

if (empty($routing) || !isset($routing['gateways'])) {
    $routing = $default_routing;
}
// Ensure go_pay exists in routing (migration safety)
if (!isset($routing['gateways']['go_pay'])) {
    $routing['gateways']['go_pay'] = $default_routing['gateways']['go_pay'];
}

?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin - Payments Hub</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
* { box-sizing: border-box; margin: 0; padding: 0; }
body { background: #0f172a; color: #f8fafc; font-family: 'Inter', 'Segoe UI', sans-serif; display: flex; min-height: 100vh; font-size: 14px; }
.main-content { flex: 1; padding: 32px; max-width: 1200px; margin: 0 auto; width: 100%; }
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 32px; }
.page-title { font-size: 24px; font-weight: 700; color: #f8fafc; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }

.card { background: #1e293b; border: 1px solid #334155; border-radius: 16px; padding: 32px; margin-bottom: 24px; box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1); }
.card-title { font-size: 16px; font-weight: 600; color: #f1f5f9; margin-bottom: 24px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid #334155; padding-bottom: 16px; }
.card-title span { display: flex; align-items: center; gap: 8px; }
.card-title i { color: #38bdf8; }

.form-group { margin-bottom: 24px; }
.form-label { display: block; font-size: 13px; font-weight: 600; color: #94a3b8; margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.5px; }
.form-control { width: 100%; background: #0f172a; border: 1px solid #334155; color: #f8fafc; padding: 12px 16px; border-radius: 8px; outline: none; transition: 0.2s; font-size: 14px; }
.form-control:focus { border-color: #38bdf8; box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.1); }
select.form-control { appearance: none; cursor: pointer; }

.btn { padding: 12px 24px; border-radius: 8px; border: none; cursor: pointer; font-weight: 600; font-size: 14px; transition: 0.2s; display: inline-flex; align-items: center; gap: 8px; }
.btn-primary { background: #0ea5e9; color: #fff; }
.btn-primary:hover { background: #0284c7; }

.alert { padding: 16px; background: rgba(16, 185, 129, 0.1); color: #10b981; border-radius: 8px; margin-bottom: 24px; border: 1px solid rgba(16, 185, 129, 0.2); font-weight: 500; }

.method-row { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; background: #0f172a; border: 1px solid #334155; border-radius: 8px; margin-bottom: 12px; }
.method-name { font-weight: 600; font-size: 14px; }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 12px; font-weight: 600; margin-left: 8px; }
.badge.lg { background: rgba(56, 189, 248, 0.1); color: #38bdf8; }
.badge.io { background: rgba(245, 158, 11, 0.1); color: #f59e0b; }
</style>
</head>
<body>

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

<div class="main-content">
    <div class="page-header">
        <div class="page-title">Payment Routing Hub</div>
    </div>

    <?php if ($msg): ?>
        <div class="alert"><i class="fa-solid fa-circle-check"></i> <?= htmlspecialchars($msg) ?></div>
    <?php endif; ?>

    <form method="POST">
        <!-- Global Routing -->
        <div class="card" style="border-color: #38bdf8; box-shadow: 0 0 15px rgba(56,189,248,0.1);">
            <div class="card-title">
                <span><i class="fa-solid fa-route"></i> Master Traffic Routing</span>
            </div>
            <div class="grid-2">
                <div class="form-group">
                    <label class="form-label">Base Domain (Callback URL)</label>
                    <input type="url" class="form-control" name="base_domain" value="<?= htmlspecialchars($base_domain) ?>" required>
                    <small style="color: #64748b; margin-top: 8px; display: block;">Used to generate absolute URLs for webhook callbacks.</small>
                </div>
            </div>
            <div class="grid-2">
                <div class="form-group">
                    <label class="form-label">Default Deposit Gateway (Position 1)</label>
                    <select name="default_deposit_gateway" class="form-control">
                        <option value="lg_pay" <?= ($routing['default_deposit_gateway'] ?? '') === 'lg_pay' ? 'selected' : '' ?>>LG Pay</option>
                        <option value="io_pay" <?= ($routing['default_deposit_gateway'] ?? '') === 'io_pay' ? 'selected' : '' ?>>IO Pay</option>
                        <option value="go_pay" <?= ($routing['default_deposit_gateway'] ?? '') === 'go_pay' ? 'selected' : '' ?>>GoPay</option>
                    </select>
                </div>
                <div class="form-group">
                    <label class="form-label">Auto-Withdrawal (Payout) Gateway</label>
                    <select name="payout_gateway" class="form-control">
                        <option value="lg_pay" <?= ($routing['payout_gateway'] ?? '') === 'lg_pay' ? 'selected' : '' ?>>LG Pay</option>
                        <option value="io_pay" <?= ($routing['payout_gateway'] ?? '') === 'io_pay' ? 'selected' : '' ?>>IO Pay</option>
                        <option value="go_pay" <?= ($routing['payout_gateway'] ?? '') === 'go_pay' ? 'selected' : '' ?>>GoPay</option>
                    </select>
                </div>
            </div>
        </div>

        <div class="grid-2">
            <!-- LG Pay Config -->
            <div class="card">
                <div class="card-title">
                    <span><i class="fa-solid fa-building-columns"></i> LG Pay Gateway</span>
                    <select name="lg_pay_status" class="form-control" style="width: auto; padding: 6px 12px; font-size: 13px;">
                        <option value="active" <?= $routing['gateways']['lg_pay']['status'] === 'active' ? 'selected' : '' ?>>Active</option>
                        <option value="maintenance" <?= $routing['gateways']['lg_pay']['status'] === 'maintenance' ? 'selected' : '' ?>>Maintenance</option>
                    </select>
                </div>
                
                <div class="form-group">
                    <label class="form-label">LG Pay App ID</label>
                    <input type="text" class="form-control" name="lg_app_id" value="<?= htmlspecialchars($lg_app_id) ?>" required>
                </div>
                <div class="form-group">
                    <label class="form-label">LG Pay Secret Key</label>
                    <input type="text" class="form-control" name="lg_key" value="<?= htmlspecialchars($lg_key) ?>" required>
                </div>

                <div class="form-label" style="margin-top: 32px;">Individual Method Maintenance</div>
                <div class="method-row">
                    <div class="method-name">Easypaisa <span class="badge lg">PKRPH-EASY</span></div>
                    <select name="lg_pay_easypaisa_status" class="form-control" style="width: 140px; padding: 6px 12px;">
                        <option value="active" <?= $routing['gateways']['lg_pay']['methods']['easypaisa']['status'] === 'active' ? 'selected' : '' ?>>Active</option>
                        <option value="maintenance" <?= $routing['gateways']['lg_pay']['methods']['easypaisa']['status'] === 'maintenance' ? 'selected' : '' ?>>Maintenance</option>
                    </select>
                </div>
                <div class="method-row">
                    <div class="method-name">Jazz Cash <span class="badge lg">PKRPH</span></div>
                    <select name="lg_pay_jazzcash_status" class="form-control" style="width: 140px; padding: 6px 12px;">
                        <option value="active" <?= $routing['gateways']['lg_pay']['methods']['jazzcash']['status'] === 'active' ? 'selected' : '' ?>>Active</option>
                        <option value="maintenance" <?= $routing['gateways']['lg_pay']['methods']['jazzcash']['status'] === 'maintenance' ? 'selected' : '' ?>>Maintenance</option>
                    </select>
                </div>
                <div class="method-row">
                    <div class="method-name">USDT <span class="badge lg">usdt</span></div>
                    <select name="lg_pay_usdt_status" class="form-control" style="width: 140px; padding: 6px 12px;">
                        <option value="active" <?= $routing['gateways']['lg_pay']['methods']['usdt']['status'] === 'active' ? 'selected' : '' ?>>Active</option>
                        <option value="maintenance" <?= $routing['gateways']['lg_pay']['methods']['usdt']['status'] === 'maintenance' ? 'selected' : '' ?>>Maintenance</option>
                    </select>
                </div>
            </div>

            <!-- IO Pay Config -->
            <div class="card">
                <div class="card-title">
                    <span><i class="fa-solid fa-satellite-dish"></i> IO Pay Gateway</span>
                    <select name="io_pay_status" class="form-control" style="width: auto; padding: 6px 12px; font-size: 13px;">
                        <option value="active" <?= $routing['gateways']['io_pay']['status'] === 'active' ? 'selected' : '' ?>>Active</option>
                        <option value="maintenance" <?= $routing['gateways']['io_pay']['status'] === 'maintenance' ? 'selected' : '' ?>>Maintenance</option>
                    </select>
                </div>
                
                <div class="form-group">
                    <label class="form-label">IO Pay App ID</label>
                    <input type="text" class="form-control" name="io_app_id" value="<?= htmlspecialchars($io_app_id) ?>" required>
                </div>
                <div class="form-group">
                    <label class="form-label">IO Pay Secret Key (Payin)</label>
                    <input type="text" class="form-control" name="io_key" value="<?= htmlspecialchars($io_key) ?>" required>
                </div>
                <div class="form-group">
                    <label class="form-label">IO Pay Secret Key (Payout)</label>
                    <input type="text" class="form-control" name="io_payout_key" value="<?= htmlspecialchars($io_payout_key) ?>" required>
                </div>
                <div class="form-group">
                    <label class="form-label">IO Pay Withdraw PIN</label>
                    <input type="text" class="form-control" name="io_withdraw_pin" value="<?= htmlspecialchars($io_withdraw_pin) ?>" required>
                    <small style="color: #64748b; margin-top: 8px; display: block;">Required for processing automated payouts via IO-Pay.</small>
                </div>

                <div class="form-label" style="margin-top: 32px;">Individual Method Maintenance</div>
                <div class="method-row">
                    <div class="method-name">Easypaisa <span class="badge io">easypaisa</span></div>
                    <select name="io_pay_easypaisa_status" class="form-control" style="width: 140px; padding: 6px 12px;">
                        <option value="active" <?= $routing['gateways']['io_pay']['methods']['easypaisa']['status'] === 'active' ? 'selected' : '' ?>>Active</option>
                        <option value="maintenance" <?= $routing['gateways']['io_pay']['methods']['easypaisa']['status'] === 'maintenance' ? 'selected' : '' ?>>Maintenance</option>
                    </select>
                </div>
                <div class="method-row">
                    <div class="method-name">Jazz Cash <span class="badge io">jazz</span></div>
                    <select name="io_pay_jazzcash_status" class="form-control" style="width: 140px; padding: 6px 12px;">
                        <option value="active" <?= $routing['gateways']['io_pay']['methods']['jazzcash']['status'] === 'active' ? 'selected' : '' ?>>Active</option>
                        <option value="maintenance" <?= $routing['gateways']['io_pay']['methods']['jazzcash']['status'] === 'maintenance' ? 'selected' : '' ?>>Maintenance</option>
                    </select>
                </div>
            </div>

            <!-- GoPay Config -->
            <div class="card" style="grid-column: 1 / -1;">
                <div class="card-title">
                    <span><i class="fa-solid fa-bolt" style="color: #10b981;"></i> GoPay Gateway</span>
                    <select name="go_pay_status" class="form-control" style="width: auto; padding: 6px 12px; font-size: 13px;">
                        <option value="active" <?= ($routing['gateways']['go_pay']['status'] ?? '') === 'active' ? 'selected' : '' ?>>Active</option>
                        <option value="maintenance" <?= ($routing['gateways']['go_pay']['status'] ?? '') === 'maintenance' ? 'selected' : '' ?>>Maintenance</option>
                    </select>
                </div>
                
                <div class="grid-2">
                    <div class="form-group">
                        <label class="form-label">Merchant ID</label>
                        <input type="text" class="form-control" name="gopay_merchant_id" value="<?= htmlspecialchars($gopay_merchant_id) ?>">
                    </div>
                    <div class="form-group">
                        <label class="form-label">Webhook Secret</label>
                        <input type="text" class="form-control" name="gopay_webhook_secret" value="<?= htmlspecialchars($gopay_webhook_secret) ?>">
                    </div>
                    <div class="form-group">
                        <label class="form-label">Payin API Key</label>
                        <input type="text" class="form-control" name="gopay_payin_api_key" value="<?= htmlspecialchars($gopay_payin_api_key) ?>">
                    </div>
                    <div class="form-group">
                        <label class="form-label">Payin API Secret</label>
                        <input type="text" class="form-control" name="gopay_payin_api_secret" value="<?= htmlspecialchars($gopay_payin_api_secret) ?>">
                    </div>
                    <div class="form-group">
                        <label class="form-label">Payout API Key</label>
                        <input type="text" class="form-control" name="gopay_payout_api_key" value="<?= htmlspecialchars($gopay_payout_api_key) ?>">
                    </div>
                    <div class="form-group">
                        <label class="form-label">Payout API Secret</label>
                        <input type="text" class="form-control" name="gopay_payout_api_secret" value="<?= htmlspecialchars($gopay_payout_api_secret) ?>">
                    </div>
                </div>

                <div class="form-label" style="margin-top: 32px;">Individual Method Configuration</div>
                <small style="color: #64748b; display: block; margin-bottom: 16px;">You can change the Payin/Payout trade type codes here if GoPay uses different codes than expected.</small>
                
                <?php
                $gp_ep = $routing['gateways']['go_pay']['methods']['easypaisa'] ?? [];
                $gp_jc = $routing['gateways']['go_pay']['methods']['jazzcash'] ?? [];
                ?>
                
                <div class="method-row">
                    <div class="method-name" style="min-width: 100px;">Easypaisa <span class="badge" style="background: rgba(16,185,129,.1); color: #10b981;">gopay</span></div>
                    <div style="display: flex; gap: 8px; align-items: center;">
                        <input type="text" name="go_pay_easypaisa_payin_code" class="form-control" style="width: 120px; padding: 6px 10px; font-size: 13px;" value="<?= htmlspecialchars($gp_ep['payin_code'] ?? 'easypaisa') ?>" placeholder="Payin Code" title="Payin Trade Type">
                        <input type="text" name="go_pay_easypaisa_payout_code" class="form-control" style="width: 120px; padding: 6px 10px; font-size: 13px;" value="<?= htmlspecialchars($gp_ep['payout_code'] ?? 'easypaisa') ?>" placeholder="Payout Code" title="Payout Trade Type">
                        <select name="go_pay_easypaisa_status" class="form-control" style="width: 130px; padding: 6px 12px;">
                            <option value="active" <?= ($gp_ep['status'] ?? '') === 'active' ? 'selected' : '' ?>>Active</option>
                            <option value="maintenance" <?= ($gp_ep['status'] ?? '') === 'maintenance' ? 'selected' : '' ?>>Maintenance</option>
                        </select>
                    </div>
                </div>
                <div class="method-row">
                    <div class="method-name" style="min-width: 100px;">Jazz Cash <span class="badge" style="background: rgba(16,185,129,.1); color: #10b981;">gopay</span></div>
                    <div style="display: flex; gap: 8px; align-items: center;">
                        <input type="text" name="go_pay_jazzcash_payin_code" class="form-control" style="width: 120px; padding: 6px 10px; font-size: 13px;" value="<?= htmlspecialchars($gp_jc['payin_code'] ?? 'jazzcash') ?>" placeholder="Payin Code" title="Payin Trade Type">
                        <input type="text" name="go_pay_jazzcash_payout_code" class="form-control" style="width: 120px; padding: 6px 10px; font-size: 13px;" value="<?= htmlspecialchars($gp_jc['payout_code'] ?? 'jazzcash') ?>" placeholder="Payout Code" title="Payout Trade Type">
                        <select name="go_pay_jazzcash_status" class="form-control" style="width: 130px; padding: 6px 12px;">
                            <option value="active" <?= ($gp_jc['status'] ?? '') === 'active' ? 'selected' : '' ?>>Active</option>
                            <option value="maintenance" <?= ($gp_jc['status'] ?? '') === 'maintenance' ? 'selected' : '' ?>>Maintenance</option>
                        </select>
                    </div>
                </div>
                
                <small style="color: #64748b; margin-top: 12px; display: block;">Webhook URL: <code style="color: #10b981;">https://pakclub24.club/webhook/</code></small>
            </div>
        </div>

        <div style="margin-top: 12px; text-align: center;">
            <button type="submit" class="btn btn-primary" style="font-size: 16px; padding: 16px 48px;"><i class="fa-solid fa-floppy-disk"></i> Save Master Routing Rules</button>
        </div>
    </form>
</div>

</body>
</html>
