import 'package:flutter/material.dart';
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';

import 'package:satu/core/redux/actions/sell_actions.dart';
import 'package:satu/core/redux/store.dart';
import 'package:satu/shared/app_colors.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';

class WorkView extends StatefulWidget {
  final String? text;

  const WorkView({Key? key, this.text}) : super(key: key);
  @override
  _WorkViewState createState() => _WorkViewState();
}

class _WorkViewState extends State<WorkView> {
  int _selectedIndex = 0;
  static const TextStyle optionStyle =
  TextStyle(fontSize: 30, fontWeight: FontWeight.bold);
  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: BottomNavigationBar(
        items: const <BottomNavigationBarItem>[
          BottomNavigationBarItem(
            icon: Icon(MdiIcons.cartArrowUp),
            label: 'Продажа',
          ),
          BottomNavigationBarItem(
            icon: Icon(MdiIcons.cartArrowDown),
            label: 'Покупка',
          ),
          BottomNavigationBarItem(
            icon: Icon(MdiIcons.cashRegister),
            label: 'Журнал',
          ),
        ],
        currentIndex: _selectedIndex,
        unselectedItemColor: Colors.black54,
        selectedItemColor: primaryColor,
        selectedLabelStyle: const TextStyle( fontWeight: FontWeight.w600 ),
        backgroundColor: whiteColor,
        elevation: 8.0,
        onTap: _onItemTapped,
      ),
    );
  }
}
