import 'package:SEFER/controller/functions/location_controller.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:SEFER/constant/colors.dart';
import 'package:SEFER/constant/style.dart';
import 'package:SEFER/controller/auth/captin/history_captain.dart';
import 'package:SEFER/controller/functions/launch.dart';
import 'package:SEFER/views/widgets/my_scafold.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';

import '../../../widgets/mycircular.dart';

class HistoryDetailsPage extends StatelessWidget {
  HistoryDetailsPage({super.key});
  HistoryCaptainController historyCaptainController =
      Get.put(HistoryCaptainController());
  @override
  Widget build(BuildContext context) {
    return MyScafolld(
      title: 'Trip Detail'.tr,
      body: [
        GetBuilder<HistoryCaptainController>(
            builder: (historyCaptainController) {
          var res = historyCaptainController.historyDetailsData['data'];
          return historyCaptainController.isloading
              ? const MyCircularProgressIndicator()
              : SingleChildScrollView(
                  child: Center(
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.start,
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        Container(
                          width: Get.width * .8,
                          decoration: BoxDecoration(
                              border: Border.all(
                                  color: AppColor.blueColor, width: 2)),
                          child: TextButton(
                            onPressed: () {
                              String mapUrl =
                                  'https://www.google.com/maps/dir/${res['start_location']}/${res['end_location']}/';
                              print(mapUrl);
                              showInBrowser(mapUrl);
                            },
                            child: Column(
                              children: [
                                SizedBox(
                                  height: Get.height * .2,
                                  width: Get.width * .75,
                                  child: GoogleMap(
                                    initialCameraPosition: CameraPosition(
                                      target: Get.find<LocationController>()
                                          .myLocation, // Assuming passenger location is available
                                      tilt: 80, zoom: 13,
                                    ),
                                    zoomControlsEnabled: true,
                                    // liteModeEnabled: true,
                                    polylines: {
                                      Polyline(
                                        zIndex: 2,
                                        consumeTapEvents: true,
                                        geodesic: true,
                                        endCap: Cap.buttCap,
                                        startCap: Cap.buttCap,
                                        visible: true,
                                        polylineId: const PolylineId('route'),
                                        points: [
                                          LatLng(
                                            double.parse(res['start_location']
                                                .toString()
                                                .split(',')[0]),
                                            double.parse(res['start_location']
                                                .toString()
                                                .split(',')[1]),
                                          ),
                                          LatLng(
                                            double.parse(res['end_location']
                                                .toString()
                                                .split(',')[0]),
                                            double.parse(res['end_location']
                                                .toString()
                                                .split(',')[1]),
                                          )
                                        ],
                                        color: AppColor.primaryColor,
                                        width: 5,
                                      ),
                                    },
                                  ),
                                ),
                                const SizedBox(
                                  height: 10,
                                ),
                                Row(
                                  mainAxisAlignment:
                                      MainAxisAlignment.spaceEvenly,
                                  children: [
                                    Text(
                                      '${'Order ID'.tr} ${res['id']}',
                                      style: AppStyle.title,
                                    ),
                                    Text(
                                      res['date'].toString(),
                                      style: AppStyle.title,
                                    ),
                                  ],
                                ),
                              ],
                            ),
                          ),
                        ),
                        const SizedBox(
                          height: 10,
                        ),
                        Container(
                          width: Get.width * .8,
                          decoration: BoxDecoration(
                              border: Border.all(
                                  color: AppColor.greenColor, width: 2)),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                            children: [
                              Text(
                                '${'Price is'.tr} ${res['price_for_driver']}',
                                style: AppStyle.title,
                              ),
                              Text(
                                '${'Distance is'.tr} ${res['distance']} KM',
                                style: AppStyle.title,
                              ),
                            ],
                          ),
                        ),
                        const SizedBox(
                          height: 10,
                        ),
                        Text(
                          'Times of Trip'.tr,
                          style: AppStyle.title,
                        ),
                        const SizedBox(
                          height: 10,
                        ),
                        Container(
                          width: Get.width * .8,
                          decoration: BoxDecoration(
                              border: Border.all(
                                  color: AppColor.redColor, width: 2)),
                          child: Column(
                            children: [
                              Text(
                                '${'Time to Passenger is'.tr} ${res['DriverIsGoingToPassenger']}',
                                style: AppStyle.title,
                              ),
                              Text(
                                '${'TimeStart is'.tr} ${res['rideTimeStart']}',
                                style: AppStyle.title,
                              ),
                              Text(
                                '${'Time Finish is'.tr} ${res['rideTimeFinish']}',
                                style: AppStyle.title,
                              ),
                            ],
                          ),
                        ),
                        const SizedBox(
                          height: 10,
                        ),
                        Container(
                          width: Get.width * .8,
                          decoration: BoxDecoration(
                              border: Border.all(
                                  color: AppColor.greenColor, width: 2)),
                          child: Center(
                            child: Text(
                              '${'Passenger Name is'.tr} ${res['first_name']} ${res['last_name']} ',
                              style: AppStyle.title,
                            ),
                          ),
                        ),
                        const SizedBox(
                          height: 10,
                        ),
                        Container(
                          width: Get.width * .8,
                          decoration: BoxDecoration(
                              border: Border.all(
                                  color: AppColor.yellowColor, width: 2)),
                          child: Center(
                            child: Text(
                              '${'Status is'.tr} ${res['status']}',
                              style: AppStyle.title,
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
                );
        })
      ],
      isleading: true,
    );
  }
}
