<?php
/**
 * @var App\Entity\Station $station
 * @var App\Customization $customization
 * @var App\View\GlobalSections $sections
 * @var App\Http\RouterInterface $router
 * @var array $props
 * @var string $nowPlayingArtUri
 */

$this->layout(
    'minimal',
    [
        'page_class' => 'page-station-public-player station-' . $station->short_name,
        'title' => $station->name,
    ]
);

$this->fetch('frontend/public/partials/station-custom', ['station' => $station]);

// Register PWA service worker
$swJsRoute = $router->named('public:sw');

$sections->appendStart('head');
?>
    <link rel="manifest" href="<?= $router->fromHere('public:manifest') ?>">

    <meta name="mobile-web-app-capable" content="yes">
    <meta name="mobile-web-app-status-bar-style" content="black">
    <meta name="mobile-web-app-title" content="<?= $this->e($station->name ?? '') ?>">

    <meta property="og:title" content="<?= $this->e($station->name ?? '') ?>">
    <meta property="og:url" content="<?= $this->e($station->url ?? '') ?>">
    <meta property="og:image" content="<?= $nowPlayingArtUri ?>">

    <meta property="twitter:card" content="player">
    <meta property="twitter:player" content="<?= $router->named(
        routeName: 'public:index',
        routeParams: ['station_id' => $station->short_name, 'embed' => 'social'],
        absolute: true
    ) ?>">
    <meta property="twitter:player:width" content="400">
    <meta property="twitter:player:height" content="200">

    <link rel="alternate" type="application/json+oembed"
          href="<?= $router->named(
              routeName: 'public:oembed',
              routeParams: ['station_id' => $station->short_name, 'format' => 'json'],
              absolute: true
          ) ?>"/>
    <link rel="alternate" type="text/xml+oembed"
          href="<?= $router->named(
              routeName: 'public:oembed',
              routeParams: ['station_id' => $station->short_name, 'format' => 'xml'],
              absolute: true
          ) ?>"/>
<?php
$sections->end();

$sections->appendStart('bodyjs');
?>
    <script>
        ready(() => {
            if ('serviceWorker' in navigator) {
                window.addEventListener('load', function () {
                    navigator.serviceWorker.register('<?=$swJsRoute ?>');
                });
            }
        });
    </script>
<?php
$sections->end();

echo $this->fetch(
    'partials/vue_body',
    [
        'component' => 'Public/FullPlayer',
        'id' => 'public-radio-player',
        'props' => $props,
    ]
);
