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

require_once __DIR__ . '/../includes/functions.php';

$siteName = trim(getSiteSetting('site_name') ?: 'Mutalex Academy');
$siteLogoSetting = trim(getSiteSetting('site_logo') ?: 'fas fa-newspaper');

$logo = [];
if (preg_match('#^(assets/images/|https?://|/assets/images/)#i', $siteLogoSetting)) {
    $src = $siteLogoSetting;
    if (strpos($src, 'assets/images/') === 0) {
        $src = rtrim(BASE_URL, '/') . '/' . ltrim($src, '/');
    } elseif (strpos($src, '/assets/images/') === 0) {
        $src = rtrim(BASE_URL, '/') . $src;
    }
    $logo = [
        'type' => 'image',
        'src' => $src,
    ];
} elseif (preg_match('#^\s*<svg[\s\S]*</svg>\s*$#i', $siteLogoSetting)) {
    $logo = [
        'type' => 'svg',
        'svg' => $siteLogoSetting,
    ];
} else {
    $logo = [
        'icon' => $siteLogoSetting,
    ];
}

$payload = [
    'site_name' => $siteName,
    'site_logo' => $logo,
    'home_url' => rtrim(BASE_URL, '/') . '/home.php',
];

echo json_encode($payload, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
