import { ensureAtLeastOneSolutionType } from '../../../../app/commerce-ssr-engine/common.js';
import { SolutionType, } from '../../../../app/commerce-ssr-engine/types/common.js';
import { buildProductListing } from '../../product-listing/headless-product-listing.js';
import { buildSearch } from '../../search/headless-search.js';
/**
 * Defines a `Sort` controller instance.
 * @group Definers
 *
 * @param props - The configurable `Sort` properties.
 * @returns The `Sort` controller definition.
 */
export function defineSort(props) {
    ensureAtLeastOneSolutionType(props);
    return {
        listing: true,
        search: true,
        ...props,
        build: (engine, solutionType) => solutionType === SolutionType.listing
            ? buildProductListing(engine).sort(props)
            : buildSearch(engine).sort(props),
    };
}
