<?php
/**
 * Manifest dinámico de Arkora.
 *
 * Genera el JSON adaptado a la ruta donde está instalado el proyecto.
 * Esto evita el error 404 cuando el sitio se instala en una ruta distinta
 * a "/biblioteca/" (la ruta hardcodeada del manifest viejo).
 */

header('Content-Type: application/manifest+json; charset=utf-8');
header('Cache-Control: public, max-age=86400'); // 1 día

// Detectar la ruta base del proyecto.
// Si el manifest se sirve en /miapp/biblioteca/manifest.json, la base es /miapp/biblioteca/
$selfPath = $_SERVER['SCRIPT_NAME'] ?? '/manifest.php';
// Quitar el archivo final (manifest.php) y dejar el directorio
$base = substr($selfPath, 0, strrpos($selfPath, '/') + 1);

$manifest = [
    'name' => 'Arkora',
    'short_name' => 'Arkora',
    'description' => 'Tu biblioteca personal organizada',
    'start_url' => $base . 'admin/',
    'scope' => $base,
    'display' => 'standalone',
    'background_color' => '#f5f1e8',
    'theme_color' => '#2d5040',
    'orientation' => 'portrait',
    'icons' => [
        [
            'src' => $base . 'favicon.png',
            'sizes' => '512x512',
            'type' => 'image/png',
            'purpose' => 'any maskable',
        ],
        [
            'src' => $base . 'favicon.png',
            'sizes' => '192x192',
            'type' => 'image/png',
        ],
    ],
];

echo json_encode($manifest, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
