from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.utils.translation import gettext_lazy as _
from accounts.models import CustomUser


class CustomUserAdmin(UserAdmin):
    # Remove username from the fieldsets
    fieldsets = (
        (None, {'fields': ('email', 'password')}),
        (_('Personal info'), {'fields': ('first_name', 'last_name')}),
        (_('Permissions'), {
            'fields': ('is_active', 'is_staff', 'is_superuser', 'groups', 'user_permissions'),
        }),
        (_('Important dates'), {'fields': ('last_login', 'date_joined')}),
    )
    
    # Remove username from the add_fieldsets
    add_fieldsets = (
        (None, {
            'classes': ('wide',),
            'fields': ('email', 'password1', 'password2'),
        }),
    )
    
    # Update list_display to use email instead of username
    list_display = ('email', 'first_name', 'last_name', 'is_staff')
    
    # Update search_fields to use email instead of username
    search_fields = ('email', 'first_name', 'last_name')
    
    # Update ordering to use email instead of username
    ordering = ('email',)


# Register your models here.
admin.site.register(CustomUser, CustomUserAdmin)
