<?php
$translate = $this->plugin('translate');
$escape = $this->plugin('escapeHtml');
$hyperlink = $this->plugin('hyperlink');
$thumbnail = $this->plugin('thumbnail');
?>

<a href="#" class="sidebar-close o-icon-close"><span class="screen-reader-text"><?php echo $translate('Close'); ?></span></a>

<?php
if ($this->userIsAllowed('Omeka\Api\Adapter\AssetAdapter', 'create')):
    echo $this->partial('omeka/admin/asset/add-form');
endif;
?>

<h3><?php echo $translate('Select asset'); ?></h3>

<div class="asset-filters">
    <?php
    echo $this->userSelect([
        'name' => 'owner_id',
        'options' => [
            'empty_option' => '',
            'prepend_value_options' => [
                '0' => sprintf('[%s]', $translate('No owner')),
            ],
        ],
        'attributes' => [
            'id' => 'filter-owner',
            'class' => 'chosen-select',
            'value' => $this->params()->fromQuery('owner_id'),
            'data-placeholder' => $translate('Filter by owner'),
        ],
    ]);
    ?>
</div>

<?php if (count($assets) > 0): ?>
<?php echo $this->pagination('common/sidebar-pagination.phtml'); ?>
<div class="asset-list">
<?php foreach ($assets as $asset): ?>
    <div class="asset" data-asset-id='<?php echo $escape($asset->id()); ?>'>
        <?php
        echo $hyperlink->raw(
            sprintf('%s <span class="asset-name">%s</span>',
                $thumbnail($asset, 'medium'),
                $escape($asset->name())
            ),
            '#',
            ['class' => 'select-asset asset-entry', 'data-asset-id' => $asset->id(), 'data-asset-url' => $asset->assetUrl()]
        );
        ?>
    </div>
<?php endforeach; ?>
<?php else: ?>
<span class="no-resources"><?php echo $translate('Omeka could not find any assets.'); ?></span>
<?php endif; ?>
</div>

<script>
$(document).ready(function () {
    $('#filter-owner').chosen(chosenOptions);
});
</script>
