from django.contrib.admin import ModelAdmin, register
from django_summernote.admin import SummernoteModelAdminMixin

from core.admin import ActivationActionsMixin, FieldsetsMixin

from .models import Post, PostTag


@register(Post)
class PostAdmin(SummernoteModelAdminMixin, FieldsetsMixin, ActivationActionsMixin, ModelAdmin):  # type: ignore [misc, type-arg]
    list_display = ("title", "author", "slug", "created", "modified")
    list_filter = ("author", "tags", "created", "modified")
    search_fields = ("title", "content", "slug")
    filter_horizontal = ("tags",)
    date_hierarchy = "created"
    autocomplete_fields = ("author", "tags")
    readonly_fields = (
        "uuid",
        "slug",
        "modified",
        "created",
    )

    summernote_fields = ("content",)
    general_fields = [
        "title",
        "author",
        "content",
        "file",
    ]
    relation_fields = [
        "tags",
    ]


@register(PostTag)
class PostTagAdmin(ModelAdmin):  # type: ignore [type-arg]
    list_display = ("tag_name", "name")
    search_fields = ("tag_name", "name")
    ordering = ("tag_name",)
