import 'package:cheminova/controller/home_controller.dart';
import 'package:cheminova/screens/inventory/inventory_management_screen.dart';
import 'package:cheminova/screens/order/order_tracking_screen.dart';
import 'package:cheminova/screens/order_management/order_management_screen.dart';
import 'package:cheminova/screens/product/product_catalog_screen.dart';
import 'package:cheminova/screens/report/order_history_report_screen.dart';
import 'package:cheminova/screens/report/reporting_analytics_screen.dart';
import 'package:cheminova/screens/retail/retail_distributer_on_boarding_screen.dart';
import 'package:cheminova/screens/shipping/shipping_management_screen.dart';
import 'package:cheminova/widgets/home_card.dart';
import 'package:cheminova/widgets/my_drawer.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:get/get.dart';

class HomeScreen extends StatefulWidget {
  const HomeScreen({super.key});

  @override
  State<HomeScreen> createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> {
  final HomeController homeController = Get.put(HomeController());
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      extendBodyBehindAppBar: true,
      appBar: AppBar(
        centerTitle: true,
        backgroundColor: Colors.transparent,
        elevation: 0,
        leading: Builder(
          builder: (context) {
            return GestureDetector(
              onTap: () => Scaffold.of(context).openDrawer(),
              child: Padding(
                padding: const EdgeInsets.all(16.0),
                child: SvgPicture.asset(
                  'assets/svg/menu.svg',
                ),
              ),
            );
          },
        ),
        title: const Text(
          "Welcome",
        ),
      ),
      drawer: const MyDrawer(),
      body: Stack(
        fit: StackFit.expand,
        children: [
          Image.asset(
            'assets/images/image_1.png',
            fit: BoxFit.cover,
          ),
          SafeArea(
            child: Padding(
              padding: const EdgeInsets.all(8.0),
              child: SingleChildScrollView(
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                  children: [
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                      children: [
                        HomeCard(
                          title: 'Product Catalogue',
                          onTap: () =>
                              Get.to(() => const ProductCatalogScreen()),
                        ),
                        HomeCard(
                          title: 'Order Tracking',
                          onTap: () => Get.to(
                            () => const OrderTrackingScreen(),
                          ),
                        ),
                      ],
                    ),
                    const SizedBox(height: 10),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                      children: [
                        HomeCard(
                          title: 'Order Management',
                          onTap: () => Get.to(
                            () =>  OrderManagementScreen(),
                          ),
                        ),
                        HomeCard(
                          title: 'Shipping Management',
                          onTap: () => Get.to(
                            () => const ShippingManagementScreen(),
                          ),
                        ),
                      ],
                    ),
                    const SizedBox(height: 10),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                      children: [
                        HomeCard(
                          title: 'Inventory Management',
                          onTap: () => Get.to(
                            () => const InventoryManagementScreen(),
                          ),
                        ),
                        HomeCard(
                          title: 'Reporting & Analytics',
                          onTap: () => Get.to(
                            () => const ReportingAnalyticsScreen(),
                          ),
                        ),
                      ],
                    ),
                    const SizedBox(height: 10),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                      children: [
                        HomeCard(
                          title: 'Order Data Export',
                          onTap: () => Get.to(
                            () => const OrderHistoryReportScreen(),
                          ),
                        ),
                        HomeCard(
                          title: 'Retail Distributors Onboarding',
                          onTap: () => Get.to(
                            () => const RetailDistributerOnBoardingScreen(),
                          ),
                        ),
                      ],
                    ),
                  ],
                ),
              ),
            ),
          )
        ],
      ),
    );
  }
}
