from django import forms
from django.utils.translation import gettext_lazy as _

from wagtail.admin.forms.choosers import BaseFilterForm


class FakeSearchFilterForm(BaseFilterForm):
    q = forms.CharField(
        label=_("Search term"),
        widget=forms.TextInput(attrs={"placeholder": _("Search")}),
        required=False,
    )

    def filter(self, objects):
        objects = super().filter(objects)
        search_query = self.cleaned_data.get("q")
        if search_query:
            self.is_searching = True
            self.search_query = search_query

        return objects
