game-village-politics-frontend/app/components/market/Trades.vue

72 lines
3.7 KiB
Vue
Raw Normal View History

<script setup lang="ts">
import type { MarketState, Trade, VillageRef } from '~/types/game'
const props = defineProps<{
market: NonNullable<MarketState['market']>
trades: Trade[]
worldId: number
now: number
secondsUntil: (iso: string) => number
}>()
const { t } = useI18n()
const incoming = computed(() => props.trades.filter((x) => x.kind === 'in'))
const own = computed(() => props.trades.filter((x) => x.kind !== 'in'))
function title(x: Trade) {
if (x.kind === 'in') return t('market.trades.from', { from: villageLabel(x.from) })
if (x.kind === 'back') return t('market.trades.back_from', { from: villageLabel(x.from) })
return t('market.trades.to', { to: villageLabel(x.to) })
}
/** The other end, for the map link. */
const other = (x: Trade): VillageRef => (x.kind === 'out' ? x.to : x.from)
</script>
<!-- Merchants under way, like the rally point's movements: deliveries coming here first, then this village's merchants out and home. -->
<template>
<section class="panel">
<div class="panel-head">
<h2 class="panel-title">{{ $t('market.trades.title') }}</h2>
<span class="badge badge-plain tabular-nums">{{ $t('market.trades.merchants', { busy: market.busy, merchants: market.merchants }) }}</span>
</div>
<div class="panel-body space-y-4">
<div v-for="list in [{ key: 'incoming', rows: incoming }, { key: 'own', rows: own }]" :key="list.key">
<h3 class="mb-1 text-xs font-semibold tracking-wide text-ink-500 uppercase">{{ $t(`market.trades.${list.key}`) }}</h3>
<table v-if="list.rows.length" class="w-full text-sm">
<thead class="sr-only">
<tr>
<th>{{ $t('market.trades.trade') }}</th>
<th class="hidden @md:table-cell">{{ $t('market.arrival') }}</th>
<th>{{ $t('market.trades.arrives_in') }}</th>
</tr>
</thead>
<tbody class="divide-y divide-parchment-300">
<tr v-for="x in list.rows" :key="x.id">
<td class="py-1.5 pr-2">
<div class="flex items-start gap-2">
<IconUi :name="x.kind === 'back' ? 'return' : 'cart'" class="mt-0.5 size-4 shrink-0" />
<div class="min-w-0">
<NuxtLink :to="{ path: `/map/${worldId}`, query: { x: other(x).x, y: other(x).y } }" class="font-semibold hover:underline">{{ title(x) }}</NuxtLink>
<span v-if="x.kind === 'in' && x.from.player" class="ml-1 text-ink-500">{{ $t('market.trades.by', { player: x.from.player.name }) }}</span>
<div class="mt-0.5 flex flex-wrap items-center gap-x-2.5 gap-y-0.5 text-xs text-ink-700">
<MarketCargo v-if="x.cargo" :cargo="x.cargo" />
<span v-if="x.kind !== 'in'" class="inline-flex items-center gap-0.5 whitespace-nowrap tabular-nums">
<IconUi name="cart" class="size-3.5" />{{ $t('market.trades.merchants_n', { count: x.merchants }) }}
</span>
<span v-if="x.route_id !== null" class="badge badge-plain">{{ $t('market.trades.route') }}</span>
<span v-if="x.offer" class="badge badge-plain">{{ $t('market.trades.offer') }}</span>
</div>
</div>
</div>
</td>
<td class="hidden py-1.5 pr-2 whitespace-nowrap text-ink-700 tabular-nums @md:table-cell">{{ formatArrival(Date.parse(x.arrives_at), now, t) }}</td>
<td class="py-1.5 text-right font-semibold whitespace-nowrap tabular-nums">{{ formatDuration(secondsUntil(x.arrives_at)) }}</td>
</tr>
</tbody>
</table>
<p v-else class="text-sm text-ink-500">{{ $t(`market.trades.none_${list.key}`) }}</p>
</div>
</div>
</section>
</template>