Page({
  data: {
    bookmarks: []
  },

  onShow() {
    this.loadBookmarks();
  },

  loadBookmarks() {
    const bookmarks = wx.getStorageSync('lunar-bookmarks') || [];
    this.setData({ bookmarks });
  },

  removeBookmark(e) {
    const date = e.currentTarget.dataset.date;
    const bookmarks = this.data.bookmarks.filter(b => b.date !== date);
    wx.setStorageSync('lunar-bookmarks', bookmarks);
    this.setData({ bookmarks });
    wx.showToast({ title: '已删除', icon: 'success' });
  },

  // 点击收藏项跳转到当日详情
  openDetail(e) {
    const date = e.currentTarget.dataset.date;
    wx.navigateTo({ url: `/pages/day-detail/day-detail?date=${date}` });
  }
});
