<?php
$translate = $this->plugin('translate');
// Prepare the item set queries
$ids = isset($query['item_set_id']) ? $query['item_set_id'] : [];
if (!is_array($ids)) {
    $ids = [$ids];
}
$ids = array_filter($ids);
if (!$ids) {
    $ids = [null];
}
?>
<div id="item-sets" class="field removable multi-value" role="group">
    <fieldset class="fieldset">
        <legend><?php echo $translate('Search by item set'); ?></legend>
        <div class="help-text"><?php echo $translate('Searches for items that are assigned to any of these item sets.'); ?></div>
        <div class="inputs">
            <?php foreach ($ids as $id): ?>
            <div class="value">
                <?php echo $this->itemSetSelect([
                    'name' => 'item_set_id[]',
                    'attributes' => [
                        'value' => $id,
                        'aria-labelledby' =>  'by-item-set-label'
                    ],
                    'options' => [
                        'disable_group_by_owner' => $this->status()->isSiteRequest(),
                    ],
                ]); ?>
                <button type="button" class="o-icon-delete remove-value button" aria-label="<?php echo $translate('Remove value'); ?>"></button>
            </div>
            <?php endforeach; ?>
        </div>
        <button class="add-value button"><?php echo $translate('Add new item set'); ?></button>
    </fieldset>
</div>
