import dynamic from 'next/dynamic'; import { Icon, Text, Popover, Tooltip, PopoverArrow, PopoverContent, PopoverTrigger, } from '@chakra-ui/react'; import { MdLastPage } from '@meronex/icons/md'; import dayjs from 'dayjs'; import relativeTimePlugin from 'dayjs/plugin/relativeTime'; import utcPlugin from 'dayjs/plugin/utc'; import { useConfig, useColorValue } from '~/context'; import { If } from '~/components'; import type { TAge, TActive, TWeight, TASPath, TMonoField, TRPKIState, TCommunities, } from './types'; dayjs.extend(relativeTimePlugin); dayjs.extend(utcPlugin); const Check = dynamic(() => import('@meronex/icons/fa').then(i => i.FaCheckCircle)); const More = dynamic(() => import('@meronex/icons/cg').then(i => i.CgMoreO)); const NotAllowed = dynamic(() => import('@meronex/icons/md').then(i => i.MdNotInterested), ); const Question = dynamic(() => import('@meronex/icons/bs').then(i => i.BsQuestionCircleFill), ); const Warning = dynamic(() => import('@meronex/icons/bi').then(i => i.BisError)); const ChevronRight = dynamic(() => import('@meronex/icons/fa').then(i => i.FaChevronRight), ); export const MonoField = (props: TMonoField) => { const { v, ...rest } = props; return ( {v} ); }; export const Active = (props: TActive) => { const { isActive } = props; const color = useColorValue(['gray.500', 'green.500'], ['whiteAlpha.300', 'blackAlpha.500']); return ( <> ); }; export const Age = (props: TAge) => { const { inSeconds, ...rest } = props; const now = dayjs.utc(); const then = now.subtract(inSeconds, 'second'); return ( {now.to(then, true)} ); }; export const Weight = (props: TWeight) => { const { weight, winningWeight, ...rest } = props; const fixMeText = winningWeight === 'low' ? 'Lower Weight is Preferred' : 'Higher Weight is Preferred'; return ( {weight} ); }; export const ASPath = (props: TASPath) => { const { path, active } = props; const color = useColorValue( ['blackAlpha.500', 'blackAlpha.500'], ['blackAlpha.500', 'whiteAlpha.300'], ); if (path.length === 0) { return ; } let paths = [] as JSX.Element[]; path.map((asn, i) => { const asnStr = String(asn); i !== 0 && paths.push(); paths.push( {asnStr} , ); }); return <>{paths}; }; export const Communities = (props: TCommunities) => { const { communities } = props; const color = useColorValue('black', 'white'); return ( <> {communities.join('\n')} ); }; export const RPKIState = (props: TRPKIState) => { const { state, active } = props; const { web } = useConfig(); const color = useColorValue( [ ['red.400', 'green.500', 'yellow.400', 'gray.500'], ['red.500', 'green.500', 'yellow.500', 'gray.600'], ], [ ['red.300', 'green.300', 'yellow.300', 'gray.300'], ['red.500', 'green.600', 'yellow.500', 'gray.800'], ], ); const icon = [NotAllowed, Check, Warning, Question]; const text = [ web.text.rpki_invalid, web.text.rpki_valid, web.text.rpki_unknown, web.text.rpki_unverified, ]; return ( ); };