// import 'package:file_picker/file_picker.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:tour_travel_agr/helper/components_widget/custom_appbar.dart';
import 'package:tour_travel_agr/helper/components_widget/widget_button.dart';
import 'package:tour_travel_agr/helper/components_widget/widget_text_field.dart';
import 'package:tour_travel_agr/helper/widget_responsive.dart';
import 'package:tour_travel_agr/resource/assets.dart';
import 'package:tour_travel_agr/resource/colors.dart';
import 'package:tour_travel_agr/resource/size.dart';

class EditProfileView extends StatefulWidget {
  const EditProfileView({super.key});

  @override
  State<EditProfileView> createState() => _EditProfileViewState();
}

class _EditProfileViewState extends State<EditProfileView> {
  final TextEditingController nameController = TextEditingController();
  final TextEditingController nikController = TextEditingController();
  final TextEditingController hpController = TextEditingController();

  Uint8List? byteImage;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: ColorManager.backgroundColor,
      body: ScreenResponsive(
        widget: bodyWidget(context),
        widthScreen: MediaQuery.of(context).size.width,
      ),
    );
  }

  Container bodyWidget(BuildContext context) {
    return Container(
      padding: EdgeInsets.only(
        top: AppPadding.safeAreaTop(context),
        left: AppPadding.p20,
        right: AppPadding.p20,
        bottom: AppPadding.safeAreaBot(context),
      ),
      child: Column(
        children: [
          const CustomAppBar(text: "Edit Profile"),
          Expanded(
            child: SingleChildScrollView(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  GestureDetector(
                    onTap: () async {
                      // TODO: aktifin kalau udah dinaikin versiondartnya
                      // FilePickerResult? result =
                      //     await FilePicker.platform.pickFiles();
                      // if (result != null) {
                      //   PlatformFile file = result.files.first;

                      //   // print(file.name);
                      //   // print(file.bytes);
                      //   // print(file.size);
                      //   // print(file.extension);
                      //   // print(file);
                      //   setState(() {
                      //     byteImage = file.bytes;
                      //   });
                      //   // print(file.path);
                      // } else {
                      //   // User canceled the picker
                      // }
                    },
                    child: Container(
                      margin: EdgeInsets.only(
                        top: AppMargin.m12,
                      ),
                      width: 112,
                      height: 112,
                      decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(100),
                        color: const Color.fromARGB(255, 235, 232, 232),
                      ),
                      child: (byteImage == null)
                          ? Image(
                              width: 52,
                              height: 52,
                              image: AssetImage(
                                Assets.editProfileSample,
                              ),
                            )
                          : ClipRRect(
                              borderRadius: BorderRadius.circular(100),
                              child: Image.memory(
                                byteImage!,
                                fit: BoxFit.fill,
                              ),
                            ),
                    ),
                  ),
                  InputTextField(
                    controller: nameController,
                    labelText: "Nama Lengkap",
                    labelColor: ColorManager.primary,
                    borderSideActive: true,
                    hintText: "Nama Lengkap",
                    marginTop: 18,
                  ),
                  InputTextField(
                    controller: nikController,
                    labelText: "NIK",
                    labelColor: ColorManager.primary,
                    borderSideActive: true,
                    hintText: "Nomor Induk Kependudukan",
                    marginTop: 12,
                  ),
                  InputTextField(
                    controller: hpController,
                    labelText: "Nomor Handphone",
                    labelColor: ColorManager.primary,
                    borderSideActive: true,
                    hintText: "628....",
                    marginTop: 12,
                    inputType: TextInputType.number,
                  ),
                  Container(
                    margin: const EdgeInsets.only(top: 30),
                    child: const CustomButton(
                      text: "Update",
                    ),
                  )
                ],
              ),
            ),
          )
        ],
      ),
    );
  }
}
