import { getAppMemberLevelConfigs } from '../core/libs/requests'
import { defineStore } from 'pinia'

export const useMemberLevelsStore = defineStore('member-levels', () => {
  //   const memberLevels = ref([])
  //   const fetchMemberLevels = async () => {
  const { data: memberLevels, run: fetchMemberLevels } = useRequest(
    () => getAppMemberLevelConfigs(),
    { initialData: [] },
  )
  const memberLevelsById = (id: number) => memberLevels.value.find((item) => item.id === id)
  const getMemberLevelLogo = (id: number) => memberLevelsById(id)?.logo
  fetchMemberLevels().then()
  return {
    memberLevels,
    fetchMemberLevels,
    memberLevelsById,
    getMemberLevelLogo,
  }
})
