import 'package:flutter/material.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 StockAdjustmenConfirmation extends StatelessWidget {
  final int totalItems;
  final VoidCallback onCancel;
  final VoidCallback onConfirm;

  const StockAdjustmenConfirmation({
    super.key,
    required this.totalItems,
    required this.onCancel,
    required this.onConfirm,
  });

  @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.w)),
      backgroundColor: Colors.white,
      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: AppColor.primaryColor.withOpacity(0.1),
                shape: BoxShape.circle,
              ),
              child: Icon(
                Icons.fact_check_rounded,
                color: AppColor.primaryColor,
                size: 10.w,
              ),
            ),

            SizedBox(height: 2.5.h),

            Text(
              "Konfirmasi Penyesuaian",
              textAlign: TextAlign.center,
              style: TextStyle(
                fontSize: AppFontSize.medium.sp,
                fontWeight: FontWeight.bold,
                color: Colors.black87,
              ),
            ),

            SizedBox(height: 1.5.h),

            RichText(
              textAlign: TextAlign.center,
              text: TextSpan(
                style: TextStyle(
                  fontSize: 10.sp,
                  color: Colors.grey[600],
                  height: 1.5,
                ),
                children: [
                  TextSpan(
                    text: "Sistem akan menyesuaikan stok sistem pada ",
                    style: TextStyle(fontSize: AppFontSize.medium.sp),
                  ),
                  TextSpan(
                    text: "$totalItems barang",
                    style: TextStyle(
                      color: Colors.black87,
                      fontSize: AppFontSize.medium.sp,
                      fontWeight: FontWeight.bold,
                    ),
                  ),
                  TextSpan(
                    text:
                        " sesuai dengan input fisik yang anda masukkan.\nLanjutkan?",
                    style: TextStyle(fontSize: AppFontSize.medium.sp),
                  ),
                ],
              ),
            ),

            SizedBox(height: 3.5.h),

            Row(
              children: [
                Expanded(
                  child: ElevatedButton(
                    onPressed: onCancel,
                    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(
                      "Batal",
                      style: TextStyle(
                        color: Colors.grey[800],
                        fontSize: AppFontSize.medium.sp,
                        fontWeight: FontWeight.w600,
                      ),
                    ),
                  ),
                ),

                SizedBox(width: 3.w),

                Expanded(
                  child: ElevatedButton(
                    onPressed: onConfirm,
                    style: ElevatedButton.styleFrom(
                      padding: EdgeInsets.symmetric(vertical: 1.5.h),
                      backgroundColor: AppColor.primaryColor,
                      shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(2.5.w),
                      ),
                      elevation: 0,
                    ),
                    child: Text(
                      "Ya, Simpan",
                      style: TextStyle(
                        color: Colors.white,
                        fontWeight: FontWeight.bold,
                        fontSize: AppFontSize.medium.sp,
                      ),
                    ),
                  ),
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }
}
