<?php
// manifest.php - Dynamic PWA Manifest
header('Content-Type: application/manifest+json');

require_once 'includes/config.php';
require_once 'includes/db_helper.php';

$pdo = DBHelper::getConnection();
$cfg = [];
try {
    $result = $pdo->query("SELECT setting_key, setting_value FROM settings");
    if ($result) {
        foreach ($result->fetchAll() as $r) {
            $cfg[$r['setting_key']] = $r['setting_value'];
        }
    }
} catch (Exception $e) { $cfg = []; }

$site_title = $cfg['site_title'] ?? 'MSLEE Artist Management';
$primary_color = $cfg['primary_color'] ?? '#ed8002';
$logo = $cfg['logo_url'] ?? '/assets/icons/icon-192.png';

$manifest = [
    'name' => $site_title,
    'short_name' => 'MSLEE',
    'description' => 'Artist Management and Printing Services',
    'start_url' => '/index.php',
    'scope' => '/',
    'display' => 'standalone',
    'theme_color' => $primary_color,
    'background_color' => '#ffffff',
    'orientation' => 'portrait-primary',
    'icons' => [
        ['src' => '/assets/icons/icon-72x72.png', 'sizes' => '72x72', 'type' => 'image/png', 'purpose' => 'any maskable'],
        ['src' => '/assets/icons/icon-96x96.png', 'sizes' => '96x96', 'type' => 'image/png', 'purpose' => 'any maskable'],
        ['src' => '/assets/icons/icon-128x128.png', 'sizes' => '128x128', 'type' => 'image/png', 'purpose' => 'any maskable'],
        ['src' => '/assets/icons/icon-144x144.png', 'sizes' => '144x144', 'type' => 'image/png', 'purpose' => 'any maskable'],
        ['src' => '/assets/icons/icon-152x152.png', 'sizes' => '152x152', 'type' => 'image/png', 'purpose' => 'any maskable'],
        ['src' => '/assets/icons/icon-192x192.png', 'sizes' => '192x192', 'type' => 'image/png', 'purpose' => 'any maskable'],
        ['src' => '/assets/icons/icon-384x384.png', 'sizes' => '384x384', 'type' => 'image/png', 'purpose' => 'any maskable'],
        ['src' => '/assets/icons/icon-512x512.png', 'sizes' => '512x512', 'type' => 'image/png', 'purpose' => 'any maskable']
    ],
    'shortcuts' => [
        ['name' => 'Shop', 'short_name' => 'Shop', 'url' => '/pages/shop.php', 'icons' => [['src' => '/assets/icons/icon-96x96.png', 'sizes' => '96x96']]],
        ['name' => 'Gallery', 'short_name' => 'Gallery', 'url' => '/pages/gallery.php', 'icons' => [['src' => '/assets/icons/icon-96x96.png', 'sizes' => '96x96']]],
        ['name' => 'Contact', 'short_name' => 'Contact', 'url' => '/pages/contact.php', 'icons' => [['src' => '/assets/icons/icon-96x96.png', 'sizes' => '96x96']]]
    ]
];

echo json_encode($manifest, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
?>