import 'package:flutter/material.dart';

/// Class for handling dialog popups in the application
class TDialogs {
  /// Display a confirmation dialog with optional custom button text
  static Future<bool?> confirmDialog({
    required BuildContext context,
    required String title,
    required String message,
    String confirmText = 'Yes',
    String cancelText = 'Cancel',
    VoidCallback? onConfirm,
    VoidCallback? onCancel,
  }) async {
    final result = await showDialog<bool>(
      context: context,
      barrierDismissible: false,
      builder:
          (context) => AlertDialog(
            title: Text(title),
            content: Text(message),
            actions: [
              TextButton(
                onPressed: () {
                  Navigator.of(context).pop(false);
                  if (onCancel != null) onCancel();
                },
                child: Text(cancelText),
              ),
              ElevatedButton(
                onPressed: () {
                  Navigator.of(context).pop(true);
                  if (onConfirm != null) onConfirm();
                },
                child: Text(confirmText),
              ),
            ],
          ),
    );

    return result;
  }

  /// Show a simple alert dialog with a single OK button
  static Future<void> alertDialog({
    required BuildContext context,
    required String title,
    required String message,
    String buttonText = 'OK',
    VoidCallback? onPressed,
  }) async {
    await showDialog<void>(
      context: context,
      builder:
          (context) => AlertDialog(
            title: Text(title),
            content: Text(message),
            actions: [
              ElevatedButton(
                onPressed: () {
                  Navigator.of(context).pop();
                  if (onPressed != null) onPressed();
                },
                child: Text(buttonText),
              ),
            ],
          ),
    );
  }
}
