import { Dict_Apis } from "@/dict/apis";
import {
  HostRootItem,
  NodeRootItem,
  QueentreeExplorer_Storage
} from "@queenjs-modules/queentree-explorer";
import { nanoid } from "nanoid";

// 设置资源面板Tab页
QueentreeExplorer_Storage.setVersion("1.0.5");
QueentreeExplorer_Storage.setDefaultValue(() => {
  const expHosts: { [name: string]: HostRootItem } = {};

  const cloudRootNode: NodeRootItem = {
    names: ["云盘"],
    ids: [nanoid()],
    nodeType: "host",
    tabPerms: ["rename", "login"],
    nodePerms: ["editable", "saveAs"],
  };

  const platformRootNode: NodeRootItem = {
    names: ["平台", "楦库", "面料"],
    ids: [
      cloudRootNode.ids[0],
      "628b4ae8633d10f8e3658557",
      "62a300a0a4fd6456392ebe76",
    ],
    nodeType: "branch",
    assetType: 31,
    tabPerms: [],
    nodePerms: ["saveAs"],
  };

  const myRootNodes = [cloudRootNode];

  if (Dict_Apis.queentreeLocal) {
    const localNodeRoot: NodeRootItem = {
      names: ["本地"],
      ids: [nanoid()],
      nodeType: "host",
      tabPerms: ["rename"],
      nodePerms: ["editable", "saveAs"],
    };

    myRootNodes.unshift(localNodeRoot);

    expHosts[localNodeRoot.ids[0]] = {
      baseURL: Dict_Apis.queentreeLocal,
      authURL: Dict_Apis.authLocal,
      authKey: "queentreesku3d",
    };
  }

  expHosts[cloudRootNode.ids[0]] = {
    baseURL: Dict_Apis.queentree,
    authURL: Dict_Apis.auth,
    authKey: "queentreesku3d",
  };

  const expNodeRoots = [...myRootNodes, platformRootNode];

  return {
    expHosts,
    expWindows: [
      {
        groupName: "我的资源",
        rootNodeIds: myRootNodes.map((rootNode) => rootNode.ids.at(-1) || ""),
      },
      {
        groupName: "平台资源",
        rootNodeIds: [platformRootNode.ids.at(-1) as string],
      },
      {
        groupName: "共享资源",
        rootNodeIds: [],
        showShareBtn: true,
      },
    ],
    expNodeRoots,
    expActiveState: {
      currWindowName: "我的资源",
    },
  };
});
