import { defineStore } from "pinia";
import { ref } from "vue";
/** importType*/
import type { PositionMaim } from "@/modules/05_placement/interface/response/SelectOrg";
import type { DataPositionNo } from "@/modules/05_placement/interface/index/SelectOrg";
export const useSelectOrgStore = defineStore("selectorg", () => {
  // const node = ref<number>(0);
  // const nodeId = ref<string>("");
  // const posmasterId = ref<string>();

  function fetchPosNo(data: PositionMaim[]) {
    const listPosNo: DataPositionNo[] = data.map((e: PositionMaim) => ({
      id: e.id,
      isPosition: e.isPosition,
      posMasterNo:
        e.orgShortname +
        (e.posMasterNoPrefix != null ? e.posMasterNoPrefix : "") +
        e.posMasterNo +
        (e.posMasterNoSuffix != null ? e.posMasterNoSuffix : ""),
      positionName: e.positionName,
      posTypeName: e.posTypeName,
      posLevelName: e.posLevelName,
      positionIsSelected: e.fullNameCurrentHolder
        ? e.fullNameCurrentHolder
        : "-",
      isSit: e.isSit,
      positions: e.positions,
      node: e.node,
      nodeId: e.nodeId,
      isCondition: e.isCondition,
    }));

    return listPosNo;
  }

  return {
    fetchPosNo,
  };
});
