import { defineStore } from 'pinia'
import { getTagList } from '@/api'
import type { TagItemDto } from '@/api/tag/types'
import { createCachedFetcher } from './helpers'
/**
 * 关于标签的store
 */
export const useTagsStore = defineStore('tags', () => {
  // 文化关键词标签
  const tagList = ref<TagItemDto[]>([])

  // 关联场景相关的标签
  const relatedScenariosTagList = ref<TagItemDto[]>([])

  // 年度主推关键词标签
  const yearRecommendTagList = ref<TagItemDto[]>([])

  const fetchAllTagList = createCachedFetcher(getTagList, (data) => {
    tagList.value = data.filter((i) => i.type === 'culture')
    relatedScenariosTagList.value = data.filter((i) => i.type === 'related_scenarios')
    yearRecommendTagList.value = data.filter((i) => i.type === 'year_recommend')
  })
  // 手动调用一次
  fetchAllTagList()

  return { tagList, fetchAllTagList, relatedScenariosTagList, yearRecommendTagList }
})
