<?php
$translate = $this->plugin('translate');
$this->htmlElement('html')->setAttribute('lang', $this->lang());
$this->headMeta()->setCharset('utf-8');
$this->headMeta()->appendName('viewport', 'width=device-width, initial-scale=1');
$this->headTitle($this->setting('installation_title', 'Omeka S'))->setSeparator(' · ');
$this->headLink()->prependStylesheet($this->assetUrl('css/style.css', 'Omeka'));
$this->headLink()->prependStylesheet($this->assetUrl('css/iconfonts.css', 'Omeka'));
$this->headLink()->prependStylesheet($this->assetUrl('vendor/chosen-js/chosen.css', 'Omeka'));
$this->headLink()->prependStylesheet($this->assetUrl('vendor/tablesaw/tablesaw.stackonly.css', 'Omeka'));
$this->headLink()->prependStylesheet('//fonts.googleapis.com/css?family=Source+Code+Pro%7CLato:400,400italic,700,700italic');
$this->headScript()->prependFile($this->assetUrl('js/admin.js', 'Omeka'));
$this->headScript()->prependFile($this->assetUrl('js/global.js', 'Omeka'));
$this->headScript()->prependFile($this->assetUrl('js/chosen-options.js', 'Omeka'));
$this->headScript()->prependFile($this->assetUrl('vendor/chosen-js/chosen.jquery.js', 'Omeka'));
$this->headScript()->prependFile($this->assetUrl('vendor/tablesaw/tablesaw.stackonly.jquery.js', 'Omeka'));
$this->headScript()->prependFile($this->assetUrl('vendor/jquery/jquery.min.js', 'Omeka'));
$this->jsTranslate();

