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/extensions/int_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 SingleChildScrollView(
      child: Column(
        children: [
          Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            mainAxisSize: MainAxisSize.min,
            children: [
              ItemDetailGrid(
                ItemDetailViewCol(LocaleKeys.from.tr(), widget.workListData!.fROMUSER ?? ""),
                ItemDetailViewCol(LocaleKeys.to.tr(), widget.workListData!.tOUSER ?? ""),
              ),
              ItemDetailGrid(
                ItemDetailViewCol(LocaleKeys.sent.tr(), widget.workListData!.bEGINDATE ?? ""),
                ItemDetailViewCol(LocaleKeys.closed.tr(), widget.workListData!.eNDDATE ?? ""),
              ),
              ItemDetailGrid(
                ItemDetailViewCol(LocaleKeys.id.tr(), widget.workListData!.nOTIFICATIONID?.toString() ?? ""),
                ItemDetailViewCol(LocaleKeys.responder.tr(), widget.workListData!.rESPONDER ?? ""),
                isItLast: true,
              ),
            ],
          ).objectContainerView(),
          12.height,
          widget.memberInformationListModel != null ?
          Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            mainAxisSize: MainAxisSize.min,
            children: [
              ItemDetailGrid(
                ItemDetailViewCol(LocaleKeys.employeeNumber.tr(), widget.memberInformationListModel!.eMPLOYEENUMBER ?? ""),
                ItemDetailViewCol(
                    LocaleKeys.employeeName.tr(), (AppState().isArabic(context) ? widget.memberInformationListModel!.eMPLOYEENAMEAr : widget.memberInformationListModel!.eMPLOYEENAMEEn) ?? ""),
              ),
              ItemDetailGrid(
                ItemDetailViewCol(LocaleKeys.jobTitle.tr(), makePositionName(widget.memberInformationListModel!.pOSITIONNAME ?? "")),
                ItemDetailViewCol(LocaleKeys.grade.tr(), widget.memberInformationListModel!.gRADENAME ?? ""),
              ),
              ItemDetailGrid(
                ItemDetailViewCol(LocaleKeys.jobCategory.tr(), makePositionName(widget.memberInformationListModel!.pOSITIONNAME ?? "")),
                ItemDetailViewCol(LocaleKeys.category.tr(), widget.memberInformationListModel!.eMPLOYMENTCATEGORYMEANING ?? ""),
              ),
              ItemDetailGrid(
                ItemDetailViewCol(LocaleKeys.employeeEmailAddress.tr(), widget.memberInformationListModel!.eMPLOYEEEMAILADDRESS ?? ""),
                ItemDetailViewCol(LocaleKeys.payrollBranch.tr(), widget.memberInformationListModel!.pAYROLLNAME ?? ""),
                isItLast: true,
              ),
            ],
          ).objectContainerView() : Container(),
        ],
      ).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;
  }
}
