from django.core.management.base import BaseCommand
from core.models import HeroImage
import os
from django.conf import settings


class Command(BaseCommand):
    help = 'Membantu mengorganisir dan menampilkan informasi hero images yang perlu diupload'

    def handle(self, *args, **options):
        self.stdout.write(
            self.style.SUCCESS('📋 DAFTAR HERO IMAGES YANG PERLU DIUPLOAD\n')
        )
        
        # Group by page
        pages = {}
        for hero in HeroImage.objects.all().order_by('page', 'name'):
            if hero.page not in pages:
                pages[hero.page] = []
            pages[hero.page].append(hero)
        
        # Display organized list
        for page_choice, page_display in HeroImage.PAGE_CHOICES:
            if page_choice in pages:
                self.stdout.write(
                    self.style.WARNING(f'\n📁 {page_display.upper()} ({page_choice})')
                )
                self.stdout.write('─' * 50)
                
                for hero in pages[page_choice]:
                    status = "✅ Ada gambar" if hero.image else "❌ Belum ada gambar"
                    self.stdout.write(f'  • {hero.name}')
                    self.stdout.write(f'    Status: {status}')
                    if hero.image:
                        self.stdout.write(f'    File: {hero.image.name}')
                    self.stdout.write('')
        
        # Summary
        total_heroes = HeroImage.objects.count()
        with_images = HeroImage.objects.exclude(image='').count()
        without_images = total_heroes - with_images
        
        self.stdout.write(
            self.style.SUCCESS(f'\n📊 RINGKASAN:')
        )
        self.stdout.write(f'  • Total Hero Images: {total_heroes}')
        self.stdout.write(f'  • Sudah ada gambar: {with_images}')
        self.stdout.write(f'  • Belum ada gambar: {without_images}')
        
        if without_images > 0:
            self.stdout.write(
                self.style.WARNING(f'\n⚠️  {without_images} hero images masih memerlukan gambar!')
            )
            self.stdout.write(
                self.style.SUCCESS('\n💡 CARA UPLOAD GAMBAR:')
            )
            self.stdout.write('  1. Masuk ke Admin Panel Django')
            self.stdout.write('  2. Pilih "Hero Images"')
            self.stdout.write('  3. Edit setiap hero image yang belum ada gambarnya')
            self.stdout.write('  4. Upload gambar yang sesuai dengan deskripsi')
            self.stdout.write('  5. Simpan perubahan')
            
            self.stdout.write(
                self.style.SUCCESS('\n📁 STRUKTUR FOLDER YANG DIREKOMENDASIKAN:')
            )
            self.stdout.write('  media/hero_images/')
            self.stdout.write('  ├── home/')
            self.stdout.write('  │   ├── pemandangan-desa.jpg')
            self.stdout.write('  │   ├── selamat-datang.jpg')
            self.stdout.write('  │   └── keindahan-alam.jpg')
            self.stdout.write('  ├── events/')
            self.stdout.write('  │   ├── gotong-royong.jpg')
            self.stdout.write('  │   ├── festival-desa.jpg')
            self.stdout.write('  │   └── kegiatan-sosial.jpg')
            self.stdout.write('  ├── tourism/')
            self.stdout.write('  │   ├── destinasi-unggulan.jpg')
            self.stdout.write('  │   ├── pemandangan-alam.jpg')
            self.stdout.write('  │   └── spot-foto.jpg')
            self.stdout.write('  └── ... (dan seterusnya)')
            
            self.stdout.write(
                self.style.SUCCESS('\n🎯 REKOMENDASI UKURAN GAMBAR:')
            )
            self.stdout.write('  • Format: JPG, PNG, atau WebP')
            self.stdout.write('  • Ukuran: 1920x1080px (16:9) atau 1920x600px')
            self.stdout.write('  • Kualitas: Tinggi untuk tampilan yang baik')
            self.stdout.write('  • File size: Maksimal 2MB per gambar')
