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

/// En återanvändbar widget för att visa felmeddelanden med en kopieringsknapp.
class ErrorMessageWidget extends StatelessWidget {
  final String errorMessage;

  const ErrorMessageWidget({Key? key, required this.errorMessage}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return AlertDialog(
      title: const Text('Fel'),
      content: Column(
        mainAxisSize: MainAxisSize.min,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          SelectableText(errorMessage),
        ],
      ),
      actions: <Widget>[
        TextButton(
          child: const Text('Stäng'),
          onPressed: () {
            Navigator.of(context).pop();
          },
        ),
        TextButton(
          child: const Text('Kopiera'),
          onPressed: () {
            Clipboard.setData(ClipboardData(text: errorMessage));
            ScaffoldMessenger.of(context).showSnackBar(
              const SnackBar(content: Text('Felmeddelande kopierat!')),
            );
          },
        ),
      ],
    );
  }
}