<?php

namespace App\Nova\Filters;

use App\Models\Ecommerce\Product\Order\Status\OrderStatus;
use Illuminate\Database\Eloquent\Builder;
use Laravel\Nova\Filters\Filter;
use Laravel\Nova\Http\Requests\NovaRequest;

class StatusFilter extends Filter
{
    /**
     * The filter's component.
     *
     * @var string
     */
    public $component = 'select-filter';

    /**
     * Get the displayable name of the filter.
     */
    public function name(): string
    {
        return __('Status');
    }

    /**
     * Apply the filter to the given query.
     *
     * @param  Builder  $query
     * @param  mixed  $value
     * @return Builder
     */
    public function apply(NovaRequest $request, $query, $value)
    {
        return $value ? $query->where('status', $value) : $query;
    }

    /**
     * Get the filter's available options.
     */
    public function options(NovaRequest $request): array
    {
        return array_flip(OrderStatus::values());
    }
}
