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

import '../../Notifiers/VisitDetailsProvider.dart';
import '../../Utils/app_colors.dart';
import '../../Utils/commonWidgets.dart';

class Followupdetails extends StatefulWidget {
  final complaintID;

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

  @override
  State<Followupdetails> createState() => _FollowupdetailsState();
}

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

  @override
  Widget build(BuildContext context) {
    return Consumer<Visitdetailsprovider>(
      builder: (context, provider, child) {
        var followups = provider.followUpList;
        return Scaffold(
          appBar: appbar(context, "Follow Up Details"),
          backgroundColor: AppColors.scaffold_bg_color,
          body: Container(
            child: ListView.builder(
              itemCount: provider.followUpList.length,
              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(
                    children: [
                      Row(
                        children: [
                          Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: List.generate(4, (j) {
                              final textheads = [
                                "Name",
                                "Date",
                                "Type",
                                "Time",
                                "Feedback",
                              ];
                              final textSubheads = [
                                "${followups[index].ename}",
                                "${followups[index].date}",
                                "${followups[index].type}",
                                "${followups[index].time}",
                                "${followups[index].feedback}",
                              ];
                              return Container(
                                padding: EdgeInsets.symmetric(vertical: 3),
                                child: Container(
                                  padding: EdgeInsets.symmetric(
                                    vertical: 3,
                                    horizontal: 0,
                                  ),
                                  child: Column(
                                    children: [
                                      Row(
                                        mainAxisAlignment:
                                            MainAxisAlignment.spaceBetween,
                                        children: [
                                          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),
                                                  ),
                                                ),
                                              ),
                                            ],
                                          ),
                                        ],
                                      ),
                                    ],
                                  ),
                                ),
                              );
                            }),
                          ),
                        ],
                      ),
                    ],
                  ),
                );
              },
            ),
          ),
        );
      },
    );
  }
}
