import { renderSortOption } from "../../common/sort/option.js";
const renderCommerceSortOption = ({ props })=>{
    const { sort } = props;
    const label = getLabel(sort);
    return renderSortOption({
        props: {
            ...props,
            label,
            value: label
        }
    });
};
function getLabel(sort) {
    if ('relevance' === sort.by) return 'relevance';
    return sort.fields.map((sortByField)=>sortByField.displayName || sortByField.name).join(' ');
}
function getSortByLabel(label, availableSorts) {
    const sortByLabel = {};
    availableSorts.forEach((availableSort)=>{
        sortByLabel[getLabel(availableSort)] = availableSort;
    });
    return sortByLabel[label];
}
export { getLabel, getSortByLabel, renderCommerceSortOption };
