from django.contrib import admin
from .models import Identity, SocialLink, SkillCategory, Skill, Language, Interest

@admin.register(Identity)
class IdentityAdmin(admin.ModelAdmin):
    # On empêche d'ajouter une deuxième identité
    def has_add_permission(self, request):
        return not Identity.objects.exists()

class SkillInline(admin.TabularInline):
    model = Skill
    extra = 1  # Affiche une ligne vide prête à remplir
    fields = ('name', 'icon_class', 'level', 'order', 'is_featured')

@admin.register(SkillCategory)
class SkillCategoryAdmin(admin.ModelAdmin):
    list_display = ('name', 'order')
    inlines = [SkillInline]  # Permet de gérer les skills directement dans la catégorie

@admin.register(Skill)
class SkillAdmin(admin.ModelAdmin):
    list_display = ('name', 'category', 'level', 'is_featured')
    list_filter = ('category', 'is_featured')
    search_fields = ('name',)

@admin.register(SocialLink)
class SocialLinkAdmin(admin.ModelAdmin):
    list_display = ('name', 'url', 'order')
    list_editable = ('order',)

@admin.register(Language)
class LanguageAdmin(admin.ModelAdmin):
    list_display = ('name', 'level', 'order')

@admin.register(Interest)
class InterestAdmin(admin.ModelAdmin):
    list_display = ('name', 'icon_class')