import 'package:fl_chart/fl_chart.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../../../constant/colors.dart';
import '../../../constant/style.dart';
import '../../../controller/admin/ride_admin_controller.dart';
import '../../widgets/my_scafold.dart';
import '../../widgets/mycircular.dart';

class Rides extends StatelessWidget {
  Rides({super.key});
  RideAdminController rideAdminController = Get.put(RideAdminController());
  @override
  Widget build(BuildContext context) {
    return MyScafolld(title: 'Rides'.tr, isleading: true, body: [
      GetBuilder<RideAdminController>(
          builder: (rideAdminController) => rideAdminController.isLoading
              ? const Center(child: MyCircularProgressIndicator())
              : Column(
                  children: [
                    SizedBox(
                      height: Get.height * .4,
                      child: LineChart(
                        duration: const Duration(milliseconds: 150),
                        curve: Curves.ease,
                        LineChartData(
                          lineBarsData: [
                            LineChartBarData(
                              spots: rideAdminController.chartData,
                              isCurved: true,
                              color: Colors.deepPurpleAccent, // Custom color
                              barWidth: 3, // Thinner line
                              dotData: const FlDotData(
                                  show: true), // Show dots on each point
                              belowBarData: BarAreaData(
                                // Add gradient fill below the line
                                show: true,
                                color: AppColor.deepPurpleAccent,
                              ),
                              isStrokeJoinRound: true,
                              shadow: const BoxShadow(
                                color: AppColor.yellowColor,
                                blurRadius: 4,
                                offset: Offset(2, 2),
                              ),
                            ),
                          ],
                          showingTooltipIndicators: const [],
                          titlesData: FlTitlesData(
                            show: true,
                            topTitles: AxisTitles(
                                axisNameWidget: Text(
                                  'Days',
                                  style: AppStyle.title,
                                ),
                                axisNameSize: 30,
                                sideTitles: const SideTitles(
                                    reservedSize: 30, showTitles: true)),
                            bottomTitles: AxisTitles(
                                axisNameWidget: Text(
                                  'Total Trips on month'.tr,
                                  style: AppStyle.title,
                                ),
                                axisNameSize: 30,
                                sideTitles: const SideTitles(
                                    reservedSize: 30, showTitles: true)),
                            leftTitles: AxisTitles(
                                axisNameWidget: Text(
                                  'Counts of Trips on month'.tr,
                                  style: AppStyle.title,
                                ),
                                axisNameSize: 30,
                                sideTitles: const SideTitles(
                                    reservedSize: 30, showTitles: true)),
                          ),
                          gridData: const FlGridData(
                            show: true,
                          ),
                          borderData: FlBorderData(
                            show: true,
                            border: const Border(
                              bottom: BorderSide(color: AppColor.accentColor),
                              left: BorderSide(color: AppColor.accentColor),
                            ),
                          ),
                        ),
                      ),
                    ),
                    // SizedBox(
                    //   height: Get.height * .4,
                    //   child: PieChart(
                    //     PieChartData(
                    //       sectionsSpace: 4, // Adjust spacing between sections
                    //       centerSpaceRadius:
                    //           40, // Adjust radius of center space
                    //       sections: [
                    //         for (final rideData in rideAdminController.rideData)
                    //           PieChartSectionData(
                    //             value: rideData.ridesCount.toDouble(),
                    //             title: '${rideData.day}', showTitle: true,
                    //             titleStyle:
                    //                 AppStyle.subtitle, // Display day as title
                    //             radius: 60, // Adjust radius of each section
                    //             color:
                    //                 AppColor.deepPurpleAccent, // Custom color
                    //           ),
                    //       ],
                    //     ),
                    //   ),
                    // ),

                    // SizedBox(
                    //   // height: 400,
                    //   child: SfCartesianChart(
                    //     legend: const Legend(
                    //       isVisible: true,
                    //       position: LegendPosition.bottom,
                    //       overflowMode: LegendItemOverflowMode.wrap,
                    //       textStyle: TextStyle(
                    //         color: Colors.white,
                    //         fontSize: 12,
                    //         fontWeight: FontWeight.bold,
                    //       ),
                    //     ),
                    //     borderWidth: 2,
                    //     borderColor: AppColor.blueColor,
                    //     plotAreaBorderColor: AppColor.deepPurpleAccent,
                    //     enableAxisAnimation: true,
                    //     primaryXAxis: CategoryAxis(
                    //       borderColor: AppColor.accentColor, borderWidth: 2,
                    //       title: AxisTitle(
                    //         text: 'Total Trips on month'.tr,
                    //         textStyle: AppStyle.title,
                    //       ),
                    //       // labelRotation: 45,
                    //       majorGridLines: const MajorGridLines(width: 0),
                    //     ),
                    //     primaryYAxis: const NumericAxis(isVisible: false),
                    //     series: <LineSeries<ChartDataS, String>>[
                    //       LineSeries<ChartDataS, String>(
                    //         dataSource: rideAdminController.chartDatasync,
                    //         xValueMapper: (ChartDataS data, _) => '${data.day}',
                    //         yValueMapper: (ChartDataS data, _) =>
                    //             data.ridesCount,
                    //         dataLabelSettings:
                    //             const DataLabelSettings(isVisible: true),
                    //       ),
                    //     ],
                    //   ),
                    // ),

                    const SizedBox(
                      height: 20,
                    ),
                    Card(
                      elevation: 4,
                      color: AppColor.deepPurpleAccent,
                      child: Padding(
                        padding: const EdgeInsets.all(8.0),
                        child: Text(
                          'Total Trips on this Month is ${rideAdminController.jsonResponse['message'][0]['current_month_rides_count']}',
                          style: AppStyle.title,
                        ),
                      ),
                    ),
                    const SizedBox(
                      height: 20,
                    ),
                    Card(
                      elevation: 4,
                      color: AppColor.yellowColor,
                      child: Padding(
                        padding: const EdgeInsets.all(8.0),
                        child: Column(
                          children: [
                            Text(
                              'Driver Average Duration: ${rideAdminController.ridesDetails[0]['driver_avg_duration']}',
                              style: AppStyle.subtitle,
                            ),
                            Text(
                              'Number of Drivers: ${rideAdminController.ridesDetails[0]['num_Driver']}',
                              style: AppStyle.subtitle,
                            ),
                            Text(
                              'Total Rides: ${rideAdminController.ridesDetails[0]['total_rides']}',
                              style: AppStyle.subtitle,
                            ),
                            Text(
                              'Ongoing Rides: ${rideAdminController.ridesDetails[0]['ongoing_rides']}',
                              style: AppStyle.subtitle,
                            ),
                            Text(
                              'Completed Rides: ${rideAdminController.ridesDetails[0]['completed_rides']}',
                              style: AppStyle.subtitle,
                            ),
                            Text(
                              'Cancelled Rides: ${rideAdminController.ridesDetails[0]['cancelled_rides']}',
                              style: AppStyle.subtitle,
                            ),
                            Text(
                              'Longest Duration: ${rideAdminController.ridesDetails[0]['longest_duration']}',
                              style: AppStyle.subtitle,
                            ),
                            Text(
                              'Total Distance: ${rideAdminController.ridesDetails[0]['total_distance']} km',
                              style: AppStyle.subtitle,
                            ),
                            Text(
                              'Average Distance: ${rideAdminController.ridesDetails[0]['average_distance']} km',
                              style: AppStyle.subtitle,
                            ),
                            Text(
                              'Longest Distance: ${rideAdminController.ridesDetails[0]['longest_distance']} km',
                              style: AppStyle.subtitle,
                            ),
                            Text(
                              'Total Driver Earnings: \$${rideAdminController.ridesDetails[0]['total_driver_earnings']}',
                              style: AppStyle.subtitle,
                            ),
                            Text(
                              'Total Company Earnings: \$${rideAdminController.ridesDetails[0]['total_company_earnings']}',
                              style: AppStyle.subtitle,
                            ),
                            Text(
                              'Company Percentage: ${rideAdminController.ridesDetails[0]['companyPercent']} %',
                              style: AppStyle.subtitle,
                            ),
                          ],
                        ),
                      ),
                    )
                  ],
                ))
    ]);
  }
}
