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

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

<div id="page-actions">
    <?php if ($this->userIsAllowed('Omeka\Entity\Site', 'create')): ?>
    <?php echo $this->hyperlink($translate('Add new site'), $this->url('admin/site/add'), ['class' => 'button']); ?>
    <?php endif; ?>
</div>

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

<?php if (count($sites) > 0): ?>
<table class="tablesaw" data-tablesaw-mode="stack">
    <thead>
        <tr>
            <th><?php echo $translate('Title'); ?></th>
            <?php echo $this->browse()->renderHeaderRow('sites'); ?>
        </tr>
    </thead>
    <tbody>
        <?php foreach ($sites as $site): ?>
        <tr>
            <td>
                <?php echo $site->link($site->title(), 'show'); ?>
                <?php if (!$site->isPublic()): ?>
                    <span class="o-icon-private" aria-label="<?php echo $translate('Private'); ?>"></span>
                <?php endif; ?>
                <ul class="actions">
                    <?php $this->trigger('view.browse.actions', ['resource' => $site]); ?>
                    <li><?php echo $this->hyperlink('', $site->siteUrl(), [
                        'target' => '_blank',
                        'class' => 'o-icon-external public',
                        'title' => $translate('View public site'),
                    ]); ?></li>
                    <?php if ($site->userIsAllowed('update')): ?>
                    <li><?php echo $site->link('', null, [
                        'class' => 'o-icon-edit',
                        'title' => $translate('Edit'),
                    ]); ?></li>
                    <?php endif; ?>
                    <?php if ($site->userIsAllowed('delete')): ?>
                    <li><?php echo $this->hyperlink('', '#', [
                        'data-sidebar-content-url' => $site->url('delete-confirm'),
                        'class' => 'o-icon-delete sidebar-content',
                        'title' => $translate('Delete'),
                    ]); ?></li>
                    <?php endif; ?>
                </ul>
            </td>
            <?php echo $this->browse()->renderContentRow('sites', $site); ?>
        </tr>
        <?php endforeach; ?>
    </tbody>
</table>
<?php $this->trigger('view.browse.after'); ?>
<div class="browse-controls">
    <?php echo $this->pagination(); ?>
</div>

<div id="sidebar" 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 sites.'); ?></p>
</div>

<?php endif; ?>
