import 'package:flutter/material.dart';
import 'package:hub/features/backend/index.dart';
import 'package:hub/features/storage/index.dart';
import 'package:hub/flutter_flow/nav/nav.dart';

import '/flutter_flow/flutter_flow_util.dart';
import 'access_notification_modal_template_component_widget.dart'
    show AccessNotificationModalTemplateComponentWidget;

class AccessNotificationModalTemplateComponentModel
    extends FlutterFlowModel<AccessNotificationModalTemplateComponentWidget> {
  late final String devUUID;
  late final String userUUID;
  late final String cliUUID;

  FocusNode? textFieldFocusNode1;
  TextEditingController? textController1;
  String? Function(BuildContext, String?)? textController1Validator;
  FocusNode? textFieldFocusNode2;
  TextEditingController? textController2;
  String? Function(BuildContext, String?)? textController2Validator;
  FocusNode? textFieldFocusNode3;
  TextEditingController? textController3;
  String? Function(BuildContext, String?)? textController3Validator;
  FocusNode? textFieldFocusNode4;
  TextEditingController? textController4;
  String? Function(BuildContext, String?)? textController4Validator;

  @override
  void initState(BuildContext context) {
    initDB();
  }

  Future<void> initDB() async {
    devUUID = (await StorageHelper().get(ProfileStorageKey.devUUID.key)) ?? '';
    userUUID =
        (await StorageHelper().get(ProfileStorageKey.userUUID.key)) ?? '';
    cliUUID =
        (await StorageHelper().get(ProfileStorageKey.clientUUID.key)) ?? '';
  }

  @override
  void dispose() {
    textFieldFocusNode1?.dispose();
    textController1?.dispose();

    textFieldFocusNode2?.dispose();
    textController2?.dispose();

    textFieldFocusNode3?.dispose();
    textController3?.dispose();

    textFieldFocusNode4?.dispose();
    textController4?.dispose();
  }

  Future<bool> visitRequestComponentAction(
    BuildContext context, {
    required String? actionValue,
    required String? refUUID,
    required String? responseValue,
    required String? vteUUID,
  }) async {
    ApiCallResponse? visitRequest;

    visitRequest = await PhpGroup.respondeSolicitacaoCall.call(
      referencia: refUUID,
      tarefa: actionValue,
      resposta: responseValue,
      idVisitante: vteUUID,
    );

    if (PhpGroup.respondeSolicitacaoCall.error(
          (visitRequest.jsonBody ?? ''),
        ) ==
        false) {
      context.pop();
      return true;
    } else {
      return false;
    }
  }
}
