import 'package:flutter/material.dart';
import 'package:monitoring/models/berita_model.dart';

class BeritaDetailScreen extends StatelessWidget {
  final BeritaModel berita;

  const BeritaDetailScreen({super.key, required this.berita});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: const Color(0xFFF8F9FA),
      appBar: AppBar(
        title: const Text('Detail Berita'),

        backgroundColor: Color(0xFF43A047),
        foregroundColor: Colors.white,
        elevation: 0,
      ),
      body: SingleChildScrollView(
        padding: const EdgeInsets.all(16),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            // Gambar
            ClipRRect(
              borderRadius: BorderRadius.circular(12),
              child:
                  berita.gambarUrl != null
                      ? Image.network(
                        berita.gambarUrl!,
                        width: double.infinity,
                        height: 200,
                        fit: BoxFit.cover,
                        errorBuilder:
                            (_, __, ___) => Image.asset(
                              'assets/404.png',
                              width: double.infinity,
                              height: 200,
                              fit: BoxFit.cover,
                            ),
                      )
                      : Image.asset(
                        'assets/404.png',
                        width: double.infinity,
                        height: 200,
                        fit: BoxFit.cover,
                      ),
            ),
            const SizedBox(height: 16),

            // Judul
            Text(
              berita.judul,
              style: const TextStyle(
                fontSize: 24,
                fontWeight: FontWeight.bold,
                color: Colors.black87,
              ),
            ),
            const SizedBox(height: 8),

            // Kategori dan Penulis
            Row(
              children: [
                Chip(
                  label: Text(berita.kategori ?? 'Umum'),
                  backgroundColor: Colors.pink.shade100,
                ),
                const SizedBox(width: 8),
                Text(
                  'Oleh ${berita.penulis ?? '-'}',
                  style: const TextStyle(fontSize: 14, color: Colors.grey),
                ),
              ],
            ),
            const SizedBox(height: 16),

            // Ringkasan atau isi
            Text(
              berita.ringkasan ?? 'Tidak ada isi berita.',
              textAlign: TextAlign.justify,
              style: const TextStyle(fontSize: 16, height: 1.5),
            ),
          ],
        ),
      ),
    );
  }
}
