import 'package:easy_localization/src/public_ext.dart';
import 'package:flutter/material.dart';
import 'package:mohem_flutter_app/classes/colors.dart';
import 'package:mohem_flutter_app/classes/date_uitl.dart';
import 'package:mohem_flutter_app/extensions/int_extensions.dart';
import 'package:mohem_flutter_app/extensions/string_extensions.dart';
import 'package:mohem_flutter_app/extensions/widget_extensions.dart';
import 'package:mohem_flutter_app/generated/locale_keys.g.dart';
import 'package:mohem_flutter_app/models/get_action_history_list_model.dart';
import 'package:mohem_flutter_app/ui/work_list/sheets/delegate_sheet.dart';
import 'package:mohem_flutter_app/ui/work_list/sheets/request_more_info_sheet.dart';
import 'package:mohem_flutter_app/widgets/bottom_sheet.dart';
import 'package:mohem_flutter_app/widgets/circular_avatar.dart';

class ActionsFragment extends StatelessWidget {
  List<GetActionHistoryList> actionHistoryList;

  ActionsFragment(this.actionHistoryList, {Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      width: double.infinity,
      height: double.infinity,
      child: ListView.separated(
        itemCount: actionHistoryList.length,
        padding: EdgeInsets.all(21),
        itemBuilder: (context, index) {
          return showItem(context, actionHistoryList[index]);
        },
        separatorBuilder: (BuildContext context, int index) {
          return 12.height;
        },
      ),
    );
  }

  Widget showItem(BuildContext context, GetActionHistoryList actionHistory) {
    return Container(
      width: double.infinity,
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(10),
        boxShadow: [
          BoxShadow(
            color: const Color(0xff000000).withOpacity(.05),
            blurRadius: 26,
            offset: const Offset(0, -3),
          ),
        ],
      ),
      clipBehavior: Clip.antiAlias,
      child: Stack(
        clipBehavior: Clip.antiAlias,
        children: [
          Positioned(
            left: -20,
            top: -10,
            child: Transform.rotate(
              angle: 15,
              child: Container(
                width: 50,
                height: 30,
                color: getStatusColor(actionHistory.aCTIONCODE!),
              ),
            ),
          ),
          Column(
            children: [
              Row(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  CircularAvatar(url: actionHistory.eMPLOYEEIMAGE ?? "", isImageBase64: true, height: 34, width: 34),
                  9.width,
                  Expanded(
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        actionHistory.nAME!.toText16(),
                        if ((actionHistory.nOTE ?? "").isNotEmpty) actionHistory.nOTE!.toText12(color: MyColors.grey57Color),
                        4.height,
                        Row(
                          children: [
                            actionHistory.aCTION!.toText10(),
                            8.width,
                            if (actionHistory.nOTIFICATIONDATE!.isNotEmpty)
                              DateUtil.formatDateToDate(DateUtil.convertSimpleStringDateToDateddMMyyyy(actionHistory.nOTIFICATIONDATE!), false).toText12(color: MyColors.lightTextColor),
                          ],
                        )
                      ],
                    ),
                  )
                ],
              ).paddingOnly(top: 19, left: 16, right: 16, bottom: 12),
              Container(width: double.infinity, height: 1, color: MyColors.lightGreyEFColor),
              Row(
                children: [
                  LocaleKeys.request_info.tr().toText12(color: MyColors.grey67Color).center.paddingOnly(top: 6, bottom: 6).onPress(() {
                    showMyBottomSheet(context, child: RequestMoreInfoSheet());
                  }).expanded,
                  Container(width: 1, height: 30, color: MyColors.lightGreyEFColor),
                  LocaleKeys.delegate.tr().toText12(color: MyColors.gradiantEndColor).center.paddingOnly(top: 6, bottom: 6).onPress(() {
                    showMyBottomSheet(context, child: DelegateSheet());
                  }).expanded,
                ],
              ),
            ],
          ),
        ],
      ),
    );
  }

  Color getStatusColor(String code) {
    if (code == "SUBMIT") {
      return const Color(0xff2E303A);
    } else if (code == "REJECTED") {
      return const Color(0xffD02127);
    } else if (code == "APPROVED") {
      return const Color(0xff1FA269);
    } else if (code == "REQUEST_INFO") {
      return const Color(0xff2E303A);
    } else {
      return const Color(0xff2E303A);
    }
  }
}

List<Color> actionsList = [
  Colors.black,
  Colors.red,
  Colors.green,
];
