import 'dart:io';

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:niogu_app/core/widgets/custom_snackbar.dart';
import 'package:sizer/sizer.dart';

class PaymentInfo extends StatelessWidget {
  final String paymentMethod;
  final String paymentProof;
  const PaymentInfo({
    super.key,
    required this.paymentMethod,
    required this.paymentProof,
  });

  @override
  Widget build(BuildContext context) {
    final bool isTablet = 100.w >= 600;
    return Container(
      padding: EdgeInsets.all(4.w),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(4.w),
        border: Border.all(color: Colors.grey.shade200),
        boxShadow: [
          BoxShadow(
            color: Colors.black.withOpacity(0.02),
            blurRadius: 10,
            offset: const Offset(0, 4),
          ),
        ],
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Row(
            children: [
              Icon(
                Icons.account_balance_wallet_outlined,
                size: 5.w,
                color: AppColor.primaryColor,
              ),
              SizedBox(width: 2.w),
              Text(
                "Informasi Pembayaran",
                style: TextStyle(
                  fontWeight: FontWeight.bold,
                  fontSize: (AppFontSize.medium - (isTablet ? 0 : 1.25)).sp,
                  color: Colors.black87,
                ),
              ),
            ],
          ),
          SizedBox(height: 2.h),

          Material(
            color: Colors.transparent,
            child: InkWell(
              onTap: paymentMethod == 'COD'
                  ? null
                  : () {
                      final File imageFile = File(paymentProof);

                      final bool imageFileExists = imageFile.existsSync();

                      if (!imageFileExists) {
                        CustomSnackbar.showError(
                          context,
                          "Ups, terjadi kesalahan",
                        );
                        return;
                      }

                      showDialog(
                        context: context,
                        useRootNavigator: true,
                        builder: (context) => Dialog(
                          insetPadding: EdgeInsets.symmetric(
                            horizontal: 2.w,
                            vertical: 2.h,
                          ),
                          backgroundColor: Colors.transparent,
                          child: GestureDetector(
                            onTap: () => Navigator.pop(context),
                            child: Container(
                              width: MediaQuery.of(context).size.width,
                              constraints: BoxConstraints(
                                maxWidth: 85.w,
                                maxHeight: 85.h,
                              ),
                              child: ClipRRect(
                                borderRadius: BorderRadius.circular(4.w),
                                child: InteractiveViewer(
                                  child: Image.file(
                                    File(paymentProof),
                                    fit: BoxFit.contain,
                                    width: double.infinity,
                                  ),
                                ),
                              ),
                            ),
                          ),
                        ),
                      );
                    },
              borderRadius: BorderRadius.circular(2.w),
              child: Container(
                padding: EdgeInsets.all(3.w),
                decoration: BoxDecoration(
                  color: Colors.grey.shade50,
                  borderRadius: BorderRadius.circular(2.w),
                  border: Border.all(color: Colors.grey.shade200),
                ),
                child: Row(
                  children: [
                    Container(
                      padding: EdgeInsets.all(2.w),
                      decoration: BoxDecoration(
                        color: Colors.white,
                        shape: BoxShape.circle,
                        boxShadow: [
                          BoxShadow(
                            color: Colors.black.withOpacity(0.05),
                            blurRadius: 5,
                          ),
                        ],
                      ),
                      child: Icon(
                        paymentMethod == 'COD'
                            ? Icons.payments_outlined
                            : Icons.receipt_long_outlined,
                        color: AppColor.primaryColor,
                        size: 5.w,
                      ),
                    ),
                    SizedBox(width: 3.w),
                    Expanded(
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Text(
                            paymentMethod,
                            style: TextStyle(
                              fontWeight: FontWeight.bold,
                              fontSize: isTablet
                                  ? (AppFontSize.medium - 1.25).sp
                                  : (AppFontSize.small - 1.25).sp,
                            ),
                          ),
                          if (paymentMethod != 'COD')
                            Text(
                              "Ketuk untuk lihat bukti pembayaran",
                              style: TextStyle(
                                fontSize: isTablet
                                    ? (AppFontSize.medium - 1.25).sp
                                    : (AppFontSize.small - 1.25).sp,
                                color: Colors.grey.shade600,
                              ),
                            ),
                        ],
                      ),
                    ),
                    if (paymentMethod != 'COD')
                      Icon(
                        Icons.arrow_forward_ios,
                        size: 3.5.w,
                        color: Colors.grey.shade400,
                      ),
                  ],
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }
}
