"""
Base admin classes and common functionality
"""

from django.contrib import admin
from django.utils.html import format_html
from adminsortable2.admin import SortableAdminMixin

from ..models import ReusableText, Category, WebsiteFaq


@admin.register(ReusableText)
class ReusableTextAdmin(admin.ModelAdmin):
    """Admin configuration for ReusableText model"""

    list_display = ("name",)
    search_fields = ("name", "text")
    ordering = ("name",)


@admin.register(Category)
class CategoryAdmin(admin.ModelAdmin):
    """Admin configuration for Category model"""

    list_display = ("name", "slug", "parent", "order")
    list_filter = ("parent",)
    search_fields = ("name", "description")
    prepopulated_fields = {"slug": ("name",)}
    ordering = ("order", "name")


@admin.register(WebsiteFaq)
class WebsiteFaqAdmin(SortableAdminMixin, admin.ModelAdmin):
    """Admin configuration for WebsiteFaq model"""

    list_display = ("question", "order")
    search_fields = ("question", "answer")
    ordering = ("order",)
