import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:SEFER/controller/admin/captain_admin_controller.dart';
import 'package:SEFER/views/admin/captain/captain_details.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';

GetBuilder<CaptainAdminController> formSearchCaptain() {
  // DbSql sql = DbSql.instance;
  return GetBuilder<CaptainAdminController>(
      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.captainController.text.length > 4) {
                              await controller.getCaptains();

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