import 'package:cheminova/models/product_model.dart';
import 'package:cheminova/screens/order/order_confermation_screen.dart';
import 'package:cheminova/widgets/input_field.dart';
import 'package:cheminova/widgets/my_drawer.dart';
import 'package:cheminova/widgets/product_card.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:get/get.dart';
import 'package:google_fonts/google_fonts.dart';

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

  @override
  State<CheckoutScreen> createState() => _CheckoutScreenState();
}

class _CheckoutScreenState extends State<CheckoutScreen> {
  final TextEditingController _addressController = TextEditingController();
  final TextEditingController _contactController = TextEditingController();

  final List<ProductModel> _checkoutList = [
    ProductModel(
      id: "1",
      image: 'assets/images/product.png',
      name: "Product 1",
      category: ProductCategory.food,
      description: 'Product 1 description',
      price: 100,
    ),
  ];

  String _groupValue = "Credit Card";

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      extendBodyBehindAppBar: true,
      appBar: AppBar(
        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',
                ),
              ),
            );
          },
        ),
        actions: [
          GestureDetector(
            onTap: () => Get.back(),
            child: Padding(
              padding: EdgeInsets.all(Get.width * 0.02),
              child: SvgPicture.asset(
                'assets/svg/back_arrow.svg',
              ),
            ),
          ),
        ],
        title: const Text(
          "Checkout",
        ),
      ),
      drawer: const MyDrawer(),
      body: Stack(
        fit: StackFit.expand,
        children: [
          Image.asset(
            'assets/images/image_1.png',
            fit: BoxFit.cover,
          ),
          SafeArea(
            child: Column(
              children: [
                SizedBox(
                  height: Get.height * 0.02,
                ),
                Card(
                  margin: EdgeInsets.symmetric(horizontal: Get.width * 0.05),
                  shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(19),
                    side: const BorderSide(color: Color(0xFFFDFDFD)),
                  ),
                  color: const Color(0xFFB4D1E5).withOpacity(0.9),
                  child: Padding(
                    padding: EdgeInsets.all(Get.width * 0.04),
                    child: Column(
                      mainAxisSize: MainAxisSize.min,
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Padding(
                          padding: EdgeInsets.symmetric(
                              horizontal: Get.width * 0.04),
                          child: Text(
                            'Shipping Information',
                            style: GoogleFonts.roboto(
                              fontSize: Get.width * 0.04,
                              fontWeight: FontWeight.w500,
                              color: Colors.black,
                            ),
                          ),
                        ),
                        InputField(
                          hintText: 'Address:',
                          labelText: 'Address:',
                          controller: _addressController,
                        ),
                        InputField(
                          hintText: 'Contact:',
                          labelText: 'Contact:',
                          controller: _contactController,
                        ),
                        Padding(
                          padding: EdgeInsets.symmetric(
                              horizontal: Get.width * 0.04),
                          child: Text(
                            'Payment Information',
                            style: GoogleFonts.roboto(
                              fontSize: Get.width * 0.04,
                              fontWeight: FontWeight.w500,
                              color: Colors.black,
                            ),
                          ),
                        ),
                        Card(
                          child: ListView(
                            padding: EdgeInsets.zero,
                            shrinkWrap: true,
                            children: [
                              SizedBox(
                                height: Get.height * 0.035,
                                child: RadioListTile(
                                  title: const Text("Credit Card"),
                                  contentPadding: EdgeInsets.zero,
                                  value: "Credit Card",
                                  groupValue: _groupValue,
                                  onChanged: (value) {
                                    setState(() {
                                      _groupValue = value.toString();
                                    });
                                  },
                                ),
                              ),
                              SizedBox(
                                height: Get.height * 0.035,
                                child: RadioListTile(
                                  title: const Text("Net Banking"),
                                  contentPadding: EdgeInsets.zero,
                                  value: "Net Banking",
                                  groupValue: _groupValue,
                                  onChanged: (value) {
                                    setState(() {
                                      _groupValue = value.toString();
                                    });
                                  },
                                ),
                              ),
                              SizedBox(
                                child: RadioListTile(
                                  title: const Text("Cash on Delivery"),
                                  contentPadding: EdgeInsets.zero,
                                  value: "Cash on Delivery",
                                  groupValue: _groupValue,
                                  onChanged: (value) {
                                    setState(() {
                                      _groupValue = value.toString();
                                    });
                                  },
                                ),
                              ),
                            ],
                          ),
                        ),
                        Padding(
                          padding: EdgeInsets.symmetric(
                              horizontal: Get.width * 0.04),
                          child: Text(
                            'Order Summary',
                            style: GoogleFonts.roboto(
                              fontSize: Get.width * 0.04,
                              fontWeight: FontWeight.w500,
                              color: Colors.black,
                            ),
                          ),
                        ),
                        Card(
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              SizedBox(
                                height: Get.height * 0.22,
                                child: Padding(
                                  padding: EdgeInsets.all(Get.width * 0.02),
                                  child: ListView.builder(
                                    padding: EdgeInsets.zero,
                                    itemCount: 10,
                                    itemBuilder: (context, index) =>
                                        ProductCard(
                                      product: _checkoutList[0],
                                      isCheckout: true,
                                    ),
                                  ),
                                ),
                              ),
                              Padding(
                                padding: EdgeInsets.all(Get.width * 0.04),
                                child: Text(
                                  'Total Price: ₹ 1000.00',
                                  style: GoogleFonts.roboto(
                                    fontSize: Get.width * 0.05,
                                    fontWeight: FontWeight.w700,
                                    color: Colors.black,
                                  ),
                                ),
                              ),
                            ],
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
                SizedBox(
                  height: Get.height * 0.025,
                ),
                SizedBox(
                  width: Get.width * 0.9,
                  height: Get.height * 0.06,
                  child: ElevatedButton(
                    onPressed: () =>
                        Get.to(() => const OrderConfermationScreen()),
                    style: ElevatedButton.styleFrom(
                      foregroundColor: Colors.white,
                      backgroundColor: const Color(0xFF00784C),
                      shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(10),
                      ),
                    ),
                    child: Text(
                      "Place Order",
                      style: GoogleFonts.roboto(
                        fontSize: Get.width * 0.04,
                        fontWeight: FontWeight.w600,
                      ),
                    ),
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}
