import 'package:flutter/material.dart';
import 'package:hub/components/organism_components/local_profile_component/local_profile_component_model.dart';
import 'package:hub/components/organism_components/menu_component/menu_component_model.dart';
import 'package:hub/components/organism_components/message_well_component/message_well_component_model.dart';
import 'package:hub/flutter_flow/flutter_flow_model.dart';
import 'package:hub/pages/home_page/home_page_widget.dart';
import 'package:hub/shared/helpers/base_storage.dart';
import 'package:hub/shared/helpers/storage_helper.dart';

class HomePageModel extends FlutterFlowModel<HomePageWidget> {
  bool isGrid = false;
  late final String devUUID;
  late final String cliUUID;
  late final String userUUID;
  late final String userName;
  late final String userEmail;

  final unfocusNode = FocusNode();
  FocusNode? textFieldFocusNode;
  TextEditingController? textController;
  String? Function(BuildContext, String?)? textControllerValidator;
  late LocalProfileComponentModel localComponentModel;
  late MenuComponentModel menuComponentModel;
  late MessageWellComponentModel messageWellComponentModel;

  Future<void> _initVariable() async {
    devUUID = (await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? '';
    userUUID = (await StorageHelper().get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? '';
    cliUUID = (await StorageHelper().get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? '';
    userName = (await StorageHelper().get(SQLiteStorageKey.userName.value, Storage.SQLiteStorage)) ?? '';
    userEmail = (await StorageHelper().get(SecureStorageKey.email.value, Storage.SecureStorage)) ?? '';
  }

  @override
  void initState(BuildContext context) {
    _initVariable();
    localComponentModel = createModel(context, () => LocalProfileComponentModel());
    menuComponentModel = createModel(context, () => MenuComponentModel());
    messageWellComponentModel = createModel(context, () => MessageWellComponentModel());
  }

  @override
  void dispose() {
    unfocusNode.dispose();
    textFieldFocusNode?.dispose();
    textController?.dispose();

    localComponentModel.dispose();
    menuComponentModel.dispose();
    messageWellComponentModel.dispose();
  }
}
