from django.contrib import admin
from django import forms
from .models import (
    Event,
    Category,
    Tag,
    StaticContent,
    DuplicatedEvents,
    BatchImportation,
    RecurrentImport,
    Place,
    Message,
    ReferenceLocation,
    Organisation
)
from django_better_admin_arrayfield.admin.mixins import DynamicArrayMixin
from django_better_admin_arrayfield.forms.widgets import DynamicArrayWidget
from django_better_admin_arrayfield.models.fields import DynamicArrayField


admin.site.register(Category)
admin.site.register(Tag)
admin.site.register(StaticContent)
admin.site.register(DuplicatedEvents)
admin.site.register(BatchImportation)
admin.site.register(RecurrentImport)
admin.site.register(Place)
admin.site.register(Message)
admin.site.register(ReferenceLocation)
admin.site.register(Organisation)


class URLWidget(DynamicArrayWidget):
    def __init__(self, *args, **kwargs):
        kwargs["subwidget_form"] = forms.URLField()
        super().__init__(*args, **kwargs)


@admin.register(Event)
class Eventdmin(admin.ModelAdmin, DynamicArrayMixin):
    formfield_overrides = {
        DynamicArrayField: {"urls": URLWidget},
    }
