import React from 'react'
import { useRouter } from 'next/router'
import { useTranslation } from 'next-i18next'
import Button from '~components/common/Button'
import {
Hovercard,
HovercardContent,
HovercardTrigger,
} from '~components/common/Hovercard'
import HovercardHeader from '~components/HovercardHeader'
import {
overMastery,
aetherialMastery,
permanentMastery,
} from '~data/overMastery'
import { ExtendedMastery } from '~types'
import styles from './index.module.scss'
interface Props {
gridCharacter: GridCharacter
children: React.ReactNode
onTriggerClick: () => void
}
const CharacterHovercard = (props: Props) => {
const router = useRouter()
const { t } = useTranslation('common')
const locale =
router.locale && ['en', 'ja'].includes(router.locale) ? router.locale : 'en'
const tintElement = props.gridCharacter.object.element.slug
function goTo() {
const urlSafeName = props.gridCharacter.object.name.en.replaceAll(' ', '_')
const url = `https://gbf.wiki/${urlSafeName}`
window.open(url, '_blank')
}
function masteryElement(dictionary: ItemSkill[], mastery: ExtendedMastery) {
const canonicalMastery = dictionary.find(
(item) => item.id === mastery.modifier
)
if (canonicalMastery) {
return (
{canonicalMastery.name[locale]}
{`+${mastery.strength}${canonicalMastery.suffix}`}
)
}
}
const overMasterySection = () => {
if (props.gridCharacter && props.gridCharacter.mastery.overMastery) {
return (
{t('modals.characters.subtitles.ring')}
{[...Array(4)].map((e, i) => {
const ringIndex = i + 1
const ringStat: ExtendedMastery =
props.gridCharacter.mastery.overMastery[i]
if (ringStat && ringStat.modifier && ringStat.modifier > 0) {
if (ringIndex === 1 || ringIndex === 2) {
return masteryElement(overMastery.a, ringStat)
} else if (ringIndex === 3) {
return masteryElement(overMastery.b, ringStat)
} else {
return masteryElement(overMastery.c, ringStat)
}
}
})}
)
}
}
const aetherialMasterySection = () => {
if (
props.gridCharacter &&
props.gridCharacter.mastery.aetherialMastery &&
props.gridCharacter.mastery.aetherialMastery.modifier > 0
) {
return (
{t('modals.characters.subtitles.earring')}
{masteryElement(
aetherialMastery,
props.gridCharacter.mastery.aetherialMastery
)}
)
}
}
const permanentMasterySection = () => {
if (props.gridCharacter && props.gridCharacter.mastery.perpetuity) {
return (
{t('modals.characters.subtitles.permanent')}
{[...Array(4)].map((e, i) => {
return masteryElement(permanentMastery, {
modifier: i + 1,
strength: permanentMastery[i].maxValue,
})
})}
)
}
}
const awakeningSection = () => {
const gridAwakening = props.gridCharacter.mastery.awakening
if (gridAwakening) {
return (
{t('modals.characters.subtitles.awakening')}
{gridAwakening.type.slug !== 'character-balanced' && (
![{gridAwakening.type.name[locale]}]({`${process.env.NEXT_PUBLIC_SIERO_IMG_URL}/awakening/${gridAwakening.type.slug}.jpg`})
)}
{`${gridAwakening.type.name[locale]}`}
{`Lv${gridAwakening.level}`}
)
}
}
const wikiButton = (
)
return (
{props.children}
{wikiButton}
{awakeningSection()}
{overMasterySection()}
{aetherialMasterySection()}
{permanentMasterySection()}
)
}
export default CharacterHovercard