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/paymentRequisitionPaymentsListProvider.dart';
import 'FileViewer.dart';

class Paymentdetailspaymentrequisition extends StatefulWidget {
  final paymentRequestId;
  final pageName;

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

  @override
  State<Paymentdetailspaymentrequisition> createState() =>
      _PaymentdetailspaymentrequisitionState();
}

class _PaymentdetailspaymentrequisitionState
    extends State<Paymentdetailspaymentrequisition> {


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

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

        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.accountName ?? "-",
                                    style: TextStyle(
                                      fontFamily: "JakartaMedium",
                                      fontSize: 14,
                                      color: AppColors.semi_black,
                                    ),
                                  ),
                                  Text(
                                    "₹${payment_det.amount}",
                                    style: TextStyle(
                                      fontFamily: "JakartaMedium",
                                      fontSize: 14,
                                      color: AppColors.app_blue,
                                    ),
                                  ),
                                ],
                              ),
                            ),
                          ),
                          Expanded(
                            flex: 2,
                            child: Container(
                              padding: EdgeInsets.symmetric(
                                horizontal: 5,
                                vertical: 10,
                              ),
                              decoration: BoxDecoration(
                                borderRadius: BorderRadius.circular(8),
                                color: Color(0xFFE3FFE0),
                              ),
                              child: Center(
                                child: Text(
                                  payment_det.refType??"-",
                                  textAlign: TextAlign.center,
                                  style: TextStyle(
                                    fontFamily: "JakartaMedium",
                                    fontSize: 14,
                                    color: Color(0xFF0D9C00),
                                  ),
                                ),
                              ),
                            ),
                          ),
                        ],
                      ),
                      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);
          },
        );
      },
    );
  }

}
