'use client'; import React from 'react'; import type { DurationValue } from '@documenso/lib/utils/expiry'; import { cn } from '../lib/utils'; import { Input } from './input'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from './select'; export interface DurationSelectorProps { value?: DurationValue; onChange?: (value: DurationValue) => void; disabled?: boolean; className?: string; minAmount?: number; maxAmount?: number; } const TIME_UNITS: Array<{ value: string; label: string; labelPlural: string }> = [ { value: 'minutes', label: 'Minute', labelPlural: 'Minutes' }, { value: 'hours', label: 'Hour', labelPlural: 'Hours' }, { value: 'days', label: 'Day', labelPlural: 'Days' }, { value: 'weeks', label: 'Week', labelPlural: 'Weeks' }, { value: 'months', label: 'Month', labelPlural: 'Months' }, ]; export const DurationSelector = ({ value = { amount: 1, unit: 'days' }, onChange, disabled = false, className, minAmount = 1, maxAmount = 365, }: DurationSelectorProps) => { const handleAmountChange = (event: React.ChangeEvent) => { const amount = parseInt(event.target.value, 10); if (!isNaN(amount) && amount >= minAmount && amount <= maxAmount) { onChange?.({ ...value, amount }); } }; const handleUnitChange = (unit: string) => { onChange?.({ ...value, unit }); }; const getUnitLabel = (unit: string, amount: number) => { const unitConfig = TIME_UNITS.find((u) => u.value === unit); if (!unitConfig) return unit; return amount === 1 ? unitConfig.label : unitConfig.labelPlural; }; return (
); };