import { removeTokenInfo } from "@dage/pc-components";
import { logoutApi } from "@/api";
import { Key } from "react";

export const logout = async () => {
  await logoutApi();

  removeTokenInfo();
  globalThis.location.href = "#/login";
};

export const getSelectedNodes = (selectedKeys: Key[], treeData: any[]) => {
  let selectedNodes: any[] = [];

  const findNodes = (keys: Key[], data: any[]) => {
    data.forEach((node) => {
      if (keys.includes(node.id) && !node.children) {
        selectedNodes.push(node);
      }
      if (node.children) {
        findNodes(keys, node.children);
      }
    });
  };

  findNodes(selectedKeys, treeData);
  return selectedNodes;
};
