const { SOLAR_TERMS, SOLAR_TERM_DATES } = require('../../utils/core/index.js');

Page({
  data: {
    year: new Date().getFullYear(),
    terms: []
  },

  onLoad() {
    this.loadTerms();
  },

  loadTerms() {
    const { year } = this.data;
    const today = new Date();
    const terms = [];

    for (let m = 0; m < 12; m++) {
      for (let t = 0; t < 2; t++) {
        const termIndex = m * 2 + t;
        const day = SOLAR_TERM_DATES[m][t];
        const dateStr = `${year}-${String(m + 1).padStart(2, '0')}-${String(day).padStart(2, '0')}`;
        const termDate = new Date(year, m, day);
        terms.push({
          name: SOLAR_TERMS[termIndex],
          date: dateStr,
          isPast: termDate < today
        });
      }
    }

    // 按日期排序
    terms.sort((a, b) => new Date(a.date) - new Date(b.date));
    this.setData({ terms });
  }
});
