// Author: fengshengxiong
// Date: 2024/5/11
// Description: 提示框

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:tone_snap/components/divider_widget.dart';

class RemindDialog extends StatelessWidget {
  const RemindDialog({
    super.key,
    this.title,
    this.content,
    this.showCancelBtn = true,
    this.cancelText,
    this.confirmText,
    this.confirmOnTap,
    this.popScope = false,
  });

  final String? title;
  final String? content;
  final bool? showCancelBtn;
  final String? cancelText;
  final String? confirmText;
  final Function()? confirmOnTap;
  final bool popScope;

  @override
  Widget build(BuildContext context) {
    return PopScope(
      canPop: popScope,
      child: Center(
        child: Container(
          width: 0.8.sw,
          clipBehavior: Clip.antiAlias,
          decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.circular(8),
          ),
          child: IntrinsicHeight(
            child: Column(
              children: [
                SizedBox(height: 10.h),
                Text(
                  title ?? 'Reminder',
                  textAlign: TextAlign.center,
                  style: TextStyle(
                    color: Colors.black,
                    fontSize: 18.sp,
                    fontWeight: FontWeight.w500,
                  ),
                ),
                SizedBox(height: 12.h),
                Padding(
                  padding: const EdgeInsets.symmetric(horizontal: 10).w,
                  child: Text(
                    content ?? '',
                    textAlign: TextAlign.center,
                    style: TextStyle(
                      color: const Color(0xFF333333),
                      fontSize: 16.sp,
                    ),
                  ),
                ),
                SizedBox(height: 12.h),
                const DividerWidget(),
                SizedBox(
                  height: 52.h,
                  child: Row(
                    children: [
                      if (showCancelBtn!) ...[
                        _optionButton(cancelText ?? 'Cancel', false),
                        Container(
                          width: 1.w,
                          height: double.infinity,
                          color: const Color(0xFFE5E5E5),
                        ),
                      ],
                      _optionButton(confirmText ?? 'Confirm', true),
                    ],
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }

  Widget _optionButton(String label, bool isConfirm) {
    return Expanded(
      child: Material(
        color: Colors.transparent,
        child: InkWell(
          onTap: () {
            Get.back();
            if (isConfirm && confirmOnTap != null) confirmOnTap!();
          },
          child: SizedBox(
            height: double.infinity,
            child: Center(
              child: Text(
                label,
                textAlign: TextAlign.center,
                style: TextStyle(
                  color: isConfirm ? Colors.black : const Color(0xFF666666),
                  fontSize: 16.sp,
                  fontWeight: FontWeight.w500,
                ),
              ),
            ),
          ),
        ),
      ),
    );
  }
}
