from django.contrib import admin
from .models import Presentation, Slide, ReportTemplate, ReportTemplateSlide


class SlideInline(admin.TabularInline):
    model = Slide
    extra = 0
    fields = ('order', 'layout', 'title', 'subtitle')
    ordering = ('order',)


@admin.register(Presentation)
class PresentationAdmin(admin.ModelAdmin):
    list_display = ('title', 'theme', 'status', 'created_by', 'hospital', 'slide_count', 'created_at')
    list_filter = ('status', 'theme', 'hospital')
    search_fields = ('title', 'description')
    readonly_fields = ('created_at', 'updated_at')
    inlines = [SlideInline]


@admin.register(Slide)
class SlideAdmin(admin.ModelAdmin):
    list_display = ('__str__', 'layout', 'order', 'presentation')
    list_filter = ('layout', 'presentation')
    ordering = ('presentation', 'order')


class TemplateSlideInline(admin.TabularInline):
    model = ReportTemplateSlide
    extra = 0
    fields = ('order', 'layout', 'title_template', 'subtitle_template', 'repeat_source', 'max_rows')
    ordering = ('order',)


@admin.register(ReportTemplate)
class ReportTemplateAdmin(admin.ModelAdmin):
    list_display = ('name', 'slug', 'data_source', 'active', 'slide_count', 'created_by', 'created_at')
    list_filter = ('active', 'data_source')
    search_fields = ('name', 'description')
    readonly_fields = ('created_at', 'updated_at', 'parsed_structure')
    inlines = [TemplateSlideInline]
