import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.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/shared/shared_styles.dart';
import 'package:satu/widgets/dialog/modal_select_dialog.dart';

class ProductsTitleBarBar extends StatelessWidget {
  final bool itemsExist;
  final String title;

  const ProductsTitleBarBar({Key? key, this.itemsExist = false, required this.title}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Padding(
        padding: EdgeInsets.only(left: 15.w, right: 5.w, top: 30.w),
        child: Row(
          children: [
            Expanded(
                child: Padding(
                  padding: EdgeInsets.symmetric( vertical: 10.w ),
                  child: Text(
                    title,
              style: TextStyle(fontSize: 16.sp, color: placeholderColor),
            ),
                )),
            if(itemsExist)
            TextButton(
                onPressed: () async {
                  bool? result = await showDialog(
                    context: context,
                    builder: (BuildContext context) {
                      return AlertDialog(
                        title: const Text("Внимание"),
                        content: Text("Удалить все товары из списка"),
                        actions: <Widget>[
                          TextButton(onPressed: () => Navigator.of(context).pop(true), child: const Text("Удалить")),
                          TextButton(
                            onPressed: () => Navigator.of(context).pop(false),
                            child: const Text("Отмена"),
                          ),
                        ],
                      );
                    },
                  );
                  if(result == true)
                    Redux.store!.dispatch(removeAllSellData);
                },
                child: Text(
                  'Удалить все',
                  style: TextStyle(fontSize: 16.sp, color: dangerColor),
                ))
          ],
        ),
      ),
    );
  }
}
