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

class MyConfirm extends StatelessWidget {
  final String title;
  final String content;
  final String confirmText;
  final String cancelText;

  const MyConfirm({
    super.key,
    required this.title,
    required this.content,
    this.confirmText = "确认",
    this.cancelText = "取消",
  });

  @override
  Widget build(BuildContext context) {
    return AlertDialog(
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(12),
      ),
      title: Text(
        title,
        style: const TextStyle(
          fontSize: 16,
          fontWeight: FontWeight.w600,
        ),
      ),
      content: Text(content),
      actions: [
        TextButton(
          onPressed: () => Get.back(result: false), // 关闭并返回 false
          child: Text(cancelText),
        ),
        ElevatedButton(
          style: ElevatedButton.styleFrom(
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(8),
            ),
          ),
          onPressed: () => Get.back(result: true), // 关闭并返回 true
          child: Text(confirmText),
        ),
      ],
    );
  }
}

class ConfirmDialog {
  static Future<bool?> show({
    required String title,
    required String content,
    String confirmText = "确认",
    String cancelText = "取消",
  }) {
    return Get.dialog<bool>(
      MyConfirm(
        title: title,
        content: content,
        confirmText: confirmText,
        cancelText: cancelText,
      ),
      barrierDismissible: false, // 点击外部不可关闭
    );
  }
}
