import 'package:flutter/material.dart';

import 'package:satu/core/redux/actions/sell_actions.dart';
import 'package:satu/core/redux/store.dart';
import 'package:satu/views/work/tabs/buy_view.dart';
import 'package:satu/views/work/tabs/journal_view.dart';
import 'package:satu/views/work/tabs/sell_view.dart';
import 'package:satu/widgets/bar/bottom_bar.dart';

class WorkView extends StatefulWidget {
  const WorkView({Key? key}) : super(key: key);

  @override
  _WorkViewState createState() => _WorkViewState();
}

class _WorkViewState extends State<WorkView> {
  int _selectedIndex = 0;
  final List<Widget> _widgetOptions = <Widget>[
    SellView(),
    BuyView(),
    JournalView(),
  ];

  @override
  void initState() {
    super.initState();
    // state sell view
    Redux.store!.dispatch(loadSellData);
  }

  void _onItemTapped(int index) {
    setState(() {
      _selectedIndex = index;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: _widgetOptions.elementAt(_selectedIndex),
      bottomNavigationBar: BottomBar(
        selectedIndex: _selectedIndex,
        onTap: _onItemTapped,
      ),
    );
  }
}
