import SwtionElement from "@/plugins/element";

export default class attributeOptions {
  private swtionEle = new SwtionElement();
  public loadAttributeOption() {
    const eleList = this.swtionEle.loadTree();
    // const attributeOptions = [
    //   {
    //     id: ifType.attribute,
    //     name: ifType[ifType.attribute],
    //     children: [
    //       {
    //         id: eleList.id,
    //         name: eleList.name,
    //         children: this.loadEleOption(eleList),
    //       },
    //     ],
    //   },
    // ];
    const attributeOptions = [
      {
        id: eleList.id,
        name: eleList.name,
        children: this.loadEleOption(eleList),
      }
    ]
    return attributeOptions;
  }

  private loadEleOption(source: IBaseElement) {
    return eleToOptions(source);
    function eleToOptions(eleList: IBaseElement) {
      let items = [
        {
          id: "self",
          name: "自有属性",
          children: eleList.attribute.self,
        },
        {
          id: "parent",
          name: "继承属性",
          children: eleList.attribute.parent,
        },
      ];
      for (let i = 0; i < eleList.children.length; i++) {
        items.push({
          id: eleList.children[i].id,
          name: eleList.children[i].name,
          children: eleToOptions(eleList.children[i]) as any,
        });
      }
      return items;
    }
  }
}