// 共用 · 本周视图 —— 每天频道性质 + 几件关键事（一屏看全、不铺钟点）
function WeekView({ weekIndex, onPickDay, onPickToday }) {
  const wk = window.WEEKS[weekIndex] || [];
  const days = wk.filter(Boolean);
  const cc = (id) => (window.CATS[id] || {}).color || '#9DB4BF';

  return (
    <div style={wStyles.root}>
      <div style={wStyles.head}>
        <div>
          <div style={wStyles.title}>本周</div>
          <div style={wStyles.sub}>{days[0].d}–{days[days.length-1].d} 日 · 看每天什么性质、大概做啥</div>
        </div>
      </div>

      <div style={wStyles.list} className="noscroll">
        {days.map(day => {
          const ch = window.CHANNELS[day.channel];
          const isToday = day.d === window.TODAY;
          return (
            <div key={day.d}
              onClick={() => (isToday ? onPickToday() : onPickDay(day.d))}
              style={{
                ...wStyles.row,
                background: `linear-gradient(100deg, ${ch.tint}cc, rgba(255,255,255,0.5))`,
                ...(isToday ? wStyles.rowToday : {}),
              }}>
              <div style={wStyles.left}>
                <div style={{ ...wStyles.dnum, color: isToday ? '#fff' : 'var(--ink)', background: isToday ? 'linear-gradient(135deg,#6FCBB2,#6FB4FF)' : 'transparent' }}>
                  {day.d}
                </div>
                <div style={wStyles.dwk}>周{day.weekday}</div>
                <div style={{ ...wStyles.chPill, color: 'var(--ink)' }}>
                  <span style={{ ...wStyles.chDot, background: ch.glow }} />{ch.name}
                </div>
              </div>
              <div style={wStyles.right}>
                {day.rest ? (
                  <div style={wStyles.restNote}>留白 · 慢下来</div>
                ) : (
                  <div style={wStyles.chips}>
                    {day.key.map((it, i) => (
                      <span key={i} style={{ ...wStyles.chip, borderColor: cc(it.cat) + '55' }}>
                        <span style={{ ...wStyles.chipDot, background: cc(it.cat) }} />
                        {it.t}
                        {it.type === 'event' && <span style={wStyles.pin}>·约</span>}
                      </span>
                    ))}
                  </div>
                )}
              </div>
              {isToday && <div style={wStyles.todayFlag}>今天</div>}
            </div>
          );
        })}
      </div>
      <div style={wStyles.foot}>点任意一天 · 摊开成「日」</div>
    </div>
  );
}

const wStyles = {
  root: { flex: 1, minHeight: 0, display: 'flex', flexDirection: 'column', padding: '14px 16px 6px' },
  head: { padding: '4px 8px 12px' },
  title: { fontSize: 28, fontWeight: 700, letterSpacing: '-0.5px' },
  sub: { fontSize: 13, color: 'var(--ink-soft)', marginTop: 2, fontWeight: 500 },
  list: { flex: 1, minHeight: 0, overflowY: 'auto', display: 'flex', flexDirection: 'column', gap: 9, paddingBottom: 4 },
  row: { position: 'relative', borderRadius: 22, padding: '13px 15px', display: 'flex', alignItems: 'center', gap: 12, border: '1px solid rgba(255,255,255,0.6)', boxShadow: '0 8px 22px -16px rgba(54,84,99,.45)', cursor: 'pointer', transition: 'transform .2s ease', minHeight: 64 },
  rowToday: { boxShadow: '0 14px 30px -14px rgba(111,180,178,.6)', border: '1px solid rgba(255,255,255,0.9)' },
  left: { display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 3, width: 52, flexShrink: 0 },
  dnum: { fontSize: 22, fontWeight: 700, width: 38, height: 38, borderRadius: 12, display: 'flex', alignItems: 'center', justifyContent: 'center', lineHeight: 1 },
  dwk: { fontSize: 11, color: 'var(--ink-soft)', fontWeight: 600 },
  chPill: { fontSize: 11, fontWeight: 700, display: 'flex', alignItems: 'center', gap: 4, marginTop: 1 },
  chDot: { width: 7, height: 7, borderRadius: 999 },
  right: { flex: 1, minWidth: 0 },
  chips: { display: 'flex', flexWrap: 'wrap', gap: 6 },
  chip: { fontSize: 12.5, fontWeight: 600, color: 'var(--ink)', background: 'rgba(255,255,255,0.72)', borderRadius: 999, padding: '5px 11px', border: '1px solid', display: 'inline-flex', alignItems: 'center', gap: 5, whiteSpace: 'nowrap' },
  chipDot: { width: 7, height: 7, borderRadius: 999 },
  pin: { color: 'var(--ink-faint)', fontWeight: 600, marginLeft: 1 },
  restNote: { fontSize: 14, color: 'var(--ink-soft)', fontWeight: 600, fontStyle: 'italic', opacity: .8 },
  todayFlag: { position: 'absolute', top: -8, right: 14, background: 'linear-gradient(120deg,#6FCBB2,#6FB4FF)', color: '#fff', fontSize: 10, fontWeight: 700, padding: '2px 9px', borderRadius: 999, letterSpacing: '.5px' },
  foot: { textAlign: 'center', fontSize: 12, color: 'var(--ink-faint)', padding: '8px 0 4px', fontWeight: 500 },
};

window.WeekView = WeekView;
