import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../../../../constant/colors.dart';
import '../../../../constant/style.dart';
import '../../../../controller/auth/captin/history_captain.dart';
import '../../../widgets/elevated_btn.dart';
import '../../../widgets/my_scafold.dart';
import '../../../widgets/mycircular.dart';

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

  @override
  Widget build(BuildContext context) {
    Get.put(HistoryCaptainController());
    return MyScafolld(
      title: 'History Page'.tr,
      body: [
        GetBuilder<HistoryCaptainController>(
            builder: (historyCaptainController) => historyCaptainController
                    .isloading
                ? const MyCircularProgressIndicator()
                : historyCaptainController.historyData['message'].length < 1
                    ? Center(
                        child: Text(
                          'No ride Yet.'.tr,
                          style: AppStyle.headTitle,
                        ),
                      )
                    : ListView.builder(
                        itemCount: historyCaptainController
                            .historyData['message'].length,
                        itemBuilder: (BuildContext context, int index) {
                          var list = historyCaptainController
                              .historyData['message'][index];
                          return InkWell(
                            onTap: () {
                              list['status'] != 'Cancel'
                                  ? historyCaptainController
                                      .getHistoryDetails(list['order_id'])
                                  : Get.defaultDialog(
                                      title: 'This Trip Cancelled'.tr,
                                      middleText: '',
                                      titleStyle: AppStyle.title,
                                      confirm: MyElevatedButton(
                                          title: 'Ok'.tr,
                                          onPressed: () => Get.back()));
                            },
                            child: Card(
                              child: Padding(
                                padding: const EdgeInsets.all(8.0),
                                child: Row(
                                  mainAxisAlignment:
                                      MainAxisAlignment.spaceBetween,
                                  children: [
                                    Column(
                                      crossAxisAlignment:
                                          CrossAxisAlignment.start,
                                      children: [
                                        Text(
                                          'OrderId'.tr,
                                          style: AppStyle.title,
                                        ),
                                        Text(
                                          list['order_id'],
                                          style: AppStyle.subtitle,
                                        ),
                                      ],
                                    ),
                                    Column(
                                      crossAxisAlignment:
                                          CrossAxisAlignment.start,
                                      children: [
                                        Text(
                                          'created time'.tr,
                                          style: AppStyle.title,
                                        ),
                                        Text(
                                          list['created_at'],
                                          style: AppStyle.subtitle,
                                        ),
                                      ],
                                    ),
                                    Text(
                                      list['status'],
                                      style: list['status'] == 'Apply'
                                          ? AppStyle.title.copyWith(
                                              color: AppColor.greenColor)
                                          : list['status'] == 'Refused'
                                              ? AppStyle.title.copyWith(
                                                  color: AppColor.redColor)
                                              : AppStyle.title.copyWith(
                                                  color: AppColor.yellowColor),
                                    ),
                                  ],
                                ),
                              ),
                            ),
                          );
                        },
                      ))
      ],
      isleading: true,
    );
  }
}
