import { ChevronDown } from 'lucide-react' import { Button, DropdownMenu, DropdownMenuContent, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuTrigger, Tooltip, TooltipContent, TooltipTrigger, } from 'ui' import { CHART_INTERVALS } from './logs.utils' import { InlineLink } from '@/components/ui/InlineLink' import { useCheckEntitlements } from '@/hooks/misc/useCheckEntitlements' function getDaysRequired(startValue: number, startUnit: string): number { if (startUnit === 'day') return startValue if (startUnit === 'hour') return startValue / 24 return 0 } interface ChartIntervalDropdownProps { value: string onChange: (value: string) => void organizationSlug?: string dropdownAlign?: 'start' | 'center' | 'end' tooltipSide?: 'left' | 'right' | 'top' | 'bottom' } export const ChartIntervalDropdown = ({ value, onChange, organizationSlug, dropdownAlign = 'start', tooltipSide = 'right', }: ChartIntervalDropdownProps) => { const selectedInterval = CHART_INTERVALS.find((i) => i.key === value) || CHART_INTERVALS[1] const { getEntitlementMax } = useCheckEntitlements('log.retention_days') const retentionDays = getEntitlementMax() return ( {CHART_INTERVALS.map((i) => { const daysRequired = getDaysRequired(i.startValue, i.startUnit) const disabled = retentionDays !== undefined && daysRequired > retentionDays if (disabled) { return ( {i.label}

Your plan only includes up to {retentionDays} day {retentionDays !== undefined && retentionDays > 1 ? 's' : ''} of log retention

{organizationSlug ? ( <> Upgrade your plan {' '} to increase log retention and view statistics for the{' '} {i.label.toLowerCase()} ) : ( `Upgrade your plan to increase log retention and view statistics for the ${i.label.toLowerCase()}` )}

) } else { return ( {i.label} ) } })}
) }