import 'package:flutter/material.dart';
import 'package:flutter_redux/flutter_redux.dart';
import 'package:satu/core/redux/state/nav_state.dart';
import 'package:satu/core/redux/store.dart';
import 'package:satu/core/services/navigator_service.dart';
import 'package:satu/core/utils/locator.dart';
import 'package:satu/views/settings/printer_bluetooth/PrinterSelect.dart';
import 'package:satu/views/settings/setting_view.dart';
import 'package:satu/views/work/work_view.dart';
import 'package:satu/widgets/drawer/app_drawer.dart';

class MainView extends StatefulWidget {
  @override
  _MainViewState createState() => _MainViewState();
}

class _MainViewState extends State<MainView> {

  NavigatorService _navigatorService = locator<NavigatorService>();

  final _workView = new WorkView(text: '1',);
  final _settingsView = new SettingsView();

  Widget _body(Type viewClass) {
    if(viewClass == WorkView) {
      return _workView;
    }
    if(viewClass == SettingsView) {
      return _settingsView;
    }
    return _workView;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      key: _navigatorService.scaffoldDrawerKey,
      drawer: AppDrawer(),
      body: StoreConnector<AppState, NavState>(
          converter: (store) => store.state.navState!,
          builder: (_, vm) {
            return _body(vm.drawerViewClass!);
          })
    );
  }
}
