import 'package:SEFER/constant/colors.dart';
import 'package:SEFER/constant/style.dart';
import 'package:SEFER/controller/firebase/firbase_messge.dart';
import 'package:SEFER/controller/home/map_passenger_controller.dart';
import 'package:SEFER/controller/functions/call_controller.dart';
import 'package:SEFER/views/widgets/my_scafold.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:SEFER/controller/home/captin/home_captain_controller.dart';

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

  @override
  Widget build(BuildContext context) {
    return MyScafolld(
        title: 'Call Page'.tr, isleading: true, body: [callPage()]);
  }
}

GetBuilder<HomeCaptainController> callPage() {
  CallController callController = Get.put(CallController());
  // callController.initAgoraFull();
  return GetBuilder<HomeCaptainController>(
    builder: (controller) => Column(
      children: [
        Padding(
          padding: const EdgeInsets.all(15),
          child: Container(
            decoration: AppStyle.boxDecoration1,
            child: Text(
              'No SIM card, no problem! Call your driver directly through our app. We use advanced technology to ensure your privacy.'
                  .tr,
              style: AppStyle.title,
            ),
          ),
        ),
        const SizedBox(
          height: 30,
        ),
        Padding(
          padding: const EdgeInsets.all(15),
          child: Container(
            height: 100, width: Get.width,
            decoration: AppStyle.boxDecoration,
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              children: [
                GestureDetector(
                  onTap: () async {
                    // await callController.initAgoraFull();
                    // callController.join();
                    // FirebaseMessagesController().sendNotificationToPassengerToken(
                    //   'Call Income',
                    //   'You have call from driver ${box.read(BoxName.nameDriver)}',
                    //   Get.find<MapDriverController>().tokenPassenger,
                    //   [
                    //     callController.token,
                    //     callController.channelName,
                    //     callController.uid.toString(),
                    //     callController.remoteUid.toString(),
                    //   ],
                    // );
                    callController.join();
                  },
                  child: Container(
                      width: 50,
                      height: 50,
                      decoration: const BoxDecoration(
                          shape: BoxShape.circle, color: AppColor.greenColor),
                      child: const Icon(
                        Icons.phone,
                        size: 35,
                        color: AppColor.secondaryColor,
                      )),
                ),
                Column(
                  children: [
                    Text(callController.status),
                    Text(Get.find<MapPassengerController>()
                        .driverName
                        .toString()),
                  ],
                ),
                GestureDetector(
                  onTap: () async {
                    FirebaseMessagesController()
                        .sendNotificationToPassengerToken(
                      'Call End',
                      'Call End'.tr,
                      Get.find<MapPassengerController>().driverToken,
                      [],
                    );
                    callController.leave();
                    Get.back();
                  },
                  child: Container(
                      width: 50,
                      height: 50,
                      decoration: const BoxDecoration(
                          shape: BoxShape.circle, color: AppColor.redColor),
                      child: const Icon(
                        Icons.phone_disabled_sharp,
                        size: 35,
                        color: AppColor.secondaryColor,
                      )),
                )
              ],
            ),
            // ignore: prefer_const_constructors
          ),
        ),
      ],
    ),
  );
}
