import 'package:hub/app_state.dart';
import 'package:hub/backend/api_requests/api_calls.dart';
import 'package:hub/backend/api_requests/api_manager.dart';
import 'package:hub/components/templates_components/liberation_history_item_details_template_component/liberation_history_item_details_template_component_widget.dart';

import 'package:hub/flutter_flow/flutter_flow_model.dart';

import 'package:flutter/material.dart';

class LiberationHistoryItemDetailsTemplateComponentModel
    extends FlutterFlowModel<
        LiberationHistoryItemDetailsTemplateComponentWidget> {
  ///  State fields for stateful widgets in this component.

  // State field(s) for TextField widget.
  FocusNode? textFieldFocusNode1;
  TextEditingController? textController1;
  String? Function(BuildContext, String?)? textController1Validator;
  // State field(s) for TextField widget.
  FocusNode? textFieldFocusNode2;
  TextEditingController? textController2;
  String? Function(BuildContext, String?)? textController2Validator;
  // State field(s) for TextField widget.
  FocusNode? textFieldFocusNode3;
  TextEditingController? textController3;
  String? Function(BuildContext, String?)? textController3Validator;
  // State field(s) for TextField widget.
  FocusNode? textFieldFocusNode4;
  TextEditingController? textController4;
  String? Function(BuildContext, String?)? textController4Validator;

  @override
  void initState(BuildContext context) {}

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

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

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

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

  /// Action blocks.
  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(
      userUUID: FFAppState().userUUID,
      devUUID: FFAppState().devUUID,
      cliUUID: FFAppState().cliUUID,
      atividade: 'respondeSolicitacao',
      referencia: refUUID,
      tarefa: actionValue,
      resposta: responseValue,
      idVisitante: vteUUID,
    );

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