<?php

if (!defined('B_PROLOG_INCLUDED') || B_PROLOG_INCLUDED !== true) {
    die();
}

class CatalogSortComponent extends CBitrixComponent
{
    public function onPrepareComponentParams($arParams)
    {
        $arParams['SORT_FIELD'] = (string)($arParams['SORT_FIELD'] ?? 'id');
        $arParams['SORT_ORDER'] = (string)($arParams['SORT_ORDER'] ?? 'desc');

        return $arParams;
    }

    public function executeComponent()
    {
        $this->arResult = [
            'CURRENT_FIELD' => $this->arParams['SORT_FIELD'] ?? 'id',
            'CURRENT_ORDER' => $this->arParams['SORT_ORDER'] ?? 'desc',
        ];

        $this->includeComponentTemplate();
    }
}
