<?php
$this->htmlElement('body')->appendAttribute('class', 'sites add');
$this->headScript()->appendFile($this->assetUrl('js/jstree/jstree.min.js', 'Omeka'));
$form->prepare();
$this->headScript()->appendFile($this->assetUrl('js/site-navigation.js', 'Omeka'));
$this->headLink()->appendStylesheet($this->assetUrl('css/jstree.css', 'Omeka'));
$escape = $this->plugin('escapeHtml');
?>
<?php echo $this->pageTitle(sprintf($this->translate('Navigation'), $site->title())); ?>

<?php echo $this->form()->openTag($form); ?>
<?php echo $this->formCollection($form, false); ?>

<div id="page-actions">
    <button><?php echo $this->translate('Save'); ?></button>
</div>

<div id="nav-tree"
    data-link-form-url="<?php echo $escape($this->url('admin/site/slug/action', ['action' => 'navigation-link-form'], true)); ?>"
    data-jstree-data="<?php echo $escape(json_encode($navTree)); ?>">
</div>
<div id="nav-selector" class="active sidebar">
    <div class="field">
        <label for="nav-custom-links"><?php echo $this->translate('Add a custom link'); ?></label>
        <div id="nav-custom-links">
            <?php foreach ($this->navigationLink()->getCustomTypes() as $type): ?>
            <?php $name = $this->navigationLink()->getName($type); ?>
            <button
                type="button"
                data-type="<?php echo $escape($type); ?>"
                data-value="<?php echo $escape($type); ?>" class="option"><?php echo $escape($this->translate($name)); ?></button>
            <?php endforeach; ?>
        </div>
    </div>
    <div class="field">
        <label><?php echo $this->translate('Add a link to a site page'); ?></label>
        <?php if ($pages = $site->notLinkedPages()): ?>
        <input type="text" class="page-selector-filter" placeholder="Filter pages">
        <div id="nav-page-links">
        <?php foreach ($pages as $page): ?>
            <button class="nav-page-link option"
                type="button"
                data-type="page"
                data-label="<?php echo $escape($page->title()); ?>"
                data-id="<?php echo $escape($page->id()); ?>"
                data-slug="<?php echo $escape($page->slug()); ?>">
                <?php echo sprintf('%s (%s)', $page->title(), $page->slug()); ?>
            </button>
        <?php endforeach; ?>
        </div>
        <?php else: ?>
        <p>There are no available pages.</p>
        <?php endif; ?>
    </div>
</div>

<?php echo $this->form()->closeTag(); ?>
