import '../parent/ParentViewModel.dart';
import 'ConnectSplash.dart';

class ViewSplash extends ParentViewModel {
  ConnectSplash connection;

  ViewSplash(super.context, this.connection);

  void initialize() {
    // App opens feed the distress conjunction, so the count is bumped before
    // anything else happens.
    _recordEngagement();

    getDataManager().getMyDescription().then((value) {
      if (value.token != "") {
        connection.launchHome(value);
      } else {
        connection.launchLogin();
      }
    }).onError((error, stackTrace) {
      connection.launchLogin();
    });
  }

  void _recordEngagement() async {
    final int count = await getDataManager().getEngagementCount();
    await getDataManager().setEngagementCount(count + 1);
  }
}
