import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:ride/constant/style.dart';
import 'package:ride/views/widgets/my_scafold.dart';
import 'package:ride/views/widgets/mycircular.dart';

import '../../../constant/colors.dart';
import '../../../controller/functions/launch.dart';
import '../../../controller/home/profile/order_history_controller.dart';

class OrderHistory extends StatelessWidget {
  const OrderHistory({super.key});

  @override
  Widget build(BuildContext context) {
    // Instantiate the OrderHistoryController class
    Get.put(OrderHistoryController());

    return MyScafolld(
      title: 'Order History'.tr,
      isleading: true,
      body: [
        GetBuilder<OrderHistoryController>(
          builder: (orderHistoryController) => orderHistoryController.isloading
              ? const MyCircularProgressIndicator()
              : ListView.builder(
                  itemCount:
                      orderHistoryController.orderHistoryListPassenger.length,
                  itemBuilder: (BuildContext context, int index) {
                    final rides =
                        orderHistoryController.orderHistoryListPassenger[index];
                    return Padding(
                      padding: const EdgeInsets.all(8.0),
                      child: Container(
                        decoration: const BoxDecoration(
                            borderRadius: BorderRadius.all(Radius.circular(12)),
                            color: AppColor.secondaryColor,
                            boxShadow: [
                              BoxShadow(
                                  color: AppColor.accentColor,
                                  offset: Offset(-3, -3),
                                  blurRadius: 0,
                                  spreadRadius: 0,
                                  blurStyle: BlurStyle.outer),
                              BoxShadow(
                                  color: AppColor.accentColor,
                                  offset: Offset(3, 3),
                                  blurRadius: 0,
                                  spreadRadius: 0,
                                  blurStyle: BlurStyle.outer)
                            ]),
                        child: Padding(
                          padding: const EdgeInsets.all(8.0),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              InkWell(
                                onTap: () {
                                  String mapUrl =
                                      'https://www.google.com/maps/dir/${rides['start_location']}/${rides['end_location']}/';
                                  print(mapUrl);
                                  launchUrl1(mapUrl);
                                },
                                child: Column(
                                  children: [
                                    Text(rides['start_location']),
                                    Text(rides['end_location']),
                                  ],
                                ),
                              ),
                              Column(
                                children: [
                                  Text(
                                    rides['date'],
                                    style: AppStyle.subtitle,
                                  ),
                                  Text(
                                    rides['time'],
                                    style: AppStyle.subtitle,
                                  ),
                                  Text(
                                    rides['status'],
                                    style: rides['status'] != 'Canceled'
                                        ? AppStyle.subtitle
                                        : AppStyle.subtitle
                                            .copyWith(color: AppColor.redColor),
                                  ),
                                  Text(
                                    rides['price'],
                                    style: AppStyle.subtitle,
                                  ),
                                ],
                              ),
                            ],
                          ),
                        ),
                      ),
                    );
                  },
                ),
        )
      ],
    );
  }
}
