import 'package:dropdown_button2/dropdown_button2.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:generp/Notifiers/financeProvider/RequesitionLidtDetailsProvider.dart';
import 'package:generp/Notifiers/financeProvider/approveRejectPaymentRequestResponse.dart';
import 'package:generp/Utils/app_colors.dart';
import 'package:generp/Utils/commonWidgets.dart';
import 'package:provider/provider.dart';

import '../../Notifiers/financeProvider/paymentReceiptsProvider.dart';
import '../../Notifiers/financeProvider/paymentRequisitionPaymentsListProvider.dart';
import 'FileViewer.dart';

class Paymentreceiptdetails extends StatefulWidget {
  final paymentRequestId;
  final pageName;

  const Paymentreceiptdetails({
    super.key,
    required this.paymentRequestId,
    required this.pageName,
  });

  @override
  State<Paymentreceiptdetails> createState() =>
      _PaymentreceiptdetailsState();
}

class _PaymentreceiptdetailsState
    extends State<Paymentreceiptdetails> {


  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
      var provider = Provider.of<Paymentreceiptsprovider>(
        context,
        listen: false,
      );
      provider.paymentsListDetailsAPI(context, widget.paymentRequestId);
    });
  }

  @override
  Widget build(BuildContext context) {
    return Consumer<Paymentreceiptsprovider>(
      builder: (context, provider, child) {
        var payment_det = provider.receiptDetails;

        return WillPopScope(
          child: Scaffold(
            appBar: appbar(context, widget.pageName),
            backgroundColor: AppColors.scaffold_bg_color,
            body: Container(
              child: SingleChildScrollView(
                child: Container(
                  decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.circular(16),
                  ),
                  margin: EdgeInsets.symmetric(vertical: 10, horizontal: 10),
                  padding: EdgeInsets.symmetric(vertical: 10, horizontal: 10),
                  child: Column(
                    children: [
                      Row(
                        children: [
                          Expanded(
                            flex: 1,
                            child: Container(
                              height: 50,
                              width: 35,
                              padding: EdgeInsets.all(8.0),
                              decoration: BoxDecoration(
                                color: Color(0xFFFFF3CE),
                                borderRadius: BorderRadius.circular(8),
                              ),
                              child: SvgPicture.asset("assets/svg/fin_ic.svg"),
                            ),
                          ),
                          SizedBox(width: 10),
                          Expanded(
                            flex: 4,
                            child: SizedBox(
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: [
                                  Text(
                                    payment_det.receipientAccount ?? "-",
                                    style: TextStyle(
                                      fontFamily: "JakartaMedium",
                                      fontSize: 14,
                                      color: AppColors.semi_black,
                                    ),
                                  ),
                                  Text(
                                    "₹${payment_det.amount}",
                                    style: TextStyle(
                                      fontFamily: "JakartaMedium",
                                      fontSize: 14,
                                      color: AppColors.app_blue,
                                    ),
                                  ),
                                ],
                              ),
                            ),
                          ),

                        ],
                      ),
                      Divider(thickness: 0.5, color: Color(0xFFD7D7D7)),
                      ...List.generate(provider.subHeadings.length, (j) {
                        return Container(
                          padding: EdgeInsets.symmetric(vertical: 7),
                          child: Row(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              Expanded(
                                child: Text(
                                  provider.Headings[j],
                                  style: TextStyle(
                                    fontFamily: "JakartaMedium",
                                    fontSize: 14,
                                    color: AppColors.semi_black,
                                  ),
                                ),
                              ),
                              Expanded(
                                child: InkResponse(
                                  onTap: () {
                                    if (provider.Headings[j] == "Attachment") {
                                      Navigator.push(
                                        context,
                                        MaterialPageRoute(
                                          builder:
                                              (context) => Fileviewer(
                                            fileName:
                                            payment_det
                                                .attachmentViewFileName!,
                                            fileUrl:
                                            payment_det
                                                .attachmentDirFilePath!,
                                          ),
                                        ),
                                      );
                                    }
                                  },
                                  child: Text(
                                    provider.Headings[j] == "Attachment"
                                        ? "View"
                                        : "${provider.subHeadings[j]}",
                                    style: TextStyle(
                                      fontSize: 14,
                                      color:
                                      provider.Headings[j] == "Attachment"
                                          ? AppColors.app_blue
                                          : Color(0xFF818181),
                                      decoration:
                                      provider.Headings[j] == "Attachment"
                                          ? TextDecoration.underline
                                          : TextDecoration.none,
                                      decorationColor:
                                      provider.Headings[j] == "Attachment"
                                          ? AppColors.app_blue
                                          : AppColors.white,
                                    ),
                                  ),
                                ),
                              ),
                            ],
                          ),
                        );
                      }),
                    ],
                  ),
                ),
              ),
            ),

          ),
          onWillPop: () {
            return onBackPressed(context);
          },
        );
      },
    );
  }

}
