import { defineStore } from "pinia";
// import local from './local/zj'
localStorage.setItem(
  "userInfo",
  JSON.stringify(local)
);

const RoleMap = {
  JLD: [1, 2, 3],
  ZJ: [4, 5, 6],
  JYZ: [7, 8],
};
export const userInfo = JSON.parse(localStorage.getItem("userInfo"));
const {
  token,
  org_info,
  user_realname,
  user_avatar,
  power,
  dept_ids,
  dept_id,
  uo_id,
  uo_name,
  user_id,
  user_org,
} = userInfo;

export const user = {
  userInfo,
  token,
  // role: org_info.dept_role.role_id * 1,
  real_name: user_realname,
  avatar: user_avatar,
  // roleName:
  //   Object.keys(RoleMap).find((k) =>
  //     RoleMap[k].includes(org_info.dept_role.role_id * 1)
  //   ) || 'None',
  power: power,
  dept_ids: dept_ids,
  dept_id,
  uo_id,
  uo_name,
  user_id: user_id,
  user_org: user_org,
};
export const useUserStore = defineStore("user", {
  state: () => user,
  actions: {
    logout() {
      localStorage.removeItem("userInfo");
      window.open(window.globalVariables.login, "_self");
    },
  },
});
