import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:niogu_app/core/constants/app_color.dart';
import 'package:niogu_app/core/constants/app_font_size.dart';
import 'package:sizer/sizer.dart';

class CustomConfirmation extends StatelessWidget {
  final String title;
  final String? body;
  final Color color;
  final IconData icon;
  final VoidCallback? onConfirm;
  final VoidCallback? onCancel;
  final RichText? richText;

  const CustomConfirmation({
    super.key,
    required this.title,
    this.body,
    required this.color,
    required this.icon,
    required this.onConfirm,
    this.onCancel,
    this.richText,
  });

  @override
  Widget build(BuildContext context) {
    final bool isTablet = 100.w >= 600;
    final double maxWidth = 100.w >= 1280
        ? 1200
        : isTablet
        ? 800
        : 400;
    return Dialog(
      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(4.5.w)),
      backgroundColor: Colors.white,
      insetPadding: EdgeInsets.symmetric(horizontal: 10.w),
      elevation: 5,
      child: Container(
        padding: EdgeInsets.symmetric(horizontal: 5.w, vertical: 3.h),
        width: double.infinity,
        constraints: BoxConstraints(maxWidth: maxWidth),
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(4.w),
        ),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            Container(
              padding: EdgeInsets.all(4.w),
              decoration: BoxDecoration(
                color: color.withOpacity(0.1),
                shape: BoxShape.circle,
              ),
              child: Icon(icon, color: color, size: 10.w),
            ),

            SizedBox(height: 2.h),

            Text(
              title,
              style: TextStyle(
                fontSize: AppFontSize.medium.sp,
                fontWeight: FontWeight.bold,
                color: Colors.black87,
              ),
            ),

            if (body != null) ...[
              SizedBox(height: 1.h),
              Text(
                body!,
                textAlign: TextAlign.center,
                style: TextStyle(
                  fontSize: isTablet
                      ? AppFontSize.medium.sp
                      : AppFontSize.small.sp,
                  color: Colors.grey[800],
                  height: 1.5,
                ),
              ),
            ],

            if (richText != null) richText!,

            SizedBox(height: 3.h),

            Row(
              children: [
                Expanded(
                  child: ElevatedButton(
                    onPressed: onCancel != null
                        ? onCancel
                        : () => context.pop(),
                    style: ElevatedButton.styleFrom(
                      backgroundColor: Colors.grey.shade300,
                      padding: EdgeInsets.symmetric(vertical: 1.5.h),
                      shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(2.5.w),
                      ),
                      elevation: 0,
                    ),
                    child: Text(
                      onCancel != null ? "Tolak" : "Batal",
                      style: TextStyle(
                        color: Colors.grey[800],
                        fontSize: AppFontSize.medium.sp,
                        fontWeight: FontWeight.w600,
                      ),
                    ),
                  ),
                ),

                SizedBox(width: 3.w),

                Expanded(
                  child: ElevatedButton(
                    onPressed: () {
                      onConfirm?.call();
                      context.pop();
                    },
                    style: ElevatedButton.styleFrom(
                      backgroundColor: AppColor.primaryColor,
                      padding: EdgeInsets.symmetric(vertical: 1.5.h),
                      shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(2.5.w),
                      ),
                      elevation: 0,
                    ),
                    child: Text(
                      onCancel != null ? "Terima" : "Lanjutkan",
                      style: TextStyle(
                        color: Colors.white,
                        fontSize: AppFontSize.medium.sp,
                        fontWeight: FontWeight.w600,
                      ),
                    ),
                  ),
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }
}
