/**
 * 收藏夹
 */
const api = require('../../utils/api');

Page({
  data: {
    favorites: [],
    loading: true,
    loadStatus: 'loading'
  },

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

  async loadFavorites() {
    this.setData({ loading: true });
    try {
      const list = await api.getFavorites();
      this.setData({
        favorites: Array.isArray(list) ? list : [],
        loadStatus: list && list.length > 10 ? 'nomore' : 'nomore'
      });
    } catch (err) {
      console.error('收藏加载失败:', err);
      this.setData({ loadStatus: 'error' });
    } finally {
      this.setData({ loading: false });
    }
  },

  goHome() {
    wx.switchTab({ url: '/pages/index/index' });
  }
});
