import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:provider/provider.dart';

import '../../Notifiers/crmProvider/crmLeadDetailsProvider.dart';
import '../../Utils/app_colors.dart';
import '../../Utils/commonWidgets.dart';
class Contactdetails extends StatefulWidget {
  const Contactdetails({super.key});

  @override
  State<Contactdetails> createState() => _ContactdetailsState();
}

class _ContactdetailsState extends State<Contactdetails> {
  @override
  Widget build(BuildContext context) {
    return Consumer<crmLeadDetailsProvider>(
      builder: (context, provider, child) {
        var customerDetails = provider.contactDetails;
        return WillPopScope(
          onWillPop: () => onBackPressed(context),
          child: Scaffold(
            resizeToAvoidBottomInset: true,
            appBar: appbar(context, "Contact Details"),
            backgroundColor: AppColors.scaffold_bg_color,
            body: SafeArea(
              child: SizedBox(
                child: SingleChildScrollView(
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      TextWidget(context,"Contact Details"),
                      ListView.builder(
                          itemCount: customerDetails.length,
                          shrinkWrap: true,
                          itemBuilder: (context, index) {
                            return 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(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: [
                                  Row(
                                    children: [
                                      Expanded(
                                        flex: 1,
                                        child: Container(
                                          height: 50,
                                          width: 35,
                                          padding: EdgeInsets.all(8.0),
                                          decoration: BoxDecoration(
                                            color: Color(0xFFE6F6FF),
                                            borderRadius: BorderRadius.circular(8),
                                          ),
                                          child: SvgPicture.asset(
                                            "assets/svg/se_block_head.svg",
                                          ),
                                        ),
                                      ),
                                      SizedBox(width: 10),
                                      Expanded(
                                        flex: 4,
                                        child: SizedBox(
                                          child: Column(
                                            crossAxisAlignment: CrossAxisAlignment.start,
                                            children: [
                                              Text(
                                                customerDetails[index].name ?? "-",
                                                style: TextStyle(
                                                  fontFamily: "JakartaMedium",
                                                  fontSize: 14,
                                                  color: AppColors.semi_black,
                                                ),
                                              ),
                                            ],
                                          ),
                                        ),
                                      ),

                                    ],
                                  ),
                                  Divider(thickness: 0.5, color: Color(0xFFD7D7D7)),
                                  ...List.generate(5, (j) {
                                  final textheads = [
                                    "Mobile",
                                    "Alternate Mobile",
                                    "Telephone Number",
                                    "Email",
                                    "Designation"
                                  ];
                                  final textSubheads = [
                                    customerDetails[index].mob1??"-",
                                    customerDetails[index].mob2??"-",
                                    customerDetails[index].tel??"-",
                                    customerDetails[index].email??"-",
                                    customerDetails[index].designation??"-",
                                  ];
                                  return Container(

                                    padding: EdgeInsets.symmetric(
                                      vertical: 6,
                                      horizontal: 0,
                                    ),
                                    child: Row(
                                      crossAxisAlignment:
                                      CrossAxisAlignment.start,
                                      children: [
                                        Expanded(
                                          flex:2,
                                          child: Text(textheads[j].toString(),
                                            maxLines: 2,
                                            overflow: TextOverflow.ellipsis,),
                                        ),
                                        Expanded(
                                          flex: 3,
                                          child: Text(
                                            textSubheads[j],
                                            maxLines: 2,
                                            overflow:
                                            TextOverflow.ellipsis,
                                            style: TextStyle(
                                              color: Color(0xFF818181),
                                            ),
                                          ),
                                        ),
                                      ],
                                    ),
                                  );
                                })],
                              ),
                            );
                          }
                      ),

                      SizedBox(height: 75),
                    ],
                  ),
                ),
              ),
            ),
            floatingActionButton: Align(
              alignment: Alignment.bottomCenter,
              child: InkWell(

                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(14.0),
                  ),
                  child: Center(
                    child: Text(
                      "Followup Details",
                      textAlign: TextAlign.center,
                      style: TextStyle(color: Colors.white,
                          fontFamily: "JakartaMedium"),
                    ),
                  ),
                ),
              ),
            ),
            floatingActionButtonLocation:
            FloatingActionButtonLocation.centerFloat,
          ),
        );
      },
    );
  }
}
