<script setup lang="ts">
import { useTheme, useCopy } from '~/composables/useLanding'
import { C } from '~/utils/landingTokens'

definePageMeta({ layout: 'page' })

const t = useTheme()
const copy = useCopy()
const c = computed(() => copy.value.pages.status)

// Status keys → colours. Operational green, planned/coming-soon muted, plus
// degraded/down for when an incident is logged in the copy.
const COLORS: Record<string, string> = {
  operational: C.ok,
  planned: C.slate,
  degraded: C.warn,
  down: C.bad,
}
const dotColor = (key: string) => COLORS[key] ?? C.slate
const labelColor = (key: string) => (key === 'degraded' || key === 'down' ? COLORS[key]! : t.value.fgMuted)

// Overall banner is "all good" unless something is actively degraded/down.
const allOk = computed(() => c.value.services.every(s => s[1] !== 'degraded' && s[1] !== 'down'))
const bannerColor = computed(() => (allOk.value ? C.ok : C.warn))

const headingStyle = computed(() => ({
  fontFamily: '\'Inter Tight\', sans-serif', fontWeight: 600, fontSize: '22px',
  letterSpacing: '-0.015em', color: t.value.fg, margin: '0 0 16px',
}))

useHead({ title: () => `${copy.value.pages.status.title} · dezky` })
</script>

<template>
  <LandingPageHeader :label="c.label" :title="c.title" :intro="c.intro" />

  <LandingContainer pad="clamp(32px, 5vw, 48px) clamp(20px, 5vw, 64px) clamp(80px, 12vw, 160px)">
    <div :style="{ maxWidth: '760px' }">
      <!-- Overall status banner -->
      <div :style="{ display: 'flex', alignItems: 'center', gap: '14px', padding: '20px 24px', borderRadius: '4px', border: `1px solid ${bannerColor}44`, background: `${bannerColor}12`, marginBottom: '48px' }">
        <span :style="{ width: '12px', height: '12px', borderRadius: '999px', background: bannerColor, boxShadow: `0 0 0 4px ${bannerColor}22`, flexShrink: 0 }" />
        <span :style="{ fontFamily: '\'Inter Tight\', sans-serif', fontWeight: 600, fontSize: '20px', letterSpacing: '-0.015em', color: t.fg }">{{ c.overallOk }}</span>
      </div>

      <!-- Per-service status -->
      <h2 :style="headingStyle">{{ c.servicesHeading }}</h2>
      <div :style="{ border: `1px solid ${t.border}`, borderRadius: '4px', overflow: 'hidden', margin: '0 0 48px' }">
        <div
          v-for="(s, i) in c.services" :key="i"
          :style="{ display: 'grid', gridTemplateColumns: '1fr auto', gap: '16px', alignItems: 'center', padding: '16px 20px', borderTop: i === 0 ? 'none' : `1px solid ${t.border}`, background: t.surface }"
        >
          <span :style="{ display: 'flex', alignItems: 'center', gap: '12px', fontFamily: '\'Inter\', sans-serif', fontSize: '15px', color: t.fg }">
            <span :style="{ width: '8px', height: '8px', borderRadius: '999px', background: dotColor(s[1]), flexShrink: 0 }" />
            {{ s[0] }}
          </span>
          <span :style="{ fontFamily: '\'JetBrains Mono\', monospace', fontSize: '12px', letterSpacing: '0.04em', color: labelColor(s[1]), whiteSpace: 'nowrap' }">{{ c.statusLabels[s[1]] ?? s[1] }}</span>
        </div>
      </div>

      <!-- Incident history -->
      <h2 :style="headingStyle">{{ c.incidentsHeading }}</h2>
      <p :style="{ fontFamily: '\'Inter\', sans-serif', fontSize: '15px', lineHeight: 1.6, color: t.fgMuted, margin: 0 }">{{ c.noIncidents }}</p>
    </div>
  </LandingContainer>
</template>
