<?php
$this->htmlElement('body')->appendAttribute('class', 'vocabs browse');
$escape = $this->plugin('escapeHtml');
$sortHeadings = [
    [
        'label' => $this->translate('Label'),
        'value' => 'label'
    ],
    [
        'label' => $this->translate('Prefix'),
        'value' => 'prefix'
    ],
    [
        'label' => $this->translate('Classes'),
        'value' => 'resource_class_count'
    ],
    [
        'label' => $this->translate('Properties'),
        'value' => 'property_count'
    ]
];
?>

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

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

<?php if (count($vocabularies) > 0): ?>

<div class="browse-controls">
    <?php echo $this->pagination(); ?>
    <?php echo $this->sortSelector($sortHeadings); ?>
</div>
<?php $this->trigger('view.browse.before'); ?>
<table class="tablesaw" data-tablesaw-mode="stack">
    <thead>
        <tr>
            <th><?php echo $this->translate('Label'); ?></th>
            <th><?php echo $this->translate('Prefix'); ?></th>
            <th><?php echo $this->translate('Classes'); ?></th>
            <th><?php echo $this->translate('Properties'); ?></th>
        </tr>
    </thead>
    <tbody>
        <?php foreach ($vocabularies as $vocabulary): ?>
        <tr>
            <td>
                <span class="resource-name">
                    <?php echo $escape($this->translate($vocabulary->label())); ?>
                </span>
                <ul class="actions">
                    <?php if (!$vocabulary->isPermanent()): ?>
                    <?php if ($vocabulary->userIsAllowed('update')): ?>
                    <li><?php echo $vocabulary->link('', 'edit', [
                        'class' => 'o-icon-edit',
                        'aria-label' => $escape($this->translate('Edit')),
                        'title' => $escape($this->translate('Edit')),
                    ]); ?></li>
                    <?php endif; ?>
                    <?php if ($vocabulary->userIsAllowed('delete')): ?>
                    <li><a href="#"
                        data-sidebar-content-url="<?php echo $escape($vocabulary->url('delete-confirm')); ?>"
                        class="o-icon-delete sidebar-content"
                        aria-label="<?php echo $escape($this->translate('Delete')); ?>"
                        title="<?php echo $escape($this->translate('Delete')); ?>"></a></li>
                    <?php endif; ?>
                    <?php endif; ?>
                    <li><a href="#"
                        data-sidebar-content-url="<?php echo $escape($vocabulary->url('show-details')); ?>"
                        class="o-icon-more sidebar-content"
                        aria-label="<?php echo $escape($this->translate('Details')); ?>"
                        title="<?php echo $escape($this->translate('Details')); ?>"></a>
                    </li>
                </ul>
            </td>
            <td><?php echo $escape($this->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">
    <a href="#"
        class="sidebar-close o-icon-close"
        aria-label="<?php echo $escape($this->translate('Close')); ?>"
        title="<?php echo $escape($this->translate('Close')); ?>"></a>
    <div class="sidebar-content"></div>
</div>

<?php else: ?>

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

<?php endif; ?>
