import { useUserInfo } from '../stores/userInfo.mjs';

const _getUserInfo = () => {
  const store = useUserInfo();
  return store.userInfos;
};
const isSupperAdmin = () => {
  var _a;
  return ((_a = _getUserInfo()) == null ? void 0 : _a.accountType) === 999;
};
const isTenantAdmin = () => {
  var _a;
  return ((_a = _getUserInfo()) == null ? void 0 : _a.accountType) === 888;
};
const isAdmin = () => {
  return isSupperAdmin() || isTenantAdmin();
};
const isNormalUser = () => {
  var _a;
  return ((_a = _getUserInfo()) == null ? void 0 : _a.accountType) === 777;
};
const isMember = () => {
  var _a;
  return ((_a = _getUserInfo()) == null ? void 0 : _a.accountType) === 666;
};
const userEmail = () => {
  var _a;
  return (_a = _getUserInfo()) == null ? void 0 : _a.email;
};
const userName = () => {
  var _a;
  return (_a = _getUserInfo()) == null ? void 0 : _a.userName;
};
const userFriendName = () => {
  var _a, _b, _c, _d, _e;
  return ((_a = _getUserInfo()) == null ? void 0 : _a.realName) ? (_b = _getUserInfo()) == null ? void 0 : _b.realName : ((_c = _getUserInfo()) == null ? void 0 : _c.account) ? (_d = _getUserInfo()) == null ? void 0 : _d.account : (_e = _getUserInfo()) == null ? void 0 : _e.email;
};
const tenantId = () => {
  var _a;
  return (_a = _getUserInfo()) == null ? void 0 : _a.tenantId;
};
const userAccount = () => {
  var _a;
  return (_a = _getUserInfo()) == null ? void 0 : _a.account;
};
const userPhone = () => {
  var _a;
  return (_a = _getUserInfo()) == null ? void 0 : _a.phone;
};
const userId = () => {
  var _a;
  return (_a = _getUserInfo()) == null ? void 0 : _a.id;
};
const orgId = () => {
  var _a;
  return (_a = _getUserInfo()) == null ? void 0 : _a.orgId;
};
const orgName = () => {
  var _a;
  return (_a = _getUserInfo()) == null ? void 0 : _a.orgName;
};
const cmpId = () => {
  var _a;
  return (_a = _getUserInfo()) == null ? void 0 : _a.cmpId;
};
const depId = () => {
  var _a;
  return (_a = _getUserInfo()) == null ? void 0 : _a.depId;
};
const groupId = () => {
  var _a;
  return (_a = _getUserInfo()) == null ? void 0 : _a.groupId;
};
const getOpOrg = () => {
  let orgId2 = 0;
  if (groupId() > 0) {
    orgId2 = groupId();
  } else if (depId() > 0) {
    orgId2 = depId();
  } else if (cmpId() > 0) {
    orgId2 = cmpId();
  }
  return { opOrgId: orgId2, opCmpId: cmpId(), opDetId: depId(), opGroupId: groupId() };
};
const posId = () => {
  var _a;
  return (_a = _getUserInfo()) == null ? void 0 : _a.posId;
};
const posName = () => {
  var _a;
  return (_a = _getUserInfo()) == null ? void 0 : _a.posName;
};
const roles = () => {
  var _a;
  return (_a = _getUserInfo()) == null ? void 0 : _a.roles;
};
const hasRoleCode = (code) => {
  var _a;
  return ((_a = _getUserInfo()) == null ? void 0 : _a.roles.find((u) => u.code === code)) ? true : false;
};
const hasPrivilege = (privilege) => {
  var _a;
  return (_a = _getUserInfo()) == null ? void 0 : _a.authApiList.includes(privilege);
};

export { cmpId, depId, getOpOrg, groupId, hasPrivilege, hasRoleCode, isAdmin, isMember, isNormalUser, isSupperAdmin, isTenantAdmin, orgId, orgName, posId, posName, roles, tenantId, userAccount, userEmail, userFriendName, userId, userName, userPhone };
