<?php

use Illuminate\Support\Facades\Route;

if (!Route::has('lobby') || !request()->is('login') && !request()->is('register')) {
    // Only serve the PWA manifest from pages that should be treated as the app.
    http_response_code(404);
    exit;
}

$config = config('pwa.app');

header('Content-Type', 'application/json', true);

$response = [
    'name' => $config['name'],
    'short_name' => $config['short_name'],
    'description' => 'A couple-friendly online games app',
    'start_url' => $config['start_url'],
    'display' => $config['display'],
    'background_color' => $config['background_color'],
    'theme_color' => $config['theme_color'],
    'orientation' => $config['orientation'],
    'scope' => $config['scope'],
    'icons' => array_map(static function (array $icon): array {
        return [
            'src' => $icon['src'],
            'sizes' => $icon['sizes'],
            'type' => $icon['type'],
            'purpose' => $icon['purpose'],
        ];
    }, $config['icons']),
];

echo json_encode($response, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR);

