from django.contrib import admin
from .models import Rapid, RapidImage, Examination, Site, Abnormality, Region, RapidCreationDefault, Answer, Exam, UserAnswer

from django.forms import ModelForm

from reversion.admin import VersionAdmin
from django.forms.widgets import RadioSelect

# Register your models here.
admin.site.register(Examination)
#admin.site.register(Site)
admin.site.register(Abnormality)
admin.site.register(Region)
admin.site.register(RapidCreationDefault)
admin.site.register(Answer)

class RapidAnswersInline(admin.TabularInline):
    model = Answer
    extra = 1


class RapidImageInline(admin.TabularInline):
    model = RapidImage
    extra = 1
    readonly_fields = [
        "image_tag",
    ]

class ExamInline(admin.TabularInline):
    model = Rapid.exams.through
    extra = 1


class RapidAdminForm(ModelForm):
    class Meta:
        model = Rapid

        fields = [
            "normal", "abnormality", "region", "laterality", "examination",
            #"site", 
            #"sign", "condition", 
            "feedback", "author"
        ]

        widgets = {
            "laterality": RadioSelect(attrs={'style': 'display: inline-flex'}),
        }


class RapidAdmin(VersionAdmin):
    form = RapidAdminForm

    filter_horizontal = (
        "abnormality",
        "region",
        #"examination",
    )
    save_on_top = True
    save_as = True
    view_on_site = True

    inlines = [
        RapidImageInline,
        RapidAnswersInline,
        ExamInline,
    ]

class ExamAdmin(VersionAdmin, admin.ModelAdmin):
    save_as = True

admin.site.register(Rapid, RapidAdmin)
admin.site.register(Exam, ExamAdmin)

class UserAnswerAdmin(admin.ModelAdmin):
    exclude = []
    readonly_fields = ["created", "updated"]

admin.site.register(UserAnswer, UserAnswerAdmin)

class RapidImageAdmin(admin.ModelAdmin):
       readonly_fields = ('rapid',)

admin.site.register(RapidImage, RapidImageAdmin)