import '/backend/api_requests/api_calls.dart';
import '/components/alert_box_custom_widget.dart';
import '/flutterlib/flutter_drop_down.dart';
import '/flutterlib/flutter_icon_button.dart';
import '/flutterlib/flutter_radio_button.dart';
import '/flutterlib/flutter_theme.dart';
import '/flutterlib/flutter_util.dart';
import '/flutterlib/flutter_widgets.dart';
import '/flutterlib/form_field_controller.dart';
import '/flutterlib/upload_data.dart';
import '/flutterlib/custom_functions.dart' as functions;
import 'new_member_widget.dart' show NewMemberWidget;
import 'package:aligned_dialog/aligned_dialog.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:provider/provider.dart';

class NewMemberModel extends FlutterModel<NewMemberWidget> {
  ///  Local state fields for this component.

  dynamic companyID;

  bool uploadPhoto = false;

  bool reuploadPhoto = false;

  ///  State fields for stateful widgets in this component.

  final formKey = GlobalKey<FormState>();
  // State field(s) for position widget.
  FormFieldController<String>? positionValueController;
  // State field(s) for title widget.
  String? titleValue;
  FormFieldController<String>? titleValueController;
  // State field(s) for name_english widget.
  FocusNode? nameEnglishFocusNode;
  TextEditingController? nameEnglishController;
  String? Function(BuildContext, String?)? nameEnglishControllerValidator;
  String? _nameEnglishControllerValidator(BuildContext context, String? val) {
    if (val == null || val.isEmpty) {
      return FFLocalizations.of(context).getText(
        's47kindu' /* Field is required */,
      );
    }

    return null;
  }

  // State field(s) for name_chinese widget.
  FocusNode? nameChineseFocusNode;
  TextEditingController? nameChineseController;
  String? Function(BuildContext, String?)? nameChineseControllerValidator;
  String? _nameChineseControllerValidator(BuildContext context, String? val) {
    if (val == null || val.isEmpty) {
      return FFLocalizations.of(context).getText(
        'zaflur71' /* Field is required */,
      );
    }

    return null;
  }

  // State field(s) for phone widget.
  FocusNode? phoneFocusNode;
  TextEditingController? phoneController;
  String? Function(BuildContext, String?)? phoneControllerValidator;
  String? _phoneControllerValidator(BuildContext context, String? val) {
    if (val == null || val.isEmpty) {
      return FFLocalizations.of(context).getText(
        '7vcgack8' /* Field is required */,
      );
    }

    return null;
  }

  // State field(s) for email widget.
  FocusNode? emailFocusNode;
  TextEditingController? emailController;
  String? Function(BuildContext, String?)? emailControllerValidator;
  String? _emailControllerValidator(BuildContext context, String? val) {
    if (val == null || val.isEmpty) {
      return FFLocalizations.of(context).getText(
        'w81fu2lr' /* Field is required */,
      );
    }

    if (!RegExp(kTextValidatorEmailRegex).hasMatch(val)) {
      return 'Has to be a valid email address.';
    }
    return null;
  }

  // State field(s) for date widget.
  FocusNode? dateFocusNode;
  TextEditingController? dateController;
  String? Function(BuildContext, String?)? dateControllerValidator;
  String? _dateControllerValidator(BuildContext context, String? val) {
    if (val == null || val.isEmpty) {
      return FFLocalizations.of(context).getText(
        '7yetp4yv' /* Field is required */,
      );
    }

    return null;
  }

  DateTime? datePicked;
  // State field(s) for documentType widget.
  String? documentTypeValue;
  FormFieldController<String>? documentTypeValueController;
  // State field(s) for documentNo widget.
  FocusNode? documentNoFocusNode;
  TextEditingController? documentNoController;
  String? Function(BuildContext, String?)? documentNoControllerValidator;
  String? _documentNoControllerValidator(BuildContext context, String? val) {
    if (val == null || val.isEmpty) {
      return FFLocalizations.of(context).getText(
        'r6lv0t4k' /* Field is required */,
      );
    }

    return null;
  }

  // State field(s) for country widget.
  FocusNode? countryFocusNode;
  TextEditingController? countryController;
  String? Function(BuildContext, String?)? countryControllerValidator;
  String? _countryControllerValidator(BuildContext context, String? val) {
    if (val == null || val.isEmpty) {
      return FFLocalizations.of(context).getText(
        'qv9aw44u' /* Field is required */,
      );
    }

    return null;
  }

  // State field(s) for city widget.
  FocusNode? cityFocusNode;
  TextEditingController? cityController;
  String? Function(BuildContext, String?)? cityControllerValidator;
  // State field(s) for addressEn widget.
  FocusNode? addressEnFocusNode;
  TextEditingController? addressEnController;
  String? Function(BuildContext, String?)? addressEnControllerValidator;
  String? _addressEnControllerValidator(BuildContext context, String? val) {
    if (val == null || val.isEmpty) {
      return FFLocalizations.of(context).getText(
        'i6hy2l1b' /* Field is required */,
      );
    }

    return null;
  }

  // State field(s) for addressCn widget.
  FocusNode? addressCnFocusNode;
  TextEditingController? addressCnController;
  String? Function(BuildContext, String?)? addressCnControllerValidator;
  String? _addressCnControllerValidator(BuildContext context, String? val) {
    if (val == null || val.isEmpty) {
      return FFLocalizations.of(context).getText(
        'mualn9yy' /* Field is required */,
      );
    }

    return null;
  }

  bool isDataUploading1 = false;
  FFUploadedFile uploadedLocalFile1 =
      FFUploadedFile(bytes: Uint8List.fromList([]));

  bool isDataUploading2 = false;
  FFUploadedFile uploadedLocalFile2 =
      FFUploadedFile(bytes: Uint8List.fromList([]));

  // Stores action output result for [Backend Call - API (Save or Update Member)] action in Button widget.
  ApiCallResponse? saveMember;
  // Stores action output result for [Backend Call - API (Save or Update Member)] action in Button widget.
  ApiCallResponse? saveMember1;
  // Stores action output result for [Backend Call - API (Save or Update Member)] action in Button widget.
  ApiCallResponse? saveMember2;

  /// Initialization and disposal methods.

  void initState(BuildContext context) {
    nameEnglishControllerValidator = _nameEnglishControllerValidator;
    nameChineseControllerValidator = _nameChineseControllerValidator;
    phoneControllerValidator = _phoneControllerValidator;
    emailControllerValidator = _emailControllerValidator;
    dateControllerValidator = _dateControllerValidator;
    documentNoControllerValidator = _documentNoControllerValidator;
    countryControllerValidator = _countryControllerValidator;
    addressEnControllerValidator = _addressEnControllerValidator;
    addressCnControllerValidator = _addressCnControllerValidator;
  }

  void dispose() {
    nameEnglishFocusNode?.dispose();
    nameEnglishController?.dispose();

    nameChineseFocusNode?.dispose();
    nameChineseController?.dispose();

    phoneFocusNode?.dispose();
    phoneController?.dispose();

    emailFocusNode?.dispose();
    emailController?.dispose();

    dateFocusNode?.dispose();
    dateController?.dispose();

    documentNoFocusNode?.dispose();
    documentNoController?.dispose();

    countryFocusNode?.dispose();
    countryController?.dispose();

    cityFocusNode?.dispose();
    cityController?.dispose();

    addressEnFocusNode?.dispose();
    addressEnController?.dispose();

    addressCnFocusNode?.dispose();
    addressCnController?.dispose();
  }

  /// Action blocks are added here.

  /// Additional helper methods are added here.

  String? get positionValue => positionValueController?.value;
}
