import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:hl_lieferservice/feature/delivery/bloc/tour_bloc.dart';
import 'package:hl_lieferservice/feature/delivery/bloc/tour_event.dart';

import '../../../../../model/article.dart';

class ResetArticleAmountDialog extends StatefulWidget {
  const ResetArticleAmountDialog({
    super.key,
    required this.article,
    required this.deliveryId,
  });

  final Article article;
  final String deliveryId;

  @override
  State<StatefulWidget> createState() => _ResetArticleAmountDialogState();
}

class _ResetArticleAmountDialogState extends State<ResetArticleAmountDialog> {
  void _reset() {
    context.read<TourBloc>().add(
      ResetScanAmountEvent(
        articleId: widget.article.internalId.toString(),
        deliveryId: widget.deliveryId,
      ),
    );

    Navigator.pop(context);
  }

  @override
  Widget build(BuildContext context) {
    return AlertDialog(
      title: const Text("Anzahl Artikel zurücksetzen?"),
      content: SizedBox(
        height: 120,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            const Text("Wollen Sie die entfernten Artikel wieder hinzufügen?"),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              children: [
                FilledButton(
                  onPressed: _reset,
                  child: const Text("Zurücksetzen"),
                ),
                OutlinedButton(
                  onPressed: () {
                    Navigator.of(context).pop();
                  },
                  child: const Text("Abbrechen"),
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }
}
