import { ChevronRight } from 'lucide-react' import Link from 'next/link' import { useMemo } from 'react' import { HoverCard, HoverCardContent, HoverCardTrigger } from 'ui' import { formatUsage } from '../helpers' import { Metric } from './BillingBreakdown.constants' import { ComputeUsageMetric, PricingMetric } from '@/data/analytics/org-daily-stats-query' import type { OrgUsageResponse } from '@/data/usage/org-usage-query' import { DOCS_URL } from '@/lib/constants' import { formatCurrency } from '@/lib/helpers' export interface ComputeMetricProps { slug?: string metric: Metric usage: OrgUsageResponse relativeToSubscription: boolean className?: string } export const ComputeMetric = ({ slug, metric, usage, relativeToSubscription, className, }: ComputeMetricProps) => { const usageMeta = usage.usages.find((x) => x.metric === metric.key) const usageLabel = useMemo(() => { if (usageMeta?.pricing_free_units) { return `${usageMeta?.usage?.toLocaleString() ?? 0} / ${ usageMeta?.pricing_free_units ?? 0 } hours` } else { return `${usageMeta?.usage?.toLocaleString() ?? 0} hours` } }, [usageMeta]) const sortedProjectAllocations = useMemo(() => { if (!usageMeta || !usageMeta.project_allocations) return [] return usageMeta.project_allocations.sort((a, b) => b.usage - a.usage) }, [usageMeta]) return (

{metric.name}

{usageLabel}  {relativeToSubscription && usageMeta?.cost && usageMeta.cost > 0 ? ( ({formatCurrency(usageMeta?.cost)}) ) : null}

{usageMeta?.unit_price_desc}

{usageMeta?.metric === ComputeUsageMetric.COMPUTE_HOURS_BRANCH ? (

Each Preview branch is a separate environment with all Briven services (Database, Auth, Storage, etc.).{' '} Read more

) : (

Every project is a dedicated server and database. For every hour your project is active, it incurs compute costs based on the compute size of your project. Paused projects do not incur compute costs.{' '} Read more

)}
{usageMeta && sortedProjectAllocations.length > 0 && ( {sortedProjectAllocations.map((allocation) => ( ))}
Project Usage
{allocation.name} {formatUsage(usageMeta.metric as PricingMetric, allocation)}
Total (Hours) {formatUsage(usageMeta.metric as PricingMetric, { usage: usageMeta.usage_original, })}
)}
) }