import 'package:flutter/material.dart';
import 'package:flutter_split_view/flutter_split_view.dart';
import 'package:persistent_bottom_nav_bar_v2/persistent_bottom_nav_bar_v2.dart';

class TalkNavigator {
  static bool hasSplitViewState(BuildContext context) =>
      context.findAncestorStateOfType<SplitViewState>() != null;
  static bool isSecondaryVisible(BuildContext context) =>
      hasSplitViewState(context) && SplitView.of(context).isSecondaryVisible;

  static void pushSplitView(
    BuildContext context,
    Widget view, {
    bool overrideToSingleSubScreen = false,
  }) {
    if (isSecondaryVisible(context)) {
      var splitView = SplitView.of(context);
      overrideToSingleSubScreen
          ? splitView.setSecondary(view)
          : splitView.push(view);
    } else {
      pushScreen(context, screen: view, withNavBar: false);
    }
  }
}
