<?php

declare(strict_types=1);

namespace Autogedal\Reduceri\Plugin;

use Amasty\Shopby\Model\Layer\Filter\OnSale;
use Amasty\Shopby\Model\Layer\FilterList;
use Magento\Catalog\Model\Layer;

class HideOnSaleFilter
{
    /**
     * Remove the On Sale filter from layered navigation display.
     *
     * amshopby/am_on_sale_filter/enabled must stay ON for OpenSearch indexing
     * (am_on_sale field is needed by AddDiscountFilter plugin on reduceri pages).
     * This plugin removes it from the visible filter list on all pages.
     */
    public function afterGetFilters(FilterList $subject, array $filters, Layer $layer): array
    {
        return array_values(array_filter($filters, static fn($f) => !($f instanceof OnSale)));
    }
}
