"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.isModerator = exports.isAdmin = exports.checkStoryPermission = exports.checkEditRolePermission = exports.checkEditCommunityPermission = exports.checkDeleteCommunityPermission = void 0;
var _tsSdkReactNative = require("@amityco/ts-sdk-react-native");
var _constants = require("../../core/constants");
const checkDeleteCommunityPermission = communityId => {
  const client = _tsSdkReactNative.Client.getActiveClient();
  const communityPermission = client.hasPermission(_constants.Permissions.DeleteCommunityPermission).community(communityId);
  return !!communityPermission;
};
exports.checkDeleteCommunityPermission = checkDeleteCommunityPermission;
const checkEditCommunityPermission = communityId => {
  const client = _tsSdkReactNative.Client.getActiveClient();
  const communityPermission = client.hasPermission(_constants.Permissions.EditCommunityPermission).community(communityId);
  return !!communityPermission;
};
exports.checkEditCommunityPermission = checkEditCommunityPermission;
const checkEditRolePermission = communityId => {
  const client = _tsSdkReactNative.Client.getActiveClient();
  const communityPermission = client.hasPermission(_constants.Permissions.EditRolePermission).community(communityId);
  return !!communityPermission;
};
exports.checkEditRolePermission = checkEditRolePermission;
const isModerator = (roles = []) => {
  if (!(roles !== null && roles !== void 0 && roles.length)) return false;
  const moderatorRoles = [_constants.MemberRoles.COMMUNITY_MODERATOR, _constants.MemberRoles.CHANNEL_MODERATOR, _constants.MemberRoles.MODERATOR, _constants.MemberRoles.SUPER_MODERATOR];
  return moderatorRoles.some(role => roles.includes(role));
};
exports.isModerator = isModerator;
const isAdmin = (roles = []) => {
  if (!(roles !== null && roles !== void 0 && roles.length)) return false;
  return roles.includes(_constants.MemberRoles.ADMIN);
};
exports.isAdmin = isAdmin;
const checkStoryPermission = (client, communityId) => {
  if (!client) {
    return false;
  }
  if (communityId) {
    const communityPermission = client.hasPermission(_constants.Permissions.ManageStoryPermission).community(communityId);
    return communityPermission;
  }
  return false;
};
exports.checkStoryPermission = checkStoryPermission;
//# sourceMappingURL=permissions.js.map