import { BigNumber } from '@ethersproject/bignumber'
import { AutoRow, Column, ExternalLink, Row, RowProps, RowStart, Text } from '@past3lle/components'
import {
SkillDependencyObject,
SkillForgeBalances,
SkillForgeMetadataState,
SkillId,
SkillLockStatus,
SkillMetadata,
SkillRarity,
getLockStatus,
useSkillForgeBalancesReadAtom,
useSkillForgeMetadataMapReadAtom
} from '@past3lle/skillforge-web3'
import { BLACK, OFF_WHITE } from '@past3lle/theme'
import { darken } from 'polished'
import React, { useMemo } from 'react'
import styled, { useTheme } from 'styled-components'
import { SHOP_URL } from '../../../constants'
import { useGetActiveSkill } from '../../../hooks/skills'
import { baseTheme } from '../../../theme/base'
import { RARITY_COLOURS_MAP } from '../../../theme/constants'
import { ThemedButtonExternalLink } from '../../Common/Button'
import { BlackHeader, MonospaceText } from '../../Common/Text'
import { Skillpoint } from '../../Skillpoint'
// import { SkillpointPoint } from '../../Skillpoint/SkillpointPoint'
import { SidePanel } from '../BaseSidePanel'
import { ActiveSkillPanelContainer, SkillRarityLabel, SkillStatusLabel, SkillsRowContainer } from './styleds'
export function ActiveSkillPanel() {
const [metadataMap] = useSkillForgeMetadataMapReadAtom()
const activeSkillState = useGetActiveSkill()
const [balances] = useSkillForgeBalancesReadAtom()
const activeSkill = activeSkillState?.[0]
const setSkillState = activeSkillState?.[1]
const lockStatus = useMemo(() => getLockStatus(activeSkill, balances), [activeSkill, balances])
const isLocked = lockStatus === SkillLockStatus.LOCKED
const isOwned = lockStatus === SkillLockStatus.OWNED
const description = useMemo(
() => _getSkillDescription(activeSkill?.name, lockStatus),
[activeSkill?.name, lockStatus]
)
const { assetsMap, ...customTheme } = useTheme()
const { rarity, deps, cardColour } = useMemo(
() => ({
rarity: activeSkill?.properties.rarity,
deps: activeSkill?.properties.dependencies,
get cardColour() {
return isLocked
? baseTheme.gradients.lockedSkill
: this.rarity
? baseTheme.gradients.unlockedSkill + `${customTheme.rarity[this.rarity].backgroundColor})`
: null
}
}),
[activeSkill?.properties.dependencies, activeSkill?.properties.rarity, customTheme.rarity, isLocked]
)
if (!activeSkill || !rarity || !deps || !cardColour || !setSkillState) return null
return (
setSkillState((state) => ({ ...state, active: [] }))}
onBack={() => setSkillState((state) => ({ ...state, active: state.active.slice(1) }))}
>
{lockStatus}
{rarity?.toLocaleUpperCase()} SKILL
{description}
{isLocked ? 'LOCKED' : isOwned ? 'VIEW IN STORE' : 'UNLOCK'}
{!isOwned && deps.length > 0 && (
REQUIRED TO UNLOCK
)}
{!isLocked && (
View on{' '}
{' '}
OpenSea{' '}
{' '}
)}
{/*
Connect Wallet
*/}
Checkout this{' '}
{' '}
tutorial{' '}
{' '}
to understand how to claim your skillpoint NFT.
)
}
const RequiredDepsContainer = styled(Column)<{ borderRadius?: string; background?: string }>``
interface SkillsRowProps {
deps: SkillDependencyObject[]
metadataMap: SkillForgeMetadataState['metadataMap']
balances: SkillForgeBalances
rowProps?: RowProps
}
function SkillsRow({ balances, deps, metadataMap, rowProps }: SkillsRowProps) {
return (
{/*
// TODO: review - right now disabled as not required in contracts
+
*/}
{deps.flatMap(({ token, id }) => {
const skillId: SkillId = `${token}-${id}`
const skill = metadataMap[skillId]
return (
skill && (
)
)
})}
)
}
function _getSkillDescription(name: string | undefined, lockStatus: SkillLockStatus) {
switch (lockStatus) {
case SkillLockStatus.LOCKED:
return "You can't get this skill yet. Click/view required skill(s) below."
case SkillLockStatus.UNLOCKED:
return `Buy ${
name || 'this skill'
} in the shop and receive a free skill + skillpoint giving you access to exclusive perks.`
case SkillLockStatus.OWNED:
return (
<>
Nice, you already own {name || 'this skill'}.
What now? Head to the shop to get new pieces and earn more skills + skillpoints!
>
)
default:
return 'Skill information missing. Please try again later.'
}
}
function _getLockStatusColour(lockStatus: SkillLockStatus, rarity: SkillRarity) {
switch (lockStatus) {
case SkillLockStatus.LOCKED:
return 'darkred'
case SkillLockStatus.UNLOCKED:
return 'darkgreen'
case SkillLockStatus.OWNED:
return RARITY_COLOURS_MAP[rarity]
}
}
// TODO: this fn should be local to the project using SkillForge Widget
const STORE_URL = process.env.NODE_ENV === 'production' ? SHOP_URL : 'http://localhost:8080'
function _getSkillShopUri(activeSkill: SkillMetadata) {
return `${STORE_URL}/#/SKILLS/${(
activeSkill?.attributes?.handle || activeSkill.name
).toLowerCase()}?referral=FORGE&id=${activeSkill.properties.shopifyId.replace('gid://shopify/Product/', '')}`
}