type FavoritesTab = 'favorites' | 'downloads';

Page({
    data: {
        activeTab: 'favorites' as FavoritesTab,
        favoriteList: [] as unknown[],
        downloadList: [] as unknown[],
    },

    onShow() {
        const tab = wx.getStorageSync('favorites_active_tab') as FavoritesTab;
        if (tab === 'downloads' || tab === 'favorites') {
            this.setData({ activeTab: tab });
            wx.removeStorageSync('favorites_active_tab');
        }
    },

    onTabSwitch(e: WechatMiniprogram.TouchEvent) {
        const tab = e.currentTarget.dataset.tab as FavoritesTab;
        if (tab !== 'favorites' && tab !== 'downloads') return;
        this.setData({ activeTab: tab });
    },

    onDiscoverTap() {
        wx.switchTab({ url: '/pages/home/home' });
    },
});
