import { useState } from 'react' import { useTranslation } from 'react-i18next' import { DESKTOP_RESOLUTION_PRESETS, clampDesktopResolution, formatResolution, matchPresetId, type DesktopResolution, } from '../../utils/desktopResolution' interface DesktopResolutionPickerProps { width: number height: number onChange: (next: DesktopResolution) => void ns?: 'desktop' | 'sessions' resolutionLabelKey?: string widthLabelKey?: string heightLabelKey?: string customKey?: string } export default function DesktopResolutionPicker({ width, height, onChange, ns = 'desktop', resolutionLabelKey = ns === 'desktop' ? 'connect.resolution' : 'dialog.resolution', widthLabelKey = ns === 'desktop' ? 'connect.width' : 'dialog.width', heightLabelKey = ns === 'desktop' ? 'connect.height' : 'dialog.height', customKey = ns === 'desktop' ? 'connect.resolutionCustom' : 'dialog.resolutionCustom', }: DesktopResolutionPickerProps) { const { t } = useTranslation(ns) const current = clampDesktopResolution(width, height) const matched = matchPresetId(current) const [forceCustom, setForceCustom] = useState(false) const selected = forceCustom || matched === 'custom' ? 'custom' : matched const showCustom = selected === 'custom' return (
{showCustom && (
{ setForceCustom(true) onChange(clampDesktopResolution(Number(event.target.value) || current.width, height)) }} className="ui-input font-mono" />
{ setForceCustom(true) onChange(clampDesktopResolution(width, Number(event.target.value) || current.height)) }} className="ui-input font-mono" />
)}
) }