import type { Signal1D } from '@zakodium/nmr-types'; import { useFormContext } from 'react-hook-form'; import { NumberInput2Controller } from '../../../../elements/NumberInput2Controller.js'; import { useTabsController } from '../../../../elements/TabsProvider.js'; import { useEvent } from '../../../../utility/Events.js'; import { useEventFocusInput } from './SignalsContent.js'; interface DeltaInputProps { signal: Signal1D; index: number; } function hasError(errors: any, i: any) { return !!errors?.signals?.[i]; } export function DeltaInput({ signal, index }: DeltaInputProps) { const { control, formState: { errors }, setValue, } = useFormContext(); const isNotValid = hasError(errors, index); const { selectedTabId: signalIndex } = useTabsController(); const { focusSource, setFocusSource } = useEventFocusInput(); useEvent({ onClick: ({ xPPM, shiftKey }) => { if (index === signalIndex && shiftKey && focusSource === 'delta') { setValue(`signals.${index}.delta`, xPPM); } }, onBrushEnd: (options) => { const { range: [from, to], shiftKey, } = options; if (index === signalIndex && shiftKey && focusSource === 'delta') { const delta = (to - from) / 2 + from; setValue(`signals.${index}.delta`, delta); } }, }); return (