import 'package:flutter/material.dart';
import 'package:flutter_redux/flutter_redux.dart';
import 'package:satu/core/models/settings/printer_setting.dart';
import 'package:satu/core/redux/actions/setting_actions.dart';
import 'package:satu/core/redux/store.dart';
import 'package:satu/widgets/bar/products_app_bar.dart';
import 'package:satu/widgets/bar/products_title_bar.dart';
import 'package:satu/widgets/fields/line_checkbox.dart';

class PrinterEncodingView extends StatelessWidget {
  const PrinterEncodingView({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: const ProductsAppBar(
        title: 'Кодировка печати',
      ),
      body: StoreConnector<AppState,PrinterSetting>(
        converter: (store) => store.state.settingState!.printer!,
        builder: (context, printer) {
          return Column(children: [
            const ProductsTitleBarBar(title: 'Выберите кодировку принтера'),
            LineCheckBox(
              PrinterConst.encodingCP866,
              value: printer.encoding == PrinterConst.encodingCP866,
              onTap: () => {
                Redux.store!.dispatch(
                  setEncodingPrint(PrinterConst.encodingCP866),
                )
              },
            ),
            const Divider(height: 1,),
            LineCheckBox(
              PrinterConst.encodingCP1251,
              value: printer.encoding == PrinterConst.encodingCP1251,
              onTap: () => {
                Redux.store!.dispatch(
                  setEncodingPrint(PrinterConst.encodingCP1251),
                )
              },
            ),
            const Divider(height: 1,),
            LineCheckBox(
              PrinterConst.encodingBigEncoding,
              value: printer.encoding == PrinterConst.encodingBigEncoding,
              onTap: () => {
                Redux.store!.dispatch(
                  setEncodingPrint(PrinterConst.encodingBigEncoding),
                )
              },
            ),
          ]);
        }
      ),
    );
  }
}
