<script setup lang="ts">
import { computed } from 'vue'
import { formatDateCompact } from '../../lib/format'
import type { DashboardSection } from '../../types'

interface Props {
  activeSection: DashboardSection
  selectedDate: string
  availableDates: string[]
  summary: string
  focusSectors: string[]
}

const props = defineProps<Props>()

const emit = defineEmits<{
  selectSection: [DashboardSection]
  selectDate: [string]
}>()

const navItems: Array<{
  key: DashboardSection
  label: string
  note: string
}> = [
  { key: 'cls', label: '财联社 7x24', note: '按日期查看全天资讯与热点概览' },
  { key: 'opinions', label: '大V日报', note: '按日期查看文章观点与对应板块' },
  { key: 'input', label: '日报录入', note: '按公众号补录当天文章链接' },
]

const recentDates = computed(() => props.availableDates.slice(0, 6))
</script>

<template>
  <aside class="sidebar">
    <div class="sidebar-top">
      <p class="eyebrow">Finance Daily</p>
      <h1 class="brand-title">财经内容日报</h1>
      <p class="brand-copy">
        面向日常资讯跟踪、观点汇总和日报录入，保持结构清晰，减少无效装饰。
      </p>
    </div>

    <nav class="nav-list">
      <button
        v-for="item in navItems"
        :key="item.key"
        class="nav-button"
        :class="{ 'nav-button--active': item.key === props.activeSection }"
        type="button"
        @click="emit('selectSection', item.key)"
      >
        <span class="nav-label">{{ item.label }}</span>
        <span class="nav-note">{{ item.note }}</span>
      </button>
    </nav>

    <div class="sidebar-block">
      <label class="block-label" for="sidebar-date">观察日期</label>
      <input
        id="sidebar-date"
        class="date-input"
        :value="props.selectedDate"
        type="date"
        @input="emit('selectDate', ($event.target as HTMLInputElement).value)"
      />
      <div class="date-pills hide-scrollbar">
        <button
          v-for="dateValue in recentDates"
          :key="dateValue"
          class="date-pill"
          :class="{ 'date-pill--active': dateValue === props.selectedDate }"
          type="button"
          @click="emit('selectDate', dateValue)"
        >
          {{ formatDateCompact(dateValue) }}
        </button>
      </div>
    </div>

    <div class="sidebar-block sidebar-block--dense">
      <p class="block-label">当前摘要</p>
      <p class="summary-copy">{{ props.summary }}</p>
      <div class="sector-tags">
        <span v-for="sector in props.focusSectors.slice(0, 6)" :key="sector" class="sector-tag">
          {{ sector }}
        </span>
      </div>
    </div>
  </aside>
</template>

<style scoped>
.sidebar {
  display: grid;
  grid-template-rows: auto auto auto 1fr;
  gap: 18px;
  min-height: 0;
  padding: 24px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-xl);
  background: rgba(255, 252, 247, 0.96);
  box-shadow: var(--shadow-soft);
  overflow: auto;
}

.sidebar-top {
  display: grid;
  gap: 8px;
}

.eyebrow {
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.brand-title {
  margin: 0;
  font-family: "Palatino Linotype", "STSong", "Songti SC", serif;
  font-size: 30px;
  line-height: 1.08;
  color: var(--ink-strong);
}

.brand-copy {
  margin: 0;
  font-size: 14px;
  color: var(--ink-soft);
}

.nav-list {
  display: grid;
  gap: 10px;
}

.nav-button {
  display: grid;
  gap: 6px;
  padding: 16px 18px;
  text-align: left;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: rgba(255, 249, 241, 0.68);
  transition: border-color 160ms ease, background 160ms ease;
}

.nav-button:hover {
  border-color: var(--line-strong);
}

.nav-button--active {
  border-color: rgba(143, 90, 45, 0.24);
  background: linear-gradient(135deg, rgba(143, 90, 45, 0.12), rgba(143, 90, 45, 0.04));
}

.nav-label {
  font-size: 16px;
  color: var(--ink-strong);
}

.nav-note {
  font-size: 13px;
  color: var(--ink-soft);
}

.sidebar-block {
  display: grid;
  gap: 12px;
  padding: 16px 18px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-md);
  background: rgba(255, 251, 245, 0.76);
}

.sidebar-block--dense {
  align-content: start;
  min-height: 0;
}

.block-label {
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.date-input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.6);
  outline: none;
}

.date-input:focus {
  border-color: rgba(143, 90, 45, 0.36);
}

.date-pills {
  display: flex;
  gap: 8px;
  min-width: 0;
  overflow: auto hidden;
}

.date-pill {
  flex: 0 0 auto;
  padding: 8px 12px;
  border-radius: 999px;
  color: var(--ink-soft);
  background: rgba(248, 240, 229, 0.9);
}

.date-pill--active {
  color: white;
  background: var(--accent);
}

.summary-copy {
  margin: 0;
  font-size: 13px;
  line-height: 1.7;
  color: var(--ink-main);
}

.sector-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.sector-tag {
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  color: var(--accent);
  background: var(--accent-soft);
}

@media (max-width: 1160px) {
  .sidebar {
    grid-template-rows: auto auto auto;
  }
}
</style>
