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

68 lines
2.4 KiB
Vue

<script setup lang="ts">
import type { BuildOption, BuildingType, Cost, Resources } from '~/types/game'
const props = defineProps<{
options: BuildOption[]
space: { used: number; max: number }
resources: Resources
canAfford: (cost: Cost) => boolean
busy: boolean
}>()
const emit = defineEmits<{ build: [type: BuildingType] }>()
const { t } = useI18n()
function status(o: BuildOption) {
if (o.blocked) return t(`village.blocked.${o.blocked}`)
if (!props.canAfford(o.cost)) return t('village.blocked.resources')
return ''
}
</script>
<template>
<section class="panel">
<div class="panel-head">
<h2 class="panel-title">{{ $t('village.build.title') }}</h2>
<span class="badge badge-plain">
{{ $t('village.build.free_space', { free: space.max - space.used }) }}
</span>
</div>
<div class="panel-body grid gap-3 sm:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4">
<article
v-for="o in options"
:key="o.type"
class="flex flex-col gap-2.5 rounded-sm border-2 border-parchment-300 bg-parchment-100 p-3"
:class="o.blocked ? 'opacity-60' : ''"
>
<div class="flex items-center gap-2.5">
<IconBuildingTile :type="o.type" class="size-10" />
<div class="min-w-0">
<h3 class="truncate font-medium">{{ $t(`buildings.${o.type}`) }}</h3>
<p class="flex flex-wrap items-center gap-x-1.5 text-xs text-ink-500">
<span class="whitespace-nowrap">
{{ o.space ? $t('village.build.space', { space: o.space }) : $t('village.build.surrounds') }}
</span>
<span class="flex items-center gap-1 whitespace-nowrap tabular-nums">
<IconUi name="clock" class="size-3" />
{{ formatDuration(o.seconds) }}
</span>
</p>
</div>
</div>
<UiCost :cost="o.cost" :have="resources" />
<div class="mt-auto flex items-center justify-between gap-2">
<span class="text-xs font-semibold text-blood-700">{{ status(o) }}</span>
<button
type="button"
class="btn btn-primary"
:disabled="busy || !!o.blocked || !canAfford(o.cost)"
@click="emit('build', o.type)"
>
<IconUi name="hammer" class="size-3.5" />
{{ $t('village.build.submit') }}
</button>
</div>
</article>
</div>
</section>
</template>