import 'package:easy_localization/src/public_ext.dart';
import 'package:flutter/material.dart';
import 'package:mohem_flutter_app/app_state/app_state.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/member_information_list_model.dart';
import 'package:mohem_flutter_app/models/worklist_response_model.dart';
import 'package:mohem_flutter_app/widgets/item_detail_view_widget.dart';

class DetailFragment extends StatefulWidget {
  WorkListResponseModel? workListData;
  MemberInformationListModel? memberInformationListModel;

  DetailFragment(this.workListData, this.memberInformationListModel);

  @override
  State<DetailFragment> createState() => _DetailFragmentState();
}

class _DetailFragmentState extends State<DetailFragment> {
  bool isOpened = false;

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          mainAxisSize: MainAxisSize.min,
          children: [
            ItemDetailView(LocaleKeys.from.tr(), widget.workListData!.fROMUSER ?? ""),
            ItemDetailView(LocaleKeys.to.tr(), widget.workListData!.tOUSER ?? ""),
            ItemDetailView(LocaleKeys.sent.tr(), widget.workListData!.bEGINDATE ?? ""),
            ItemDetailView(LocaleKeys.closed.tr(), widget.workListData!.eNDDATE ?? ""),
            ItemDetailView(LocaleKeys.id.tr(), widget.workListData!.nOTIFICATIONID?.toString() ?? ""),
            ItemDetailView(LocaleKeys.responder.tr(), widget.workListData!.rESPONDER ?? ""),
          ],
        ).objectContainerView(),
        12.height,
        Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          mainAxisSize: MainAxisSize.min,
          children: [
            ItemDetailView(LocaleKeys.employeeNumber.tr(), widget.memberInformationListModel!.eMPLOYEENUMBER ?? ""),
            ItemDetailView(LocaleKeys.employeeName.tr(),
                (AppState().isArabic(context) ? widget.memberInformationListModel!.eMPLOYEENAMEAr : widget.memberInformationListModel!.eMPLOYEENAMEEn) ?? ""),
            ItemDetailView(LocaleKeys.jobTitle.tr(), makePositionName(widget.memberInformationListModel!.pOSITIONNAME ?? "")),
            ItemDetailView(LocaleKeys.grade.tr(), widget.memberInformationListModel!.gRADENAME ?? ""),
            ItemDetailView(LocaleKeys.jobCategory.tr(), makePositionName(widget.memberInformationListModel!.pOSITIONNAME ?? "")),
            ItemDetailView(LocaleKeys.category.tr(), widget.memberInformationListModel!.eMPLOYMENTCATEGORYMEANING ?? ""),
            ItemDetailView(LocaleKeys.employeeEmailAddress.tr(), widget.memberInformationListModel!.eMPLOYEEEMAILADDRESS ?? ""),
            ItemDetailView(LocaleKeys.payrollBranch.tr(), widget.memberInformationListModel!.pAYROLLNAME ?? ""),
          ],
        ).objectContainerView(),
      ],
    ).paddingAll(21);
  }

  String makePositionName(String job) {
    String jobName = "";
    List<String> list = job.split(".").toList();
    if (list.length > 1) {
      list.removeLast();
      jobName = list.join(" ");
    }
    return jobName;
  }

}
