<?php if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) die();
/**
 * @var array $arResult
 */
$currentField = $arResult['CURRENT_FIELD'];
$currentOrder = $arResult['CURRENT_ORDER'];
$isActive = fn($field, $order) => ($currentField === $field && $currentOrder === $order) ? ' active' : '';
?>
<div class="catalog-sort"
     data-entity="catalog-sort"
     data-params="<?= htmlspecialchars(json_encode($arResult['CATALOG_PARAMS'] ?? [])) ?>">
    <span>Сортировать:</span>
    <button type="button"
            class="catalog-sort__btn<?= $isActive('id', 'desc') ?>"
            data-field="id"
            data-order="desc">
        По новизне
    </button>
    <button type="button"
            class="catalog-sort__btn<?= $isActive('id', 'asc') ?>"
            data-field="id"
            data-order="asc">
        <span>Сначала старые</span>
    </button>
</div>

<?php CJSCore::Init(['ajax']); ?>
