import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:mohem_flutter_app/classes/colors.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/itg_forms_models/wf_history_model.dart';
import 'package:mohem_flutter_app/ui/work_list/sheets/selected_itg_item_sheet.dart';
import 'package:mohem_flutter_app/widgets/bottom_sheet.dart';
import 'package:mohem_flutter_app/widgets/circular_avatar.dart';

class ApprovalLevelfragment extends StatelessWidget {
  List<WFHistory> wFHistory;

  ApprovalLevelfragment({Key? key, this.wFHistory = const <WFHistory>[]}) : super(key: key);

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

  Widget showItem(BuildContext context, WFHistory history) {
    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(history.action!),
              ),
            ),
          ),
          Column(
            children: [
              Row(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  CircularAvatar(url: null, isImageBase64: false, height: 34, width: 34),
                  9.width,
                  Expanded(
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        history.name!.toText16(),
                        if ((history.notes ?? "").isNotEmpty) history.notes!.toText12(color: MyColors.grey57Color),
                        4.height,
                        Row(
                          children: [
                            history.action!.toText10(
                              color: getStatusColor(history.action!),
                            ),
                            8.width,
                            if (history.date!.isNotEmpty) history.date!.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: SelectedItgItemSheet(
                        LocaleKeys.comments.tr(),
                        wfHistory: history,
                        apiMode: 'RequestInformation',
                      ),
                    );
                  }).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: SelectedItgItemSheet(
                        LocaleKeys.comments.tr(),
                        wfHistory: history,
                        apiMode: 'Delegate',
                      ),
                    );
                  }).expanded,
                ],
              ),
            ],
          ),
        ],
      ),
    );
  }

  Color getStatusColor(String code) {
    if (code == "Submit") {
      return MyColors.grey3AColor;
    } else if (code == "Pending") {
      return MyColors.yellowColor;
    } else if (code == "Not Doable" || code == "Rejected") {
      return MyColors.redColor;
    } else if (code == "APPROVED") {
      return MyColors.greenColor;
    } else if (code == "Requested Information") {
      return MyColors.orange;
    } else {
      return MyColors.yellowColor;
    }
  }
}
