"use client" import Image from "next/image" import { useMemo } from "react" import CharacterCard from "../card/characterCard" import useLocaleStore from "@/stores/localeStore" import { useTranslations } from "next-intl" import useDetailDataStore from "@/stores/detailDataStore" import useCurrentDataStore from '@/stores/currentDataStore'; import { calcRarity, getNameChar } from "@/helper" export default function AvatarBar({ onClose }: { onClose?: () => void }) { const { avatarSearch, mapAvatarElementActive, mapAvatarPathActive, setAvatarSearch, setAvatarSelected, setMapAvatarElementActive, setMapAvatarPathActive, setSkillIDSelected, } = useCurrentDataStore() const { mapAvatar, baseType, damageType } = useDetailDataStore() const transI18n = useTranslations("DataPage") const {locale} = useLocaleStore() const listAvatar = useMemo(() => { if (!mapAvatar || !locale || !transI18n) return [] let list = Object.values(mapAvatar) if (avatarSearch) { list = list.filter(item => getNameChar(locale, transI18n, item) .toLowerCase() .includes(avatarSearch.toLowerCase()) ) } const allElementFalse = !Object.values(mapAvatarElementActive).some(v => v) const allPathFalse = !Object.values(mapAvatarPathActive).some(v => v) list = list.filter(item => (allElementFalse || mapAvatarElementActive[item.DamageType]) && (allPathFalse || mapAvatarPathActive[item.BaseType]) ) list.sort((a, b) => { const r = calcRarity(b.Rarity) - calcRarity(a.Rarity) if (r !== 0) return r return a.ID - b.ID }) return list }, [mapAvatar, mapAvatarElementActive, mapAvatarPathActive, avatarSearch, locale, transI18n]) return (