import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:mohem_flutter_app/api/chat/chat_provider_model.dart';
import 'package:mohem_flutter_app/app_state/app_state.dart';
import 'package:mohem_flutter_app/classes/colors.dart';
import 'package:mohem_flutter_app/classes/utils.dart';
import 'package:mohem_flutter_app/config/routes.dart';
import 'package:mohem_flutter_app/extensions/string_extensions.dart';
import 'package:mohem_flutter_app/extensions/widget_extensions.dart';
import 'package:mohem_flutter_app/widgets/shimmer/dashboard_shimmer_widget.dart';
import 'package:provider/provider.dart';

class ChatFavoriteUsersScreen extends StatelessWidget {
  const ChatFavoriteUsersScreen({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: MyColors.white,
      body: Consumer<ChatProviderModel>(
        builder: (BuildContext context, ChatProviderModel m, Widget? child) {
          if (m.isLoading) {
            return ChatHomeShimmer();
          } else {
            return m.favUsersList != null && m.favUsersList.isNotEmpty
                ? ListView.separated(
                    itemCount: m.favUsersList!.length,
                    padding: const EdgeInsets.only(top: 20),
                    shrinkWrap: true,
                    physics: const NeverScrollableScrollPhysics(),
                    itemBuilder: (BuildContext context, int index) {
                      return SizedBox(
                        height: 55,
                        child: ListTile(
                          leading: Stack(
                            children: [
                              SvgPicture.asset(
                                "assets/images/user.svg",
                                height: 48,
                                width: 48,
                              ),
                              Positioned(
                                right: 5,
                                bottom: 1,
                                child: Container(
                                  width: 10,
                                  height: 10,
                                  decoration: BoxDecoration(
                                    color: m.favUsersList![index].userStatus == 1 ? MyColors.green2DColor : Colors.red,
                                    borderRadius: const BorderRadius.all(
                                      Radius.circular(10),
                                    ),
                                  ),
                                ),
                              )
                            ],
                          ),
                          title: (m.favUsersList![index].userName!.replaceFirst(".", " ").capitalizeFirstofEach ?? "").toText14(color: MyColors.darkTextColor),
                          trailing: IconButton(
                            alignment: Alignment.centerRight,
                            padding: EdgeInsets.zero,
                            icon: Icon(m.favUsersList![index].isFav! ? Icons.star : Icons.star_border),
                            color: m.favUsersList![index].isFav! ? MyColors.yellowColor : MyColors.grey35Color,
                            onPressed: () {
                              if (m.favUsersList![index].isFav!) m.unFavoriteUser(userID: AppState().chatDetails!.response!.id!, targetUserID: m.favUsersList![index].id!);
                            },
                          ),
                          minVerticalPadding: 0,
                          onTap: () {
                            Navigator.pushNamed(
                              context,
                              AppRoutes.chatDetailed,
                              arguments: {"targetUser": m.favUsersList![index], "isNewChat": false},
                            ).then(
                              (Object? value) {
                                m.clearSelections();
                              },
                            );
                          },
                        ),
                      );
                    },
                    separatorBuilder: (BuildContext context, int index) => const Padding(
                      padding: EdgeInsets.only(right: 10, left: 70),
                      child: Divider(
                        color: Color(
                          0xFFE5E5E5,
                        ),
                      ),
                    ),
                  )
                : Column(
                    children: <Widget>[
                      Utils.getNoDataWidget(context).expanded,
                    ],
                  );
          }
        },
      ),
    );
  }
}
