"use client" import { useEffect, useMemo } from "react"; import SelectCustomText from "../select/customSelectText"; import { calcMonsterStats, getLocaleName, replaceByParam } from "@/helper"; import useLocaleStore from "@/stores/localeStore"; import useUserDataStore from "@/stores/userDataStore";; import Image from "next/image"; import { useTranslations } from "next-intl"; import { MonsterStore } from "@/types"; import useDetailDataStore from "@/stores/detailDataStore"; export default function PeakBar() { const { locale } = useLocaleStore() const { peak_config, setPeakConfig } = useUserDataStore() const { mapMonster, mapPeak, damageType, eliteConfig, hardLevelConfig } = useDetailDataStore() const transI18n = useTranslations("DataPage") const listFloor = useMemo(() => { const peak = mapPeak?.[peak_config?.event_id?.toString()] if (!peak) return [] return [...peak.PreLevel, peak.BossLevel].filter(it => it != null) }, [peak_config, mapPeak]) const eventSelected = useMemo(() => { return mapPeak?.[peak_config?.event_id?.toString()] }, [peak_config, mapPeak]) const bossConfig = useMemo(() => { return mapPeak?.[peak_config?.event_id?.toString()]?.BossConfig; }, [peak_config, mapPeak]) const challengeSelected = useMemo(() => { const challenge = structuredClone(listFloor?.find((peak) => peak?.ID === peak_config.challenge_id)) if ( challenge && challenge.ID === mapPeak?.[peak_config?.event_id?.toString()]?.BossLevel?.ID && bossConfig && peak_config?.boss_mode === "Hard" ) { return bossConfig } return challenge }, [peak_config, listFloor, mapPeak, bossConfig]) useEffect(() => { if (!challengeSelected) return if (peak_config.event_id !== 0 && peak_config.challenge_id !== 0 && challengeSelected) { const newBattleConfig = structuredClone(peak_config) newBattleConfig.cycle_count = 6 newBattleConfig.blessings = [] for (const value of challengeSelected.MazeBuff) { newBattleConfig.blessings.push({ id: 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.EventList[0].ID for (const wave of challengeSelected.EventList[0].MonsterList) { if (!wave) continue const newWave: MonsterStore[] = [] for (const value of Object.values(wave)) { if (!value) continue newWave.push({ monster_id: value, level: challengeSelected.EventList[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, peak_config.boss_mode, mapPeak, ]) if (!mapPeak) return null return (