<?php
$translate = $this->plugin('translate');
$escape = $this->plugin('escapeHtml');
$this->htmlElement('body')->appendAttribute('class', 'vocabs browse');
?>

<?php echo $this->pageTitle($translate('Vocabularies')); ?>

<div id="page-actions">
    <?php if ($this->userIsAllowed('Omeka\Api\Adapter\VocabularyAdapter', 'create')): ?>
    <?php echo $this->hyperlink($translate('Import new vocabulary'), $this->url(null, ['action' => 'import'], true), ['class' => 'button']); ?>
    <?php endif; ?>
</div>


<div class="browse-controls">
    <?php echo $this->pagination(); ?>
    <?php echo $this->browse()->renderSortSelector('vocabularies'); ?>
</div>
<?php $this->trigger('view.browse.before'); ?>

<?php if (count($vocabularies) > 0): ?>
<table class="tablesaw" data-tablesaw-mode="stack">
    <thead>
        <tr>
            <th><?php echo $translate('Label'); ?></th>
            <th><?php echo $translate('Prefix'); ?></th>
            <th><?php echo $translate('Classes'); ?></th>
            <th><?php echo $translate('Properties'); ?></th>
        </tr>
    </thead>
    <tbody>
        <?php foreach ($vocabularies as $vocabulary): ?>
        <tr>
            <td>
                <?php echo $escape($translate($vocabulary->label())); ?>
                <ul class="actions">
                    <?php $this->trigger('view.browse.actions', ['resource' => $vocabulary]); ?>
                    <?php if (!$vocabulary->isPermanent()): ?>
                    <?php if ($vocabulary->userIsAllowed('update')): ?>
                    <li><?php echo $vocabulary->link('', 'edit', [
                        'class' => 'o-icon-edit',
                        'title' => $translate('Edit'),
                    ]); ?></li>
                    <?php endif; ?>
                    <?php if ($vocabulary->userIsAllowed('delete')): ?>
                    <li><?php echo $this->hyperlink('', '#', [
                        'data-sidebar-content-url' => $vocabulary->url('delete-confirm'),
                        'class' => 'o-icon-delete sidebar-content',
                        'title' => $translate('Delete'),
                    ]); ?></li>
                    <?php endif; ?>
                    <?php endif; ?>
                    <li><?php echo $this->hyperlink('', '#', [
                        'data-sidebar-content-url' => $vocabulary->url('show-details'),
                        'class' => 'o-icon-more sidebar-content',
                        'title' => $translate('Details'),
                    ]); ?></li>
                </ul>
            </td>
            <td><?php echo $escape($translate($vocabulary->prefix())); ?></td>
            <td><?php echo $this->hyperlink($vocabulary->resourceClassCount(), $this->url('admin/id', ['action' => 'classes', 'id' => $vocabulary->id()], true)); ?></td>
            <td><?php echo $this->hyperlink($vocabulary->propertyCount(), $this->url('admin/id', ['action' => 'properties', 'id' => $vocabulary->id()], true)); ?></td>
        </tr>
        <?php endforeach; ?>
    </tbody>
</table>
<?php $this->trigger('view.browse.after'); ?>
<div class="browse-controls">
    <?php echo $this->pagination(); ?>
</div>

<div class="sidebar">
    <?php echo $this->hyperlink('', '#', [
        'class' => 'sidebar-close o-icon-close',
        'title' => $translate('Close'),
    ]); ?>
    <div class="sidebar-content"></div>
</div>

<?php else: ?>

<div class="no-resources">
    <p><?php echo $translate('Omeka could not find any vocabularies.'); ?></p>
</div>

<?php endif; ?>
