<script setup lang="ts">
// Section 04 — sovereignty. Inverted (carbon) panel with a heading/body column
// and a spec table. Ported from landing-sections.jsx Sovereignty.
import { computed } from 'vue'
import { C } from '~/utils/landingTokens'
import { useTheme, useCopy } from '~/composables/useLanding'

const t = useTheme()
const copy = useCopy()

// Borders/muted derive from whether the inverted foreground is bone (light
// page → carbon panel → bone text) or carbon (dark page → bone panel).
const onBone = computed(() => t.value.invertFg === C.bone)
const rule14 = computed(() => (onBone.value ? 'rgba(244,243,238,0.14)' : 'rgba(10,10,10,0.14)'))
const rule18 = computed(() => (onBone.value ? 'rgba(244,243,238,0.18)' : 'rgba(10,10,10,0.18)'))
const rule10 = computed(() => (onBone.value ? 'rgba(244,243,238,0.1)' : 'rgba(10,10,10,0.1)'))
const muted55 = computed(() => (onBone.value ? 'rgba(244,243,238,0.55)' : 'rgba(10,10,10,0.55)'))
const muted70 = computed(() => (onBone.value ? 'rgba(244,243,238,0.7)' : 'rgba(10,10,10,0.7)'))

const labelParts = computed(() => {
  const [index, ...rest] = copy.value.sovereignty.label.split(' — ')
  return { index, text: rest.join(' — ') }
})
</script>

<template>
  <section id="sovereignty" :style="{ background: t.invert, color: t.invertFg, scrollMarginTop: '72px' }">
    <LandingContainer pad="clamp(56px, 8vw, 140px) clamp(20px, 5vw, 64px)">
      <div :style="{
        display: 'flex', alignItems: 'center', gap: '14px',
        paddingBottom: '24px', marginBottom: '56px',
        borderBottom: `1px solid ${rule14}`,
        fontFamily: '\'JetBrains Mono\', monospace', fontSize: '11px',
        letterSpacing: '0.16em', textTransform: 'uppercase', color: muted55,
      }">
        <span :style="{ opacity: 0.6 }">{{ labelParts.index }}</span>
        <span>—</span>
        <span>{{ labelParts.text }}</span>
      </div>
      <div class="sovereignty-main-grid" :style="{ display: 'grid', gap: '96px' }">
        <div>
          <h2 :style="{ fontFamily: '\'Inter Tight\', sans-serif', fontWeight: 600, fontSize: 'clamp(36px, 4.4vw, 64px)', letterSpacing: '-0.032em', lineHeight: 1.0, margin: 0, textWrap: 'balance', color: t.invertFg }">{{ copy.sovereignty.heading }}</h2>
          <div :style="{ marginTop: '36px', display: 'flex', flexDirection: 'column', gap: '18px', maxWidth: '540px' }">
            <p v-for="(p, i) in copy.sovereignty.body" :key="i" :style="{ fontFamily: '\'Inter\', sans-serif', fontSize: '17px', lineHeight: 1.55, color: muted70, margin: 0, textWrap: 'pretty' }">{{ p }}</p>
          </div>
        </div>
        <div :style="{ paddingTop: '8px' }">
          <div
            v-for="(row, i) in copy.sovereignty.checks" :key="i"
            class="sovereignty-check-row"
            :style="{
              display: 'grid', padding: '20px 0',
              borderTop: i === 0 ? `1px solid ${rule18}` : 'none',
              borderBottom: `1px solid ${rule10}`,
              fontFamily: '\'Inter\', sans-serif', fontSize: '14px', alignItems: 'baseline',
            }"
          >
            <div :style="{ fontFamily: '\'JetBrains Mono\', monospace', fontSize: '11px', color: muted55, letterSpacing: '0.06em', textTransform: 'uppercase' }">{{ row[0] }}</div>
            <div :style="{ color: t.invertFg, fontWeight: 500 }">{{ row[1] }}</div>
          </div>
        </div>
      </div>
    </LandingContainer>
  </section>
</template>

<style scoped>
.sovereignty-main-grid {
  grid-template-columns: 1.1fr 1fr;
}

.sovereignty-check-row {
  grid-template-columns: 1fr 1.4fr;
}

@media (max-width: 768px) {
  .sovereignty-main-grid {
    grid-template-columns: 1fr;
  }

  .sovereignty-check-row {
    grid-template-columns: 1fr;
  }
}
</style>
