import 'package:easy_localization/src/public_ext.dart';
import 'package:flutter/material.dart';
import 'package:mohem_flutter_app/api/profile_api_client.dart';
import 'package:mohem_flutter_app/classes/colors.dart';
import 'package:mohem_flutter_app/classes/utils.dart';
import 'package:mohem_flutter_app/extensions/int_extensions.dart';
import 'package:mohem_flutter_app/extensions/string_extensions.dart';
import 'package:mohem_flutter_app/extensions/widget_extensions.dart';
import 'package:mohem_flutter_app/generated/locale_keys.g.dart';
import 'package:mohem_flutter_app/models/get_employee_address_model.dart';
import 'package:mohem_flutter_app/models/get_employee_basic_details.model.dart';
import 'package:mohem_flutter_app/models/get_employee_phones_model.dart';
import 'package:mohem_flutter_app/models/profile/phone_number_types_modek.dart';
import 'package:mohem_flutter_app/ui/profile/profile.dart';
import 'package:mohem_flutter_app/widgets/app_bar_widget.dart';
import 'package:mohem_flutter_app/widgets/button/default_button.dart';
import 'package:mohem_flutter_app/widgets/dynamic_forms/dynamic_textfield_widget.dart';

class PhoneNumbers extends StatefulWidget {
  List<GetEmployeePhonesList> getEmployeePhonesList;

  PhoneNumbers({Key? key, required this.getEmployeePhonesList}) : super(key: key);

  @override
  _PhoneNumbersState createState() => _PhoneNumbersState();
}

class _PhoneNumbersState extends State<PhoneNumbers> {
  List<GetPhoneNumberTypesModel> getPhoneNumberTypesList = [];
  @override
  void initState() {
    super.initState();
    getPhoneNumberTypes();
  }

  void getPhoneNumberTypes() async {
    Utils.showLoading(context);
    getPhoneNumberTypesList = await ProfileApiClient().getPhoneNumberTypes();
    setState(() {});
    Utils.hideLoading(context);
  }

  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBarWidget(
          context,
          title: LocaleKeys.profile_contactDetails.tr(),
        ),
        backgroundColor: MyColors.backgroundColor,
        bottomSheet: footer(),
        body: Column(children: [
          Container(
              width: double.infinity,
              margin: EdgeInsets.only(
                top: 20,
                left: 26,
                right: 26,
              ),
              padding: EdgeInsets.only(left: 14, right: 14, top: 5, bottom: 20),
              height: 400,
              decoration: BoxDecoration(
                boxShadow: [
                  BoxShadow(
                    color: Colors.grey.withOpacity(0.5),
                    spreadRadius: 5,
                    blurRadius: 26,
                    offset: Offset(0, 3),
                  ),
                ],
                color: Colors.white,
                borderRadius: BorderRadius.circular(10.0),
              ),
              child: SingleChildScrollView(
                  child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: widget.getEmployeePhonesList
                          .map((e) => Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
                                PopupMenuButton(
                                    child: DynamicTextFieldWidget(
                                      "Please Select *",
                                      e.pHONETYPEMEANING ?? "",
                                      isEnable: true,
                                      isPopup: true,
                                    ).paddingOnly(bottom: 12),
                                    itemBuilder: (_) => <PopupMenuItem<int>>[
                                          for (int i = 0; i < getPhoneNumberTypesList.length; i++) PopupMenuItem<int>(child: Text(getPhoneNumberTypesList![i].mEANING!), value: i),
                                        ],
                                    onSelected: (int index) {
                                      e.pHONETYPEMEANING = getPhoneNumberTypesList[index].mEANING;
                                      setState(() {});
                                    }),
                                "${e.pHONENUMBER}".toText16(isBold: true, color: MyColors.blackColor),
                              ]))
                          .toList())))
        ]));
  }

  footer() {
    return Container(
      decoration: BoxDecoration(
        // borderRadius: BorderRadius.circular(10),
        color: MyColors.white,
        boxShadow: [
          BoxShadow(color: MyColors.lightGreyEFColor, spreadRadius: 3),
        ],
      ),
      child: DefaultButton(LocaleKeys.update.tr(), () async {
        //     context.setLocale(const Locale("en", "US")); // to change Loacle
        Profile();
      }).insideContainer,
    );
  }

  updatePhone() {}
}
