import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:SEFER/views/admin/passenger/passenger_details_page.dart';
import 'package:SEFER/views/widgets/elevated_btn.dart';

import '../../../constant/colors.dart';
import '../../../constant/style.dart';
import '../../../controller/admin/passenger_admin_controller.dart';

GetBuilder<PassengerAdminController> formSearchPassengers() {
  // DbSql sql = DbSql.instance;
  return GetBuilder<PassengerAdminController>(
      builder: (controller) => Column(
            children: [
              Padding(
                padding: const EdgeInsets.all(16),
                child: Container(
                  decoration:
                      const BoxDecoration(color: AppColor.secondaryColor),
                  child: TextField(
                    decoration: InputDecoration(
                      border: const OutlineInputBorder(
                          borderRadius: BorderRadius.only(),
                          gapPadding: 4,
                          borderSide: BorderSide(
                            color: AppColor.redColor,
                            width: 2,
                          )),
                      suffixIcon: InkWell(
                          onTap: () async {
                            if (controller.passengerController.text.length >
                                4) {
                              await controller.getPassengers();

                              Get.defaultDialog(
                                  title: controller.passengers['message'][0]
                                      ['email'],
                                  titleStyle: AppStyle.title,
                                  content: Column(
                                    mainAxisAlignment:
                                        MainAxisAlignment.spaceBetween,
                                    children: [
                                      Text(
                                        'Name is ${controller.passengers['message'][0]['first_name']} ${controller.passengers['message'][0]['last_name']}',
                                        style: AppStyle.title,
                                      ),
                                      Text(
                                        'phone is ${controller.passengers['message'][0]['phone']}',
                                        style: AppStyle.title,
                                      ),
                                    ],
                                  ),
                                  confirm: MyElevatedButton(
                                      title: 'Go To Details'.tr,
                                      onPressed: () {
                                        Get.to(
                                            () => const PassengerDetailsPage(),
                                            arguments: {
                                              'data': controller
                                                  .passengers['message'][0],
                                            });
                                      }));
                            }
                          },
                          child: const Icon(Icons.search)),
                      hintText: 'Search for Passenger'.tr,
                      hintStyle: AppStyle.title,
                      hintMaxLines: 1,
                      prefixIcon: IconButton(
                        onPressed: () async {
                          controller.passengerController.clear();
                          controller.clearPlaces();
                        },
                        icon: Icon(
                          Icons.clear,
                          color: Colors.red[300],
                        ),
                      ),
                    ),
                    controller: controller.passengerController,
                  ),
                ),
              )
            ],
          ));
}
