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

/// Visar en global dialogruta med ett felmeddelande och en kopieringsknapp.
void showGlobalErrorDialog(BuildContext context, String errorMessage) {
  showDialog(
    context: context,
    builder: (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!')),
              );
            },
          ),
        ],
      );
    },
  );
}