<?php
// Konfigurasi Integrasi dengan Sistem Existing
define('COCKPIT_API_KEY', 'API-df9da796f43d1241c36bcd39f85970223850134c');
define('COCKPIT_BASE_URL', 'https://www.senatorabadi.web.id/ecommerce_herbal/admin');
define('COCKPIT_ORDERS_COLLECTION', 'pesanan');
define('COCKPIT_PRODUCTS_COLLECTION', 'produk');

// Telegram Notification
define('TELEGRAM_TOKEN', '8770697756:AAH8LDqchM9StZXoIy8noNHyWzEzdKlEXsQ');
define('TELEGRAM_CHAT_ID', '-1003833945138');

// Admin Credentials (bisa dikembangkan ke database)
define('ADMIN_USER', 'adminherbal');
define('ADMIN_PASS_HASH', password_hash('Herbal2024!', PASSWORD_DEFAULT));

// Base URL untuk redirect & API
define('ADMIN_BASE_URL', 'https://www.senatorabadi.web.id/ecommerce_herbal/adminpenjualan');

// Helper: CURL Request ke Cockpit API
function cockpitRequest($endpoint, $method = 'GET', $data = null) {
    $url = COCKPIT_BASE_URL . $endpoint;
    $ch = curl_init();
    $headers = ['Content-Type: application/json'];
    
    if ($method === 'POST' && $data) {
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
    }
    
    curl_setopt_array($ch, [
        CURLOPT_URL => $url,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_CUSTOMREQUEST => $method,
        CURLOPT_HTTPHEADER => $headers,
        CURLOPT_SSL_VERIFYPEER => false
    ]);
    
    $response = curl_exec($ch);
    curl_close($ch);
    return json_decode($response, true);
}

// Helper: Kirim Notifikasi Telegram
function sendTelegram($message) {
    $url = "https://api.telegram.org/bot" . TELEGRAM_TOKEN . "/sendMessage";
    $payload = [
        'chat_id' => TELEGRAM_CHAT_ID,
        'text' => $message,
        'parse_mode' => 'Markdown'
    ];
    
    $ch = curl_init();
    curl_setopt_array($ch, [
        CURLOPT_URL => $url,
        CURLOPT_POST => true,
        CURLOPT_POSTFIELDS => http_build_query($payload),
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_SSL_VERIFYPEER => false
    ]);
    $result = curl_exec($ch);
    curl_close($ch);
    return $result;
}
?>