import { useState } from 'react';
type TimecodeInputFormatOptions,
type TimecodeInputParseOptions,
} from '@techsquidtv/canvas-timeline-react/timecode-input';
import { fromSeconds, type RationalTime } from '@techsquidtv/canvas-timeline-utils';
{ value: 'seconds', label: 'Seconds', formatOptions: { format: 'seconds' } },
formatOptions: { format: 'frames', frameRate: 24 },
parseOptions: { frameRate: 24 },
formatOptions: TimecodeInputFormatOptions;
parseOptions?: TimecodeInputParseOptions;
const sequenceRate = 24000;
const initialSeconds = 3723.04;
function ClipStartInput({
onApply: (time: RationalTime) => void;
const [formatValue, setFormatValue] = useState('seconds');
const [text, setText] = useState(() =>
formatTimecodeInput(initialSeconds, { format: 'seconds' })
formatOptions.find((option) => option.value === formatValue) ?? formatOptions[0];
const parsedSeconds = parseTimecodeInput(text, selectedFormat.parseOptions);
function handleFormatChange(nextFormatValue: string) {
const nextFormat = formatOptions.find((option) => option.value === nextFormatValue);
const nextSeconds = parseTimecodeInput(text, selectedFormat.parseOptions);
setFormatValue(nextFormat.value);
if (nextSeconds !== null) {
setText(formatTimecodeInput(nextSeconds, nextFormat.formatOptions));
if (parsedSeconds !== null) {
onApply(fromSeconds(parsedSeconds, sequenceRate));
setText(formatTimecodeInput(parsedSeconds, selectedFormat.formatOptions));
invalid={parsedSeconds === null}
aria-label="Timecode format"
onChange={(event) => handleFormatChange(event.currentTarget.value)}
{formatOptions.map((option) => (
<option key={option.value} value={option.value}>
: `${option.label} (${formatTimecodeInput(parsedSeconds, {
<button disabled={parsedSeconds === null} type="submit">