35 lines
1.7 KiB
Vue
35 lines
1.7 KiB
Vue
<script setup lang="ts">
|
|
const props = defineProps<{ id: string; min: number; max: number }>()
|
|
/** Seconds of real time. */
|
|
const every = defineModel<number>({ required: true })
|
|
const { t } = useI18n()
|
|
|
|
const hours = ref(Math.floor(every.value / 3600))
|
|
const minutes = ref(Math.round((every.value % 3600) / 60))
|
|
watch([hours, minutes], () => {
|
|
every.value = Math.max(0, Math.floor(Number(hours.value) || 0)) * 3600 + Math.max(0, Math.floor(Number(minutes.value) || 0)) * 60
|
|
})
|
|
watch(every, (s) => {
|
|
if (s === Math.floor(Number(hours.value) || 0) * 3600 + Math.floor(Number(minutes.value) || 0) * 60) return
|
|
hours.value = Math.floor(s / 3600)
|
|
minutes.value = Math.round((s % 3600) / 60)
|
|
})
|
|
const outside = computed(() => every.value < props.min || every.value > props.max)
|
|
</script>
|
|
|
|
<!-- A route's interval in real hours and minutes, with the range the market allows. -->
|
|
<template>
|
|
<div class="space-y-0.5 text-sm">
|
|
<div class="flex flex-wrap items-center gap-1.5">
|
|
<label :for="`${id}-h`" class="label mb-0 w-24">{{ $t('market.routes.every') }}</label>
|
|
<input :id="`${id}-h`" v-model.number="hours" type="number" min="0" inputmode="numeric" class="input w-14 px-1.5 py-0.5 text-right tabular-nums" :aria-label="$t('market.routes.hours')" />
|
|
<span>{{ $t('market.routes.h') }}</span>
|
|
<input v-model.number="minutes" type="number" min="0" max="59" step="5" inputmode="numeric" class="input w-14 px-1.5 py-0.5 text-right tabular-nums" :aria-label="$t('market.routes.minutes')" />
|
|
<span>{{ $t('market.routes.min') }}</span>
|
|
</div>
|
|
<p class="text-xs" :class="outside ? 'text-blood-700' : 'text-ink-500'">
|
|
{{ $t('market.routes.range', { min: formatInterval(min, t), max: formatInterval(max, t) }) }}
|
|
</p>
|
|
</div>
|
|
</template>
|