from django.contrib import admin
from django.utils.html import format_html
from .models import HeroSlide

# Register your models here.

@admin.register(HeroSlide)
class HeroSlideAdmin(admin.ModelAdmin):
    list_display = ('title', 'image_preview', 'order', 'is_active', 'created_at')
    list_editable = ('order', 'is_active')
    list_filter = ('is_active', 'created_at')
    search_fields = ('title', 'subtitle')
    readonly_fields = ('image_preview', 'created_at', 'updated_at')
    
    fieldsets = (
        ('Content', {
            'fields': ('title', 'subtitle', 'image', 'image_preview'),
            'description': 'Add the main content for this slide. Images should be high quality (1920x1080).'
        }),
        ('Call to Action', {
            'fields': ('button_text', 'button_url'),
            'description': 'Optional button that will appear on the slide.'
        }),
        ('Settings', {
            'fields': ('order', 'is_active'),
            'description': 'Control the slide\'s position and visibility.'
        }),
        ('Timestamps', {
            'fields': ('created_at', 'updated_at'),
            'classes': ('collapse',),
        }),
    )

    def image_preview(self, obj):
        if obj.image:
            return format_html(
                '<img src="{}" style="max-height: 50px; border-radius: 5px; box-shadow: 0 2px 4px rgba(0,0,0,0.1);">',
                obj.image.url
            )
        return "No image"
    image_preview.short_description = 'Preview'

    class Media:
        css = {
            'all': ('css/custom_admin.css',)
        }
