
import HttpService from "~/services/httpService";

export const treeListMixin = {
   beforeMount() {
    this.httpService = new HttpService(import.meta.env.VITE_LIST_BASE_URL);
  },
  mounted() {
  },
  data() {
    return {
      httpService: undefined,
      treeItems: [
        // {
        //   addLeafNodeDisabled: true,
        //   addTreeNodeDisabled: true,
        //   children: [],
        //   delNodeDisabled: true,
        //   dragDisabled: true,
        //   editNodeDisabled: true,
        //   isLeaf : true,
        //   id: 1,
        //   name: "زمان",
        //   pid: 0,
        // },
   
      ],
    };
  },
  computed: {
  },
  methods: {

    ConvertDataToTree(list, parent_id = 0, parent_element = null) {
     
      
      if (!Array.isArray(list)) {
        console.error('Input is not an array!');
        return []; // یا هر مقدار پیش‌فرض دیگری که مناسب است
    }
      
      var finalList = [];
      var index = 0;
      list.forEach((element) => {
        finalList.push({
          delNodeDisabled: true,
          dragDisabled: true,
          editNodeDisabled: true,
          addLeafNodeDisabled: true,
          addTreeNodeDisabled: true,
          isLeaf: element.children == 0,
          id: element["id"],
          index : index++,
          keyId: element["id"],
          name: element["label"],
          child_order: element["child_order"],
          children: [],
          // value: element,
          pid: parent_id,
          parent : parent_element,
          other_id : element["other_id"],
        });
      });
      return finalList;
    },
  },
}; 