// import { useUserStore } from '@/store/modules/user';

export function usePermission() {
  // const userStore = useUserStore();

  /**
   * 检查权限
   * @param accesses
   */
  function _somePermissions(accesses: string[]) {
    // return userStore.getPermissions.some((item: any) => {
    //   const { value }: any = item;
    //   return accesses.includes(value);
    // });
    return false;
  }

  /**
   * 判断是否存在权限
   * 可用于 v-if 显示逻辑
   * */
  function hasPermission(accesses: string[]): boolean {
    if (!accesses || !accesses.length) return true;
    return _somePermissions(accesses);
  }

  /**
   * 是否包含指定的所有权限
   * @param accesses
   */
  function hasEveryPermission(accesses: string[]): boolean {
    // const permissionsList = userStore.getPermissions;
    // if (Array.isArray(accesses)) {
    //   return permissionsList.every((access: any) =>
    //     accesses.includes(access.value)
    //   );
    // }
    return false;
    // throw new Error(`[hasEveryPermission]: ${accesses} should be a array !`);
  }

  /**
   * 是否包含其中某个权限
   * @param accesses
   * @param accessMap
   */
  function hasSomePermission(accesses: string[]): boolean {
    // const permissionsList = userStore.getPermissions;
    // if (Array.isArray(accesses)) {
    //   return permissionsList.some((access: any) =>
    //     accesses.includes(access.value)
    //   );
    // }
    return false;
    // throw new Error(`[hasSomePermission]: ${accesses} should be a array !`);
  }

  return { hasPermission, hasEveryPermission, hasSomePermission };
}
