import { Exp_Storage } from "@queenjs-modules/queentree-explorer/dicts/storage";
import {
  HostRootItem,
  NodeRootItem,
} from "@queenjs-modules/queentree-explorer/typings";

import ListModule from "..";

export default ListModule.action({
  initExpStorage(baseURL: string) {
    Exp_Storage.setVersion("1.0.5").setDefaultValue(() => {
      const expHosts: { [name: string]: HostRootItem } = {};

      const localNodeRoot: NodeRootItem = {
        names: ["本地"],
        ids: [Math.random().toString()],
        nodeType: "host",
        tabPerms: ["rename"],
        nodePerms: ["editable", "saveAs"],
      };

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

      const expNodeRoots = [localNodeRoot];

      return {
        expHosts,
        expWindows: [
          {
            groupName: "我的资源",
            rootNodeIds: expNodeRoots.map(
              (rootNode) => rootNode.ids.at(-1) || ""
            ),
          },
        ],
        expNodeRoots,
        expActiveState: {
          currWindowName: "我的资源",
        },
      };
    });
  },
});
