<?php
ob_start();
session_start();
header('Content-Type: application/json; charset=utf-8');

if (!isset($_SESSION['username'])) {
    http_response_code(401);
    echo json_encode(['success' => false, 'msg' => 'Unauthorized']);
    exit;
}

require_once __DIR__ . '/../../wizwizxui-timebot/services/PanelBridge.php';

$panelType = $_POST['panel_type'] ?? 'sanaei';
$panelUrl = trim($_POST['panel_url'] ?? '');
$username = trim($_POST['username'] ?? '');
$password = trim($_POST['password'] ?? '');
$apiToken = trim($_POST['api_token'] ?? '');
$subBase = trim($_POST['subscription_base_url'] ?? '');

$result = PanelBridge::testPanelConnection($panelType, $panelUrl, $username, $password, $apiToken, $subBase);
echo json_encode($result, JSON_UNESCAPED_UNICODE);
