import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
import { forwardRef } from 'react';
import { useI18n, useTestIds } from '../../../../hooks';
import FormField from '../../../FormField';
import { getDurationInputTestIds } from '../../DateTime.test-ids';
import { withTestIds } from '../../../../utils';
import useAutoFocusNextInput from '../useAutoFocusNextInput';
import Time from './Time';
import NumberUnit from './NumberUnit';
import { Format } from './DurationInput.types';
const DurationInput = forwardRef(function DurationInput(props, ref) {
    const { testId, id, label, labelHidden, required, status, disabled, onChange, format = Format.Seconds, onSelect, additionalInfo, ...restProps } = props;
    const testIds = useTestIds(testId, getDurationInputTestIds);
    const t = useI18n();
    // Refs are actually handled in Time component rendered below.
    const { description, descriptionID } = useAutoFocusNextInput([]);
    const Comp = format === Format.Formatted ? (_jsx(Time, { testId: testId, status: status, disabled: disabled, onChange: onChange, ...restProps })) : (_jsx(NumberUnit, { testId: testId, format: format, status: status, disabled: disabled, onChange: onChange, onSelect: onSelect, ...restProps }));
    return label ? (_jsxs(_Fragment, { children: [_jsx(FormField, { as: 'fieldset', labelAs: 'legend', ...(format === Format.Formatted ? { info: t('time_format_info') } : undefined), status: status, testId: testIds, label: label, labelHidden: labelHidden, id: id, required: required, disabled: disabled, ref: ref, additionalInfo: additionalInfo, "aria-describedby": format === Format.Formatted ? descriptionID : undefined, children: Comp }), format === Format.Formatted ? description : null] })) : (Comp);
});
export default withTestIds(DurationInput, getDurationInputTestIds);
//# sourceMappingURL=DurationInput.js.map