import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:generp/Notifiers/VisitDetailsProvider.dart';
import 'package:generp/Utils/app_colors.dart';
import 'package:generp/Utils/commonWidgets.dart';
import 'package:provider/provider.dart';

import 'Followupdetails.dart';

class Visitdetails extends StatefulWidget {
  final complaintID;

  const Visitdetails({super.key, required this.complaintID});

  @override
  State<Visitdetails> createState() => _VisitdetailsState();
}

class _VisitdetailsState extends State<Visitdetails> {
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    WidgetsBinding.instance.addPostFrameCallback((_) {
      var visitdetails = Provider.of<Visitdetailsprovider>(
        context,
        listen: false,
      );
      visitdetails.LoadVisitDetailsAPI(context, widget.complaintID);
    });
  }

  @override
  Widget build(BuildContext context) {
    return Consumer<Visitdetailsprovider>(
      builder: (context, provider, child) {
        var customerDetails = provider.customerDetails;
        var generatorDetails = provider.generatorDetails;
        var complaintDetails = provider.complaintDetailsNew;
        return WillPopScope(
          onWillPop: () => onBackPressed(context),
          child: Scaffold(
            resizeToAvoidBottomInset: true,
            appBar: appbar(context, "Visit Details"),
            backgroundColor: AppColors.scaffold_bg_color,
            body: Container(
              child: SingleChildScrollView(
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text("Customer Details"),
                    Container(
                      margin: EdgeInsets.symmetric(horizontal: 10, vertical: 5),
                      padding: EdgeInsets.symmetric(horizontal: 15, vertical: 10),
                      decoration: BoxDecoration(
                        color: Colors.white,
                        borderRadius: BorderRadius.circular(20),
                      ),
                      child: Column(
                        children: [
                          Row(
                            children: [
                              Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: List.generate(4, (j) {
                                  final textheads = [
                                    "${customerDetails.cname}",
                                    "Mobile Number",
                                    "Contact Person Number",
                                    "Mail ID",
                                  ];
                                  final textSubheads = [
                                    "${customerDetails.aname}",
                                    "${customerDetails.mob1}",
                                    "${customerDetails.mob2}",
                                    "${customerDetails.mail}",
                                  ];
                                  return Container(
                                    padding: EdgeInsets.symmetric(vertical: 3),
                                    child: Container(
                                      padding: EdgeInsets.symmetric(
                                        vertical: 3,
                                        horizontal: 0,
                                      ),
                                      child: Column(
                                        children: [
                                          Row(
                                            mainAxisAlignment:
                                                MainAxisAlignment.spaceBetween,
                                            children: [
                                              if (j == 0) ...[
                                                SvgPicture.asset(
                                                  "assets/svg/se_block_head.svg",
                                                ),
                                                SizedBox(width: 5),
                                              ],
                                              Column(
                                                crossAxisAlignment:
                                                    CrossAxisAlignment.start,
                                                children: [
                                                  Text(textheads[j].toString()),
                                                  SizedBox(
                                                    // height:45,
                                                    width:
                                                        MediaQuery.of(
                                                          context,
                                                        ).size.width *
                                                        0.75,
                                                    child: Text(
                                                      textSubheads[j],
                                                      maxLines: 2,
                                                      overflow:
                                                          TextOverflow.ellipsis,
                                                      style: TextStyle(
                                                        color: Color(0xFF818181),
                                                      ),
                                                    ),
                                                  ),
                                                ],
                                              ),
                                            ],
                                          ),
                                        ],
                                      ),
                                    ),
                                  );
                                }),
                              ),
                            ],
                          ),
                        ],
                      ),
                    ),

                    Text("Generator Details"),
                    Container(
                      margin: EdgeInsets.symmetric(horizontal: 10, vertical: 5),
                      padding: EdgeInsets.symmetric(horizontal: 15, vertical: 10),
                      decoration: BoxDecoration(
                        color: Colors.white,
                        borderRadius: BorderRadius.circular(20),
                      ),
                      child: Column(
                        children: [
                          Row(
                            children: [
                              SvgPicture.asset("assetName"),
                              Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: List.generate(6, (j) {
                                  final textheads = [
                                    "Gen ID",
                                    "Engine Number",
                                    "Address",
                                    "Product Name",
                                    "Engine Model",
                                    "Date Of Supply",
                                  ];
                                  final textSubheads = [
                                    "${generatorDetails.genHashId}",
                                    "${generatorDetails.engineNo}",
                                    "${generatorDetails.address}",
                                    "${generatorDetails.spname}",
                                    "${generatorDetails.engineModel}",
                                    "${complaintDetails.dateOfSupply}",
                                  ];
                                  return Container(
                                    padding: EdgeInsets.symmetric(vertical: 3),
                                    child: Column(
                                      children: [
                                        Row(
                                          mainAxisAlignment:
                                              MainAxisAlignment.spaceBetween,
                                          children: [
                                            Container(
                                              padding: EdgeInsets.symmetric(
                                                vertical: 3,
                                                horizontal: 0,
                                              ),
                                              child: Column(
                                                crossAxisAlignment:
                                                    CrossAxisAlignment.start,
                                                children: [
                                                  Text(textheads[j].toString()),
                                                  SizedBox(
                                                    // height:45,
                                                    width:
                                                        MediaQuery.of(
                                                          context,
                                                        ).size.width *
                                                        0.8,
                                                    child: Text(
                                                      textSubheads[j],
                                                      maxLines: 2,
                                                      overflow:
                                                          TextOverflow.ellipsis,
                                                      style: TextStyle(
                                                        color: Color(0xFF818181),
                                                      ),
                                                    ),
                                                  ),
                                                ],
                                              ),
                                            ),
                                          ],
                                        ),
                                      ],
                                    ),
                                  );
                                }),
                              ),
                            ],
                          ),
                        ],
                      ),
                    ),

                    Text("Complaint Details"),
                    Container(
                      margin: EdgeInsets.symmetric(horizontal: 10, vertical: 5),
                      padding: EdgeInsets.symmetric(horizontal: 15, vertical: 10),
                      decoration: BoxDecoration(
                        color: Colors.white,
                        borderRadius: BorderRadius.circular(20),
                      ),
                      child: Column(
                        children: [
                          Row(
                            children: [
                              SvgPicture.asset("assetName"),
                              Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: List.generate(4, (j) {
                                  final textheads = [
                                    "Complaint ID",
                                    "Complaint Description",
                                    "Opened Date",
                                    "Complaint Type",
                                  ];
                                  final textSubheads = [
                                    "${complaintDetails.complaintId}",
                                    "${complaintDetails.complaintDesc}",
                                    "${complaintDetails.openedDate}",
                                    "${complaintDetails.complaintType}",
                                  ];
                                  return Container(
                                    padding: EdgeInsets.symmetric(vertical: 3),
                                    child: Column(
                                      children: [
                                        Row(
                                          mainAxisAlignment:
                                              MainAxisAlignment.spaceBetween,
                                          children: [
                                            Container(
                                              padding: EdgeInsets.symmetric(
                                                vertical: 3,
                                                horizontal: 0,
                                              ),
                                              child: Column(
                                                crossAxisAlignment:
                                                    CrossAxisAlignment.start,
                                                children: [
                                                  Text(textheads[j].toString()),
                                                  SizedBox(
                                                    // height:45,
                                                    width:
                                                        MediaQuery.of(
                                                          context,
                                                        ).size.width *
                                                        0.8,
                                                    child: Text(
                                                      textSubheads[j],
                                                      maxLines: 2,
                                                      overflow:
                                                          TextOverflow.ellipsis,
                                                      style: TextStyle(
                                                        color: Color(0xFF818181),
                                                      ),
                                                    ),
                                                  ),
                                                ],
                                              ),
                                            ),
                                          ],
                                        ),
                                      ],
                                    ),
                                  );
                                }),
                              ),
                            ],
                          ),
                        ],
                      ),
                    ),

                    SizedBox(height: 75),
                  ],
                ),
              ),
            ),
            floatingActionButton: Align(
              alignment: Alignment.bottomCenter,
              child: InkWell(
                onTap: () {
                  Navigator.push(
                    context,
                    MaterialPageRoute(
                      builder:
                          (context) =>
                              Followupdetails(complaintID: widget.complaintID),
                    ),
                  );
                },
                child: Container(
                  alignment: Alignment.bottomCenter,
                  height: 45,
                  width: MediaQuery.of(context).size.width,
                  margin: EdgeInsets.symmetric(horizontal: 10),
                  decoration: BoxDecoration(
                    color: AppColors.app_blue,
                    borderRadius: BorderRadius.circular(30.0),
                  ),
                  child: Center(
                    child: Text(
                      "Followup Details",
                      textAlign: TextAlign.center,
                      style: TextStyle(color: Colors.white),
                    ),
                  ),
                ),
              ),
            ),
            floatingActionButtonLocation:
                FloatingActionButtonLocation.centerFloat,
          ),
        );
      },
    );
  }
}
