<?php
$escape = $this->plugin('escapeHtml');
$siteNav = (string) $this->navigation('Zend\Navigation\AdminSite')->menu();
$globalNav =
    '<h5>' . $this->translate('Resources') . '</h5>' . $this->navigation('Zend\Navigation\AdminResource')->menu() .
    '<h5>' . $this->translate('Admin') . '</h5>' . $this->navigation('Zend\Navigation\AdminGlobal')->menu();
?>
<header>
    <div class="logo"><a href="<?php echo $this->url('admin'); ?>"><?php echo $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 $this->translate('Navigation Menu'); ?></span></a>
        <a href="#" class="o-icon-search button"><span class="screen-reader-text"><?php echo $this->translate('Search Site'); ?></span></a>
        <a href="#" class="o-icon-user button"><span class="screen-reader-text"><?php echo $this->translate('User Menu'); ?></span></a>
    </div>
    <div id="user">
        <?php if ($this->identity()): ?>
        <p class="user-id"><?php echo sprintf($this->translate('Signed in as %s'),  '<a href="' . $this->url('admin/id', [
            'controller' => 'user',
            'id' => $this->identity()->getId(),
        ]) . '">' . $escape($this->identity()->getName()) . '</a>'); ?></p>
        <p class="logout"><a href="<?php echo $this->url('logout'); ?>"><?php echo $this->translate('Logout'); ?></a></p>
        <?php else: ?>
        <p><?php echo $this->translate('not logged in'); ?></p>
        <?php endif; ?>
    </div>
    <div id="search">
        <form action="" id="search-form">
            <?php $searchValue = isset($_GET['property'][0]['in'][0]) ? $_GET['property'][0]['in'][0] : ''; ?>
            <input type="text" name="property[0][in][]" value="<?php echo $escape($searchValue); ?>">
            <button type="button" id="advanced"><?php echo $this->translate('Advanced Options'); ?></button>
            <button type="submit"><?php echo $this->translate('Search'); ?></button>
            <fieldset id="advanced-options">
                <legend><?php echo $this->translate('Resource Type'); ?></legend>
                <input type="radio" name="resource-type" id="search-items" value="item" checked="checked"
                    data-input-placeholder="<?php echo $escape($this->translate('Search Items')); ?>"
                    data-action="<?php echo $escape($this->url('admin/default', ['controller' => 'item', 'action' => 'browse'])); ?>">
                <label for="search-items"><?php echo $this->translate('Items'); ?></label>
                <input type="radio" name="resource-type" id="search-item-sets" value="item-set"
                    data-input-placeholder="<?php echo $escape($this->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 $this->translate('Item Sets'); ?></label>
                <input type="radio" name="resource-type" id="search-media" value="media"
                    data-input-placeholder="<?php echo $escape($this->translate('Search Media')); ?>"
                    data-action="<?php echo $escape($this->url('admin/default', ['controller' => 'media', 'action' => 'browse'])); ?>">
                <label for="search-media"><?php echo $this->translate('Media'); ?></label>
            </fieldset>
        </form>
    </div>
    <nav id="menu" role="navigation">
        <?php echo $siteNav; ?>
        <?php if (isset($site)): ?>
        <nav id="site-nav">
            <h5>
                <?php echo $site->link($site->title(), 'show'); ?>
            </h5>
            <a href="<?php echo $site->siteUrl(); ?>" class="o-icon-external public" target="_blank" aria-label="<?php echo $this->translate('View public site'); ?>" title="<?php echo $this->translate('View public site'); ?>"></a>
        <?php echo $site->adminNav()->menu(); ?>
        </nav>
        <?php endif; ?>
        <?php echo $globalNav; ?>
        <?php if ($this->navigation('Zend\Navigation\AdminModule')->count() > 0): ?>
        <h5><?php echo $this->translate('Modules'); ?></h5>
        <?php echo $this->navigation('Zend\Navigation\AdminModule')->menu(); ?>
        <?php endif; ?>
    </nav>
</header>

<script>
    $('#advanced').click(function(event) {
        event.preventDefault();
        $('#advanced-options').slideToggle('slow');
    });
</script>
