game-village-politics-frontend/app/components/map/InfoCard.vue

44 lines
1.9 KiB
Vue

<script setup lang="ts">
import type { MapVillage } from '~/types/map'
defineProps<{
village: MapVillage | null
at: { x: number; y: number } | null
}>()
const emit = defineEmits<{ center: [at: { x: number; y: number }] }>()
const continentOf = (x: number, y: number) => `K${Math.floor(y / 100)}${Math.floor(x / 100)}`
</script>
<template>
<section class="panel">
<div class="panel-head">
<h2 class="panel-title">{{ $t('map.info.title') }}</h2>
</div>
<div class="panel-body text-sm">
<template v-if="village">
<p class="font-display text-lg font-semibold">{{ village.name }}</p>
<dl class="mt-3 grid grid-cols-[auto_1fr] gap-x-4 gap-y-1.5">
<dt class="text-ink-500">{{ $t('map.info.coordinates') }}</dt>
<dd class="font-semibold tabular-nums">{{ village.x }}|{{ village.y }} <span class="text-ink-500">{{ village.continent }}</span></dd>
<dt class="text-ink-500">{{ $t('map.info.owner') }}</dt>
<dd>{{ village.player?.name ?? $t('map.barbarian') }}</dd>
<dt class="text-ink-500">{{ $t('map.info.points') }}</dt>
<dd class="tabular-nums">{{ village.points }}</dd>
</dl>
<div class="mt-4 flex flex-wrap gap-2">
<NuxtLink v-if="village.own" :to="`/village/${village.id}`" class="btn btn-primary">{{ $t('map.info.open') }}</NuxtLink>
<button type="button" class="btn btn-outline" @click="emit('center', { x: village.x, y: village.y })">
{{ $t('map.info.center') }}
</button>
</div>
</template>
<template v-else-if="at">
<p class="text-ink-700">{{ $t('map.info.empty') }}</p>
<p class="mt-1 font-semibold tabular-nums">{{ at.x }}|{{ at.y }} <span class="text-ink-500">{{ continentOf(at.x, at.y) }}</span></p>
</template>
<p v-else class="text-ink-500">{{ $t('map.info.hint') }}</p>
</div>
</section>
</template>