<?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->getShortName(),
        'title' => $station->getName(),
    ]
);

$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="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-title" content="<?= $this->e($station->getName() ?? '') ?>">

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

    <meta property="twitter:card" content="player">
    <meta property="twitter:player" content="<?= $router->named(
        'public:index',
        ['station_id' => $station->getShortName(), 'embed' => 'social'],
        [],
        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(
              'public:oembed',
              ['station_id' => $station->getShortName(), 'format' => 'json'],
              [],
              true
          ) ?>"/>
    <link rel="alternate" type="text/xml+oembed"
          href="<?= $router->named(
              'public:oembed',
              ['station_id' => $station->getShortName(), 'format' => 'xml'],
              [],
              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,
    ]
);
