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

export const useMemberLevelsStore = defineStore('', () => {
  //   const memberLevels = ref([])
  //   const fetchMemberLevels = async () => {
  const { data: memberLevels, run: fetchMemberLevels } = useRequest(
    () => getAppMemberLevelConfigs(),
    { initialData: [] },
  )
  const memberLevelsById = (id: number) => memberLevels.value.find((item) => item.memberLevel === id)
  const getMemberLevelLogo = (id: number) => memberLevelsById(id)?.logo
  // 获取头像框
  const getMemberAvatarFrame = (id: number) => memberLevelsById(id)?.avatar
  fetchMemberLevels().then()
  return {
    memberLevels,
    fetchMemberLevels,
    memberLevelsById,
    getMemberLevelLogo,
    getMemberAvatarFrame,
  }
})
