import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:ride/constant/box_name.dart';
import 'package:ride/constant/style.dart';
import 'package:ride/controller/profile/captain_profile_controller.dart';
import 'package:ride/env/env.dart';
import 'package:ride/main.dart';
import 'package:ride/views/widgets/elevated_btn.dart';
import 'package:ride/views/widgets/my_scafold.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(
                          "${Env.serverPHP}/card_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 :${box.read(BoxName.emailDriver)}',
                          style: AppStyle.title),
                      const SizedBox(height: 8.0),
                      Text('Phone Number is :${box.read(BoxName.phoneDriver)}',
                          style: AppStyle.title),
                      const SizedBox(height: 8.0),
                      Text('Date of Birth is :${box.read(BoxName.dobDriver)}',
                          style: AppStyle.title),
                      const SizedBox(height: 8.0),
                      Text('Sex is :${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 :${box.read(BoxName.vin)}',
                          style: AppStyle.title),
                      const SizedBox(height: 8.0),
                      Text('Color is  :${box.read(BoxName.color)}',
                          style: AppStyle.title),
                      const SizedBox(height: 8.0),
                      Text('Make is :${box.read(BoxName.make)}',
                          style: AppStyle.title),
                      const SizedBox(height: 8.0),
                      Text('Model is :${box.read(BoxName.model)}',
                          style: AppStyle.title),
                      const SizedBox(height: 8.0),
                      Text('Year is :${box.read(BoxName.year)}',
                          style: AppStyle.title),
                      const SizedBox(height: 8.0),
                      Text(
                          'Expiration Date  :${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',
                  titleStyle: AppStyle.title,
                  content: SizedBox(
                    height: Get.height * .4,
                    child: SingleChildScrollView(
                      child: Column(
                        children: [
                          MyTextForm(
                            controller: controller.vin,
                            hint: 'write vin for your car',
                            label: 'VIN',
                            type: TextInputType.emailAddress,
                          ),
                          MyTextForm(
                            controller: controller.color,
                            hint: 'write Color for your car',
                            label: 'Color',
                            type: TextInputType.emailAddress,
                          ),
                          MyTextForm(
                            controller: controller.make,
                            hint: 'write Make for your car',
                            label: 'Make',
                            type: TextInputType.emailAddress,
                          ),
                          MyTextForm(
                            controller: controller.model,
                            hint: 'write Model for your car',
                            label: 'Model',
                            type: TextInputType.emailAddress,
                          ),
                          MyTextForm(
                            controller: controller.year,
                            hint: 'write Year for your car',
                            label: 'Year',
                            type: TextInputType.number,
                          ),
                          MyTextForm(
                              controller: controller.expirationDate,
                              hint: 'write Expiration Date for your car',
                              label: 'Expiration Date',
                              type: TextInputType.datetime),
                          MyElevatedButton(
                              title: 'Update'.tr,
                              onPressed: () => controller.updateFields())
                        ],
                      ),
                    ),
                  ));
            },
            icon: const Icon(Icons.edit),
          ),
        ));
  }
}
