"use client" import { useEffect, useMemo } from "react"; import SelectCustomText from "../select/customSelectText"; import useEventStore from "@/stores/eventStore"; import { getLocaleName, replaceByParam } from "@/helper"; import useLocaleStore from "@/stores/localeStore"; import useUserDataStore from "@/stores/userDataStore"; import useMonsterStore from "@/stores/monsterStore"; import Image from "next/image"; import cloneDeep from 'lodash/cloneDeep' import { useTranslations } from "next-intl"; import { MonsterStore } from "@/types"; export default function PeakBar() { const { PEAKEvent, mapPEAKInfo } = useEventStore() const { listMonster } = useMonsterStore() const { locale } = useLocaleStore() const { peak_config, setPeakConfig } = useUserDataStore() const transI18n = useTranslations("DataPage") const listFloor = useMemo(() => { if (!mapPEAKInfo?.[peak_config?.event_id?.toString()]) return [] return [ ...mapPEAKInfo[peak_config?.event_id?.toString()]?.PreLevel, mapPEAKInfo[peak_config?.event_id?.toString()]?.BossLevel, ] }, [peak_config, mapPEAKInfo]) const eventSelected = useMemo(() => { return mapPEAKInfo?.[peak_config?.event_id?.toString()] }, [peak_config, mapPEAKInfo]) const bossConfig = useMemo(() => { return mapPEAKInfo?.[peak_config?.event_id?.toString()]?.BossConfig; }, [peak_config, mapPEAKInfo]) const challengeSelected = useMemo(() => { const challenge = cloneDeep(listFloor.find((peak) => peak.Id === peak_config.challenge_id)) if ( challenge && challenge.Id === mapPEAKInfo?.[peak_config?.event_id?.toString()]?.BossLevel?.Id && bossConfig && peak_config?.boss_mode === "Hard" ) { challenge.Name = bossConfig.HardName challenge.EventIDList = bossConfig.EventIDList challenge.InfiniteList = bossConfig.InfiniteList challenge.TagList = bossConfig.TagList } return challenge }, [peak_config, listFloor, mapPEAKInfo, bossConfig]) useEffect(() => { if (!challengeSelected) return if (peak_config.event_id !== 0 && peak_config.challenge_id !== 0 && challengeSelected) { const newBattleConfig = cloneDeep(peak_config) newBattleConfig.cycle_count = 6 newBattleConfig.blessings = [] for (const value of challengeSelected.TagList) { newBattleConfig.blessings.push({ id: Number(value.Id), level: 1 }) } if (peak_config.buff_id !== 0) { newBattleConfig.blessings.push({ id: peak_config.buff_id, level: 1 }) } newBattleConfig.monsters = [] newBattleConfig.stage_id = challengeSelected.EventIDList[0].StageID for (const wave of challengeSelected.EventIDList[0].MonsterList) { if (!wave) continue const newWave: MonsterStore[] = [] for (const value of Object.values(wave)) { if (!value) continue newWave.push({ monster_id: Number(value), level: challengeSelected.EventIDList[0].Level, amount: 1, }) } newBattleConfig.monsters.push(newWave) } setPeakConfig(newBattleConfig) } // eslint-disable-next-line react-hooks/exhaustive-deps }, [ peak_config.event_id, peak_config.challenge_id, peak_config.buff_id, mapPEAKInfo, ]) if (!PEAKEvent) return null return (
{/* Title Card */}
({ id: peak.id, name: `${getLocaleName(locale, peak)} (${peak.id}) `, }))} excludeSet={[]} selectedCustomSet={peak_config.event_id.toString()} placeholder={transI18n("selectPEAKEvent")} setSelectedCustomSet={(id) => setPeakConfig({ ...peak_config, event_id: Number(id), challenge_id: 0, buff_id: 0 })} />
{/* Settings */}
{eventSelected && eventSelected.BossLevel.Id === peak_config.challenge_id && (
)}
{ eventSelected && eventSelected.BossLevel.Id === peak_config.challenge_id && bossConfig && bossConfig.BuffList && (
({ id: buff.Id.toString(), name: buff?.Name || "", description: replaceByParam(buff?.Desc || "", buff?.Param || []), })) : [] } excludeSet={[]} selectedCustomSet={peak_config?.buff_id?.toString()} placeholder={transI18n("selectBuff")} setSelectedCustomSet={(id) => setPeakConfig({ ...peak_config, buff_id: Number(id) })} />
) } {/* Turbulence Buff */}

{transI18n("turbulenceBuff")}

{challengeSelected && challengeSelected?.TagList?.length > 0 ? ( challengeSelected.TagList.map((subOption, index) => (
)) ) : (
{transI18n("noTurbulenceBuff")}
)}
{/* Enemy Waves */} {(peak_config?.challenge_id ?? 0) !== 0 && (

{challengeSelected?.Name}

{challengeSelected && Object.values(challengeSelected.InfiniteList).map((waveValue, waveIndex) => (

{transI18n("wave")} {waveIndex + 1}

{Array.from(new Set(waveValue.MonsterGroupIDList)).map((monsterId, enemyIndex) => (
{listMonster.find((monster) => monster.child.includes(monsterId))?.icon && monster.child.includes(monsterId))?.icon?.split("/")?.pop()?.replace(".png", "")}.webp`} alt="Enemy Icon" width={376} height={512} className="w-full h-full object-cover" />}
Lv. {challengeSelected?.EventIDList[0].Level}
{listMonster .find((monster) => monster.child.includes(monsterId)) ?.weak?.map((icon, iconIndex) => ( {icon} ))}
))}
))}
)}
) }