import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:SEFER/constant/box_name.dart';
import 'package:SEFER/constant/style.dart';
import 'package:SEFER/controller/profile/captain_profile_controller.dart';
import 'package:SEFER/main.dart';
import 'package:SEFER/views/widgets/elevated_btn.dart';
import 'package:SEFER/views/widgets/my_scafold.dart';

import '../../../constant/api_key.dart';
import '../../widgets/my_textField.dart';

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

  @override
  Widget build(BuildContext context) {
    Get.put(CaptainProfileController());
    return MyScafolld(
        title: 'My Profile'.tr,
        body: [
          GetBuilder<CaptainProfileController>(
            builder: (controller) => Padding(
              padding: const EdgeInsets.all(16.0),
              child: SingleChildScrollView(
                child: Center(
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      CircleAvatar(
                        radius: Get.width * 0.26,
                        backgroundColor: Colors.white,
                        backgroundImage: CachedNetworkImageProvider(
                          '${AK.serverPHP}/portrate_captain_image/${box.read(BoxName.driverID)}.jpg',
                        ),
                      ),
                      const SizedBox(height: 8.0),
                      Text(
                          box.read(BoxName.nameDriver) +
                              ' ' +
                              box.read(BoxName.lastNameDriver).toString(),
                          style: AppStyle.title),
                      const SizedBox(height: 8.0),
                      Text('${'Email is'.tr} :${box.read(BoxName.emailDriver)}',
                          style: AppStyle.title),
                      const SizedBox(height: 8.0),
                      Text(
                          '${'Phone Number is'.tr} :${box.read(BoxName.phoneDriver)}',
                          style: AppStyle.title),
                      const SizedBox(height: 8.0),
                      Text(
                          '${'Date of Birth is'.tr} :${box.read(BoxName.dobDriver)}',
                          style: AppStyle.title),
                      const SizedBox(height: 8.0),
                      Text('${'Sex is '.tr}:${box.read(BoxName.sexDriver)}',
                          style: AppStyle.title),
                      const SizedBox(height: 8.0),
                      const Divider(
                        // height: 2,
                        endIndent: 1,
                        indent: 2,
                        thickness: 2,
                      ),
                      const SizedBox(height: 8.0),
                      Text('Car Details'.tr, style: AppStyle.headTitle2),
                      const SizedBox(height: 8.0),
                      Text('${'VIN is'.tr} :${box.read(BoxName.vin)}',
                          style: AppStyle.title),
                      const SizedBox(height: 8.0),
                      Text('${'Color is '.tr} :${box.read(BoxName.color)}',
                          style: AppStyle.title),
                      const SizedBox(height: 8.0),
                      Text(
                          '${'Car Plate is '.tr} :${box.read(BoxName.carPlate)}',
                          style: AppStyle.title),
                      const SizedBox(height: 8.0),
                      Text('${'Make is '.tr}:${box.read(BoxName.make)}',
                          style: AppStyle.title),
                      const SizedBox(height: 8.0),
                      Text('${'Model is'.tr} :${box.read(BoxName.model)}',
                          style: AppStyle.title),
                      const SizedBox(height: 8.0),
                      Text('${'Year is'.tr} :${box.read(BoxName.year)}',
                          style: AppStyle.title),
                      const SizedBox(height: 8.0),
                      Text(
                          '${'Expiration Date '.tr} :${box.read(BoxName.expirationDate)}',
                          style: AppStyle.title),
                      const SizedBox(height: 8.0),
                    ],
                  ),
                ),
              ),
            ),
          )
        ],
        isleading: true,
        action: GetBuilder<CaptainProfileController>(
          builder: (controller) => IconButton(
            onPressed: () {
              Get.defaultDialog(
                  title: 'Edit Your data'.tr,
                  titleStyle: AppStyle.title,
                  content: SizedBox(
                    height: Get.height * .4,
                    child: SingleChildScrollView(
                      child: Column(
                        children: [
                          MyTextForm(
                            controller: controller.vin,
                            hint: 'write vin for your car'.tr,
                            label: 'VIN'.tr,
                            type: TextInputType.emailAddress,
                          ),
                          MyTextForm(
                            controller: controller.color,
                            hint: 'write Color for your car'.tr,
                            label: 'Color'.tr,
                            type: TextInputType.emailAddress,
                          ),
                          MyTextForm(
                            controller: controller.make,
                            hint: 'write Make for your car'.tr,
                            label: 'Make'.tr,
                            type: TextInputType.emailAddress,
                          ),
                          MyTextForm(
                            controller: controller.model,
                            hint: 'write Model for your car'.tr,
                            label: 'Model'.tr,
                            type: TextInputType.emailAddress,
                          ),
                          MyTextForm(
                            controller: controller.year,
                            hint: 'write Year for your car'.tr,
                            label: 'Year'.tr,
                            type: TextInputType.number,
                          ),
                          MyTextForm(
                              controller: controller.expirationDate,
                              hint: 'write Expiration Date for your car'.tr,
                              label: 'Expiration Date'.tr,
                              type: TextInputType.datetime),
                          MyElevatedButton(
                              title: 'Update'.tr,
                              onPressed: () => controller.updateFields())
                        ],
                      ),
                    ),
                  ));
            },
            icon: const Icon(Icons.edit),
          ),
        ));
  }
}
