<!DOCTYPE html>
<?php
/**
 * @var \League\Plates\Template\Template $this
 * @var \App\Auth $auth
 * @var \App\Acl $acl
 * @var \App\Http\Router $router
 * @var \App\Session\Flash $flash
 * @var \App\Customization $customization
 * @var \App\Assets $assets
 * @var array $app_settings
 */
?>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">

<?php
if ($title)
    $page_title = $title.' - '.$app_settings['name'];
else
    $page_title = $app_settings['name'];

if (!APP_IN_PRODUCTION)
    $page_title = '('.ucfirst(APP_APPLICATION_ENV).') '.$page_title;
?>
<title><?=$page_title ?></title>

<?=$this->fetch('partials/icons') ?>

<?php
$assets
    ->load('main_header')
    ->load('main_body')
    ->load('theme_'.$customization->getTheme())
    ->addInlineCss($customization->getCustomInternalCss());

echo $assets->css();
echo $assets->js();
?>
</head>
<body class="<?=$page_class ?>">
<?=$assets->inlineJs($request) ?>

<a class="sr-only" href="#content"><?=__('Skip to main content') ?></a>

<header id="header" class="clearfix" data-ma-theme="blue" style="background-image: url('/static/img/header_bg.png');" data-rjs="3">
    <ul class="h-inner">
        <?php if (!empty($sidebar)): ?>
        <li class="hi-trigger ma-trigger" data-ma-action="sidebar-open" data-ma-target="#sidebar">
            <div class="line-wrap">
                <div class="line top"></div>
                <div class="line center"></div>
                <div class="line bottom"></div>
            </div>
        </li>
        <?php endif; ?>

        <li class="logo">
            <a href="<?=$router->named('dashboard') ?>">
                azura<strong>cast</strong> <?php if (!empty($customization->getInstanceName())): ?><small><?=$this->e($customization->getInstanceName()) ?></small><?php endif; ?>
            </a>
        </li>

        <li class="pull-right">
            <ul class="hi-menu" role="toolbar">
                <?=$this->fetch('partials/radio_controls') ?>

                <li class="dropdown">
                    <a data-toggle="dropdown" href="" aria-label="menu" title="<?=__('Open or Close Dropdown Menu') ?>"><i class="him-icon zmdi zmdi-more-vert"></i></a>
                    <ul class="dropdown-menu dm-icon pull-right">
                        <li><a href="<?=$router->named('dashboard') ?>"><i class="zmdi zmdi-home"></i> <?=__('Dashboard') ?></a></li>
                        <?php if ($acl->userAllowed($user, 'view administration')): ?>
                            <li><a href="<?=$router->named('admin:index:index') ?>"><i class="zmdi zmdi-settings"></i> <?=__('System Administration') ?></a></li>
                        <?php endif; ?>
                        <li><a href="<?=$router->named('profile:index') ?>"><i class="zmdi zmdi-account"></i> <?=__('My Account') ?></a></li>
                        <li><a href="<?=$router->named('api_keys:index') ?>"><i class="zmdi zmdi-key"></i> <?=__('My API Keys') ?></a></li>
                        <li class="divider">&nbsp;</li>
                    <?php if ($auth->isMasqueraded()): ?>
                        <li><a href="<?=$router->named('account:endmasquerade') ?>"><i class="zmdi zmdi-power"></i> <?=__('End Session') ?></a></li>
                    <?php else: ?>
                        <li><a href="<?=$router->named('account:logout') ?>"><i class="zmdi zmdi-power"></i> <?=__('Sign Out') ?></a></li>
                    <?php endif; ?>
                    </ul>
                </li>
            </ul>
        </li>
    </ul>
</header>

<section id="main">
    <?php if (!empty($sidebar)): ?>
    <nav id="sidebar" class="sidebar c-overflow" role="navigation">
        <?=$sidebar ?>
    </nav>
    <?php endif; ?>

    <section id="content" <?php if (empty($sidebar)): ?>class="content-alt"<?php endif; ?> role="main">
        <div class="container">
        <?php if ($manual): ?>
            <?=$this->section('content') ?>
        <?php else: ?>
            <?php if ($header): ?>
                <div class="block-header">
                    <h2><?=$header ?></h2>
                </div>
            <?php endif; ?>
            <div class="card">
                <div class="card-header ch-alt">
                    <h2><?=$title ?></h2>
                </div>
                <div class="card-body card-padding">
                    <?=$this->section('content') ?>
                </div>
            </div>
        <?php endif; ?>
        </div>
    </section>
</section>

<footer id="footer" <?php if (empty($sidebar)): ?>class="footer-alt"<?php endif; ?> role="contentinfo">
    <?=__('Powered by %s', '<a href="https://www.azuracast.com/" target="_blank">'.$app_settings['name'].'</a> &bull; '.\App\Version::getVersionText().' &bull; '.(APP_INSIDE_DOCKER ? 'Docker' : 'Traditional').' &bull; PHP '.\PHP_MAJOR_VERSION.'.'.\PHP_MINOR_VERSION) ?><br>
    <?=__('Like our software? <a href="%s" target="_blank">Donate to support AzuraCast!</a>', 'https://www.azuracast.com/donate.html') ?>
</footer>

<div id="radio-player"></div>

<?php if ($flash->hasMessages()): ?>
    <script type="text/javascript" nonce="<?=$assets->getCspNonce() ?>">
        $(function() {
            <?php foreach($flash->getMessages() as $message): ?>
            notify("<?=str_replace(array('"', "\n"), array('\'', '<br>'), $message['text']) ?>", '<?=$message['color'] ?>', false);
            <?php endforeach; ?>
        });
    </script>
<?php endif; ?>
</body>
</html>
