game-village-politics-frontend/app/components/game/ProtectionBar.vue

45 lines
1.5 KiB
Vue
Raw Normal View History

<script setup lang="ts">
const props = defineProps<{
until: string
villageId: number
secondsUntil: (iso: string) => number
}>()
// Shown until it ends, or until the player closes it for this session.
const key = computed(() => `vp.protection.hidden.${props.villageId}`)
const hidden = ref(false)
onMounted(() => {
try {
hidden.value = sessionStorage.getItem(key.value) === '1'
} catch {
// no storage: the bar just shows again
}
})
function close() {
hidden.value = true
try {
sessionStorage.setItem(key.value, '1')
} catch {
// only this page view remembers it
}
}
const left = computed(() => props.secondsUntil(props.until))
</script>
<!-- A slim notice under the village bar while beginner protection lasts, with its countdown. -->
<template>
<div v-if="!hidden && left > 0" class="border-b-2 border-wood-700 bg-parchment-50" role="status">
<div class="mx-auto flex max-w-[96rem] items-center gap-2 px-3 py-1.5 text-sm sm:px-6">
<IconUi name="support" class="size-4 shrink-0 text-moss-700" />
<p class="min-w-0 flex-1">
{{ $t('village.protection.ends_in') }}
<span class="font-semibold tabular-nums">{{ formatDuration(left) }}</span>
<span class="hidden text-ink-500 sm:inline"> · {{ $t('village.protection.hint') }}</span>
</p>
<button type="button" class="text-ink-500 hover:text-blood-700" :aria-label="$t('common.close')" @click="close">
<IconUi name="close" class="size-4" />
</button>
</div>
</div>
</template>