import 'package:flutter/material.dart';
import 'package:hub/components/templates_components/visitor_search_modal_template_component/visitor_search_modal_template_component_widget.dart';
import 'package:hub/features/backend/index.dart';
import 'package:hub/features/storage/index.dart';
import 'package:hub/flutter_flow/flutter_flow_model.dart';

class VisitorSearchModalTemplateComponentModel
    extends FlutterFlowModel<VisitorSearchModalTemplateComponentWidget> {
  late final String devUUID;
  late final String userUUID;
  late final String cliUUID;

  List<dynamic> visitors = [];
  void addToVisitors(dynamic item) => visitors.add(item);
  void removeFromVisitors(dynamic item) => visitors.remove(item);
  void removeAtIndexFromVisitors(int index) => visitors.removeAt(index);
  void insertAtIndexInVisitors(int index, dynamic item) =>
      visitors.insert(index, item);
  void updateVisitorsAtIndex(int index, Function(dynamic) updateFn) =>
      visitors[index] = updateFn(visitors[index]);

  List<String> docs = [];
  void addToDocs(String item) => docs.add(item);
  void removeFromDocs(String item) => docs.remove(item);
  void removeAtIndexFromDocs(int index) => docs.removeAt(index);
  void insertAtIndexInDocs(int index, String item) => docs.insert(index, item);
  void updateDocsAtIndex(int index, Function(String) updateFn) =>
      docs[index] = updateFn(docs[index]);

  FocusNode? textFieldFocusNode;
  TextEditingController? textController;
  String? Function(BuildContext, String?)? textControllerValidator;
  ApiCallResponse? getVisitorByDoc;

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

  Future<void> initDatabase() 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() {
    textFieldFocusNode?.dispose();
    textController?.dispose();
  }
}
