import { useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import { StateEvent } from '../../../../types/matrix/room';
import { PermissionGroup } from '../../common-settings/permissions';

export const usePermissionGroups = (): PermissionGroup[] => {
  const { t } = useTranslation();
  const groups: PermissionGroup[] = useMemo(() => {
    const messagesGroup: PermissionGroup = {
      name: t('RoomSettings.perm_manage'),
      items: [
        {
          location: {
            state: true,
            key: StateEvent.SpaceChild,
          },
          name: t('RoomSettings.perm_manage_space_rooms'),
        },
        {
          location: {},
          name: t('RoomSettings.perm_other_message_events'),
        },
      ],
    };

    const moderationGroup: PermissionGroup = {
      name: t('RoomSettings.perm_moderation'),
      items: [
        {
          location: {
            action: true,
            key: 'invite',
          },
          name: t('RoomSettings.perm_invite'),
        },
        {
          location: {
            action: true,
            key: 'kick',
          },
          name: t('RoomSettings.perm_kick'),
        },
        {
          location: {
            action: true,
            key: 'ban',
          },
          name: t('RoomSettings.perm_ban'),
        },
      ],
    };

    const roomOverviewGroup: PermissionGroup = {
      name: t('RoomSettings.perm_space_overview'),
      items: [
        {
          location: {
            state: true,
            key: StateEvent.RoomAvatar,
          },
          name: t('RoomSettings.perm_space_avatar'),
        },
        {
          location: {
            state: true,
            key: StateEvent.RoomName,
          },
          name: t('RoomSettings.perm_space_name'),
        },
        {
          location: {
            state: true,
            key: StateEvent.RoomTopic,
          },
          name: t('RoomSettings.perm_space_topic'),
        },
      ],
    };

    const roomSettingsGroup: PermissionGroup = {
      name: t('RoomSettings.perm_settings'),
      items: [
        {
          location: {
            state: true,
            key: StateEvent.RoomJoinRules,
          },
          name: t('RoomSettings.perm_change_space_access'),
        },
        {
          location: {
            state: true,
            key: StateEvent.RoomCanonicalAlias,
          },
          name: t('RoomSettings.perm_publish_address'),
        },
        {
          location: {
            state: true,
            key: StateEvent.RoomPowerLevels,
          },
          name: t('RoomSettings.perm_change_all_permission'),
        },
        {
          location: {
            state: true,
            key: StateEvent.PowerLevelTags,
          },
          name: t('RoomSettings.perm_edit_power_levels'),
        },
        {
          location: {
            state: true,
            key: StateEvent.RoomTombstone,
          },
          name: t('RoomSettings.perm_upgrade_space'),
        },
        {
          location: {
            state: true,
          },
          name: t('RoomSettings.perm_other_settings'),
        },
      ],
    };

    const otherSettingsGroup: PermissionGroup = {
      name: t('RoomSettings.perm_other'),
      items: [
        {
          location: {
            state: true,
            key: StateEvent.PoniesRoomEmotes,
          },
          name: t('RoomSettings.perm_manage_emojis_stickers'),
        },
        {
          location: {
            state: true,
            key: StateEvent.RoomServerAcl,
          },
          name: t('RoomSettings.perm_change_server_acls'),
        },
      ],
    };

    return [
      messagesGroup,
      moderationGroup,
      roomOverviewGroup,
      roomSettingsGroup,
      otherSettingsGroup,
    ];
  }, [t]);

  return groups;
};
