// lib/app/modules/home/views/home_view.dart
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../controllers/home_controller.dart';
import '../../../widgets/banner_slider.dart';
import '../../../widgets/monitoring_card.dart';

class HomeView extends GetView<HomeController> {
  const HomeView({super.key});
  
  @override
  Widget build(BuildContext context) {
    Get.put(HomeController());
    
    return Scaffold(
      backgroundColor: Colors.white,
      body: SafeArea(
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            // Header
            Padding(
              padding: const EdgeInsets.all(20),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  const Text(
                    'Halo Perawat',
                    style: TextStyle(
                      fontSize: 24,
                      fontWeight: FontWeight.bold,
                    ),
                  ),
                  InkWell(
                    onTap: () => controller.showLogoutDialog(context),
                    child: Container(
                      padding: const EdgeInsets.all(8),
                      decoration: BoxDecoration(
                        border: Border.all(color: Colors.grey[300]!),
                        borderRadius: BorderRadius.circular(10),
                      ),
                      child: const Icon(Icons.logout, color: Colors.red),
                    ),
                  ),
                ],
              ),
            ),
            
            // Banner Slider - Gunakan widget universal
            BannerSlider(
              bannerImages: controller.bannerImages,
              currentCarouselIndex: controller.currentCarouselIndex,
              onPageChanged: controller.updateCarouselIndex,
            ),
            
            const SizedBox(height: 15),
            
            // Monitoring Infus Section
            Padding(
              padding: const EdgeInsets.symmetric(horizontal: 20),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  const Text(
                    'Monitoring Infus',
                    style: TextStyle(
                      fontSize: 18,
                      fontWeight: FontWeight.bold,
                    ),
                  ),
                  TextButton(
                    onPressed: () {},
                    child: const Text(
                      'See all',
                      style: TextStyle(color: Color(0xFF0091EA)),
                    ),
                  ),
                ],
              ),
            ),
            
            // Monitoring List
            Expanded(
              child: Obx(
                () => ListView.builder(
                  padding: const EdgeInsets.symmetric(horizontal: 20),
                  itemCount: controller.monitoringList.length,
                  itemBuilder: (context, index) {
                    final item = controller.monitoringList[index];
                    return MonitoringCard(
                      item: item,
                      onTap: () {
                        // Handle tap jika diperlukan
                      },
                    );
                  },
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}