import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:satu/core/models/dialog_models.dart';
import 'package:satu/core/redux/actions/sell_actions.dart';
import 'package:satu/core/redux/store.dart';
import 'package:satu/core/services/dialog_service.dart';
import 'package:satu/core/utils/locator.dart';
import 'package:satu/shared/app_colors.dart';

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

  final bool itemsExist;
  final String title;

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.only(left: 15, right: 5, top: 15),
      child: Row(
        children: [
          Expanded(
            child: Padding(
              padding: const EdgeInsets.symmetric(vertical: 10),
              child: Text(
                title,
                style: const TextStyle(fontSize: 12, color: placeholderColor),
              ),
            ),
          ),
          if (itemsExist)
            TextButton(
              onPressed: () async {
                final DialogResponse response =
                    await locator<DialogService>().showConfirmationDialog(
                  title: 'Внимание',
                  description: 'Удалить все товары из списка?',
                  confirmationTitle: 'Удалить',
                  cancelTitle: 'Отмена',
                );
                if (response.confirmed == true) {
                  Redux.store!.dispatch(removeAllSellData);
                }
              },
              child: Text(
                'Удалить все',
                style: TextStyle(fontSize: 16.sp, color: dangerColor),
              ),
            )
        ],
      ),
    );
  }
}
