from django.utils.translation import gettext_lazy as _

from wagtail.admin.viewsets.chooser import ChooserViewSet

from ocyan.main.loading import get_ocyan_classes

# pylint: disable=W0632
AccountChooseView, AccountChooseResultsView = get_ocyan_classes(
    "ocyan_plugin_wagtail.user_views", ["AccountChooseView", "AccountChooseResultsView"]
)


class AccountChooserViewSet(ChooserViewSet):
    per_page = 20
    model = "ocyan_plugin_wagtail.Account"
    icon = "user"
    choose_one_text = _("Choose account")
    choose_view_class = AccountChooseView
    choose_results_view_class = AccountChooseResultsView
    form_fields = ["username", "email", "first_name", "last_name"]
    url_filter_parameters = preserve_url_parameters = [
        "is_superuser",
        "is_staff",
        "is_active",
    ]


account_chooser_viewset = AccountChooserViewSet("account_chooser")
