<?php
$translate = $this->plugin('translate');
$escape = $this->plugin('escapeHtml');
?>
<form class="sorting" action="">
    <?php echo $this->queryToHiddenInputs(['sort_by', 'sort_order']); ?>
    <select name="sort_by" aria-label="<?php echo $translate('Sort by'); ?>">
    <?php foreach($sortBy as $sortByHeading): ?>
        <?php $selected = ($sortByQuery === $sortByHeading['value']) ? 'selected' : ''; ?>
        <option value="<?php echo $escape($sortByHeading['value']); ?>" <?php echo $selected; ?>><?php echo $sortByHeading['label']; ?></option>
    <?php endforeach; ?>
    </select>
    <select name="sort_order" aria-label="<?php echo $translate('Sort order'); ?>">
        <option value="asc" <?php echo ($sortOrderQuery === 'asc') ? 'selected' : ''; ?>><?php echo $translate('Ascending'); ?></option>
        <option value="desc" <?php echo ($sortOrderQuery === 'desc') ? 'selected' : ''; ?>><?php echo $translate('Descending'); ?></option>
    </select>
    <button class="button" type="submit"><?php echo $translate('Sort'); ?></button>
</form>
