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

import '../../../constant/box_name.dart';
import '../../../constant/colors.dart';
import '../../../constant/style.dart';
import '../../../controller/home/map_passenger_controller.dart';
import '../../../controller/profile/profile_controller.dart';
import '../../../main.dart';

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

  @override
  Widget build(BuildContext context) {
    ProfileController profileController = Get.put(ProfileController());
    return GetBuilder<MapPassengerController>(builder: (controller) {
      return (controller.statusRideFromStart
          // ||  controller.statusRide == 'Begin'
          )
          ? Positioned(
              left: 10,
              right: 10,
              bottom: 4,
              child: Container(
                decoration: AppStyle.boxDecoration1,
                height: Get.height * .3,
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: <Widget>[
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                      children: [
                        Container(
                          width: Get.width * .15,
                          decoration: AppStyle.boxDecoration1,
                          child: Column(
                            children: [
                              Text(
                                '⏱️',
                                style: AppStyle.title,
                              ),
                              Text(
                                box.read(BoxName.arrivalTime),
                                style: AppStyle.title,
                              ),
                            ],
                          ),
                        ),
                        Container(
                          width: Get.width * .15,
                          decoration: AppStyle.boxDecoration1,
                          child: Column(
                            children: [
                              Text(
                                '📍',
                                style: AppStyle.title,
                              ),
                              Text(
                                controller.rideStatusFromStartApp['data']
                                        ['distance']
                                    .toString(),
                                style: AppStyle.title,
                              ),
                            ],
                          ),
                        ),
                        Container(
                          width: Get.width * .15,
                          decoration: AppStyle.boxDecoration1,
                          child: Column(
                            children: [
                              Text(
                                '💵 ',
                                style: AppStyle.title,
                              ),
                              Text(
                                controller.rideStatusFromStartApp['data']
                                    ['price'],
                                style: AppStyle.title,
                              ),
                            ],
                          ),
                        ),
                      ],
                    ),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                      children: [
                        CircleAvatar(
                          radius: 30,
                          backgroundImage: NetworkImage(
                              //   '',
                              // ),
                              'https://ride.mobile-app.store/portrate_captain_image/${controller.rideStatusFromStartApp['data']['driver_id']}.jpg'),
                        ),
                        Text(
                          '${controller.rideStatusFromStartApp['data']['driverName']}',
                          style: AppStyle.title,
                        ),
                        Column(
                          children: [
                            Text(
                              '${controller.rideStatusFromStartApp['data']['rateDriver']} 📈',
                              style: AppStyle.title,
                            ),
                            Text(
                              '${controller.rideStatusFromStartApp['data']['carType']}',
                              style: AppStyle.title,
                            ),
                          ],
                        ),
                      ],
                    ),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceAround,
                      children: [
                        IconButton(
                          onPressed: () async {
                            if (box.read(BoxName.sosPhonePassenger) == null) {
                              {
                                await profileController.updatField(
                                    'sosPhone', TextInputType.phone);
                                box.write(BoxName.sosPhonePassenger,
                                    profileController.prfoileData['sosPhone']);
                              }
                            } else {
                              controller
                                  .sendSMS(box.read(BoxName.sosPhonePassenger));
                            }
                          },
                          icon: const Icon(
                            Icons.sos_rounded,
                            color: AppColor.redColor,
                          ),
                        ),
                        IconButton(
                          onPressed: () async {
                            print(box.read(BoxName.sosPhonePassenger));
                            if (box.read(BoxName.sosPhonePassenger) == null ||
                                box.read(BoxName.sosPhonePassenger) == 'sos') {
                              {
                                await profileController.updatField(
                                    'sosPhone', TextInputType.phone);
                                box.write(BoxName.sosPhonePassenger,
                                    profileController.prfoileData['sosPhone']);
                              }
                            } else {
                              String phoneNumber = box
                                  .read(BoxName.sosPhonePassenger)
                                  .toString();
                              // phoneNumber = phoneNumber.replaceAll('0', '');
                              print(phoneNumber); // Output: 798583061
                              var phone =
                                  // '+${box.read(BoxName.countryCode)}${box.read(BoxName.sosPhonePassenger)}';
                                  '${box.read(BoxName.sosPhonePassenger)}';
                              controller.sendWhatsapp(phone);
                            }
                          },
                          icon: const Icon(
                            FontAwesome.whatsapp,
                            color: AppColor.greenColor,
                          ),
                        ),
                      ],
                    )
                  ],
                ),
              ),
            )
          : const SizedBox();
    });
  }
}
