from django.contrib import admin
from django.utils.translation import gettext_lazy as _

from .models import Member


@admin.register(Member)
class MemberAdmin(admin.ModelAdmin):
    def family_member_count(self, obj):
        return obj.family_members.count()

    def show_user_is_active(self, obj):
        return obj.user.is_active

    show_user_is_active.boolean = True
    show_user_is_active.short_description = _("active?")

    list_display = ["__str__", "user__email", "show_user_is_active", "family_member_count", "birthday", "created", "updated"]
    date_hierarchy = "birthday"
    list_filter = ["user__is_superuser", "user__is_active"]
    readonly_fields = ["created", "updated", "access_token"]
    filter_horizontal = ["family_members"]
    raw_id_fields = ["user"]
    fieldsets = [
        ("GENERAL INFORMATION", {"fields": ["user", "family_members", "birthday", "license", "access_token"]}),
        ("CONTACT_INFORMATION", {"fields": ["phone_number", "emergency_phone_number"]}),
        ("METADATA", {"fields": ["created", "updated"]}),
    ]
