<!--
SPDX-FileCopyrightText: syuilo and misskey-project
SPDX-License-Identifier: AGPL-3.0-only
-->

<template>
<div class="_gaps_m">
	<FormSection first>
		<template #label>{{ i18n.ts.rolesAssignedToMe }}</template>
		<div class="_gaps_s">
			<MkRolePreview v-for="role in $i.roles" :key="role.id" :role="role" :forModeration="false"/>
		</div>
	</FormSection>
	<FormSection>
		<template #label>{{ i18n.ts._role.policies }}</template>
		<MkKeyValue v-for="policy in Object.keys($i.policies)" :key="policy" oneline style="margin: 1em 0;">
			<template #key>{{ i18n.ts._role._options[`${policy}`] }}</template>
			<template #value>{{ getValue(policy, $i.policies[policy]) }}</template>
		</MkKeyValue>
	</FormSection>
</div>
</template>

<script lang="ts" setup>
import { computed } from 'vue';
import FormSection from '@/components/form/section.vue';
import { i18n } from '@/i18n.js';
import { signinRequired } from '@/account.js';
import { definePageMetadata } from '@/scripts/page-metadata.js';
import MkRolePreview from '@/components/MkRolePreview.vue';
import MkKeyValue from '@/components/MkKeyValue.vue';

const $i = signinRequired();

function getValue(policy, policyValue) {
	if (typeof(policyValue) === 'boolean') {
		return policyValue ? i18n.ts.yes : i18n.ts.no;
	} else if (typeof(policyValue) === 'number') {
		if (policy === 'driveCapacityMb') {
			return `${policyValue}MB`;
		}
		return policyValue;
	} else {
		return policyValue;
	}
}

const headerActions = computed(() => []);

const headerTabs = computed(() => []);

definePageMetadata(() => ({
	title: i18n.ts.roles,
	icon: 'ti ti-badges',
}));
</script>

<style lang="scss" module>

</style>