$escape = $this->plugin('escapeHtml');
$siteNav = (string) $this->navigation('Laminas\Navigation\AdminSite')->menu();
$resourceNav = (string) $this->navigation('Laminas\Navigation\AdminResource')->menu();
$adminNav = (string) $this->navigation('Laminas\Navigation\AdminGlobal')->menu();
$moduleNav = (string) $this->navigation('Laminas\Navigation\AdminModule')->menu();
$this->trigger('view.layout');
?>
<?php echo $this->doctype(); ?>
<?php echo $this->htmlElement('html'); ?>
    <head>
        <?php echo $this->headMeta(); ?>
        <?php echo $this->headTitle(); ?>
        <?php echo $this->headLink(); ?>
        <?php echo $this->headStyle(); ?>
        <?php echo $this->headScript(); ?>
    </head>
    <?php echo $this->htmlElement('body'); ?>
        <a href="#content" class="skip"><?php echo $translate('Skip to main content'); ?></a>
        <div class="flex">
            <header>
                <div class="logo"><a href="<?php echo $this->url('admin'); ?>"><?php echo $escape($this->setting('installation_title', 'Omeka S')); ?></a></div>
                <div id="mobile-nav">
                    <a href="#" class="o-icon-menu button"><span class="screen-reader-text"><?php echo $translate('Navigation menu'); ?></span></a>
                    <a href="#" class="o-icon-search button"><span class="screen-reader-text"><?php echo $translate('Search site'); ?></span></a>
                    <a href="#" class="o-icon-user button"><span class="screen-reader-text"><?php echo $translate('User menu'); ?></span></a>
                </div>
                <div id="user">
                    <?php if ($this->identity()): ?>
                    <p class="user-id">
                        <?php echo $this->hyperlink($this->identity()->getName(), $this->url('admin/id', ['controller' => 'user', 'id' => $this->identity()->getId()]),['class' => 'user-show o-icon-user button']); ?>
                        <?php echo $this->plugin('hyperlink')->raw('<span class="sr-only">' . $translate('Edit user') . '</span>', $this->url('admin/id', ['controller' => 'user', 'action' => 'edit', 'id' => $this->identity()->getId()], ['fragment' => 'user-settings']), ['class' => 'user-settings button', 'title' => $translate('Edit user')]); ?>
                    </p>
                    <p class="logout"><a href="<?php echo $this->url('logout'); ?>"><?php echo $translate('Logout'); ?></a></p>
                    <?php else: ?>
                    <p><?php echo $translate('not logged in'); ?></p>
                    <?php endif; ?>
                </div>
                <div id="search">
                    <form action="" id="search-form" aria-label="<?php echo $translate('Search'); ?>" role="search">
                        <?php $searchValue = isset($_GET['fulltext_search']) ? $_GET['fulltext_search'] : ''; ?>
                        <input type="text" name="fulltext_search" id="fulltext-search" value="<?php echo $escape($searchValue); ?>" aria-label="<?php echo $translate('Query'); ?>">
                        <button type="button" id="advanced" aria-label="<?php echo $translate('Advanced options'); ?>" title="<?php echo $translate('Advanced options'); ?>" aria-expanded="false" aria-controls="advanced-options"></button>
                        <fieldset id="advanced-options">
                            <legend><?php echo $translate('Resource type'); ?></legend>
                            <input type="radio" name="resource-type" id="search-items" value="item" checked="checked"
                                data-input-placeholder="<?php echo $escape($translate('Search items')); ?>"
                                data-action="<?php echo $escape($this->url('admin/default', ['controller' => 'item', 'action' => 'browse'])); ?>">
                            <label for="search-items"><?php echo $translate('Items'); ?></label>
                            <input type="radio" name="resource-type" id="search-item-sets" value="item-set"
                                data-input-placeholder="<?php echo $escape($translate('Search item sets')); ?>"
                                data-action="<?php echo $escape($this->url('admin/default', ['controller' => 'item-set', 'action' => 'browse'])); ?>">
                            <label for="search-item-sets"><?php echo $translate('Item sets'); ?></label>
                            <input type="radio" name="resource-type" id="search-media" value="media"
                                data-input-placeholder="<?php echo $escape($translate('Search media')); ?>"
                                data-action="<?php echo $escape($this->url('admin/default', ['controller' => 'media', 'action' => 'browse'])); ?>">
                            <label for="search-media"><?php echo $translate('Media'); ?></label>
                        </fieldset>
                        <button type="submit" id="search-submit" aria-label="<?php echo $translate('Submit'); ?>" title="<?php echo $translate('Submit'); ?>"><span class="o-icon-search" aria-hidden="true"></span></button>
                    </form>
                </div>
                <nav id="menu" aria-label="<?php echo $translate('Navigation menu'); ?>">
                    <?php echo $siteNav; ?>
                    <?php if (isset($site)): ?>
                    <nav id="site-nav">
                        <h5><?php echo $site->link($site->title(), 'show'); ?></h5>
                        <?php echo $this->hyperlink('', $site->siteUrl(), ['class' => 'o-icon-external public', 'target' => '_blank', 'title' => $translate('View public site')]); ?>
                    <?php echo $site->adminNav()->menu(); ?>
                    </nav>
                    <?php endif; ?>
                    <h5><?php echo $translate('Resources') ?></h5>
                    <?php echo $resourceNav; ?>
                    <?php if ($adminNav): ?>
                    <h5><?php echo $translate('Admin') ?></h5>
                    <?php echo $adminNav ?>
                    <?php endif; ?>
                    <?php if ($moduleNav): ?>
                    <h5><?php echo $translate('Modules') ?></h5>
                    <?php echo $moduleNav ?>
                    <?php endif; ?>
                </nav>
            </header>
            <script>
                $('#search-form').on('click', '#advanced', function() {
                    var toggleButton = $(this);
                    $('#advanced-options').slideToggle('slow');
                    toggleButton.toggleClass('open');
                    if (toggleButton.hasClass('open')) {
                        toggleButton.attr('aria-expanded', 'true');
                    } else {
                        toggleButton.attr('aria-expanded', 'false');
                    }
                });
            </script>

            <div id="content" role="main">
                <?php echo $this->messages(); ?>
                <?php echo $this->content; ?>
            </div>
        </div>
        <footer>
            <p class="site-version"><a href="https://omeka.org/s"><?php echo $translate('Omeka S'); ?></a> <span class="version-number"><?php echo sprintf($translate('version %s'), Omeka\Module::VERSION)?></span></p>
            <a href="<?php echo $this->url('admin/default', ['controller' => 'system-info']); ?>"><?php echo $translate('System information'); ?></a>
            <a href="https://omeka.org/s/docs/user-manual"><?php echo $translate('User manual'); ?></a>
            <a href="https://forum.omeka.org/"><?php echo $translate('Support forums'); ?></a>
        </footer>
    </body>
</html>
