import React, { memo } from 'react' import { Box } from '@a11ywatch/ui' import type { User } from '@app/types' import { TextSkeleton } from '@app/components/placeholders' import { Link } from '@app/components/stateless/typo/link' import { getUsageLimitsMs } from '@a11ywatch/website-source-builder' const APIInfoBlockComponent = ({ user, loading, hideHeader, }: { user: User loading?: boolean hideHeader?: boolean }) => { const maxUsage = getUsageLimitsMs(user?.role ?? 0) const baseUsage = user?.scanInfo?.totalUptime ? (Number(user.scanInfo.totalUptime) / maxUsage) * 100 : 0 const usageAnchorDate = user?.usageAnchorDate const anchorDate = usageAnchorDate ? new Date(Number(usageAnchorDate)) : new Date() const nextMonth = anchorDate.getMonth() + 1 anchorDate.setMonth(nextMonth > 12 ? 0 : nextMonth) return ( {hideHeader ? null : (

API Reference

)} {!user && loading ? ( ) : !user ? (

Login {' '} to see your API limits and test requests using your account.

) : (
{/*

Plan allows up to {}

*/}

Usage used {`${Math.min(baseUsage, 100).toFixed(0)}%`}

{usageAnchorDate ? (

Your limit resets {anchorDate.toDateString()}.

) : null}
)}
) } export const APIInfoBlock = memo(APIInfoBlockComponent)