import { watch } from 'vue'
import { useDataTable } from '@/hooks/datatable'
import { useFavoriteStore } from '@/stores'

export function useFavorite() {
    const { getFavoriteList, $toRefs } = useFavoriteStore()
    const { loading, favoriteList } = $toRefs()
    const { dataList, total, pageIndex, pageSize, filters } = useDataTable<Ermcp.MyFavoriteRsp>({ localPagination: true })

    watch(favoriteList, (data) => {
        total.value = data.length
        dataList.value = data
    }, {
        immediate: true
    })

    return {
        loading,
        dataList,
        filters,
        total,
        pageIndex,
        pageSize,
        getFavoriteList,
    }
}