import { useContext } from "react";
import { cl } from "../../utils/helpers/index.js";
import { CheckboxGroupContext } from "../checkbox/CheckboxGroup.context.js";
import { RadioGroupContext } from "../radio/RadioGroup.context.js";
import { containsReadMore, useFormField } from "../useFormField.js";
/**
 * Handles props for Fieldset in context with parent Fieldset.
 */
export const useFieldset = (props, legendId) => {
    const formField = useFormField(props, "fieldset");
    const checkboxGroupContext = useContext(CheckboxGroupContext);
    const radioGroupContext = useContext(RadioGroupContext);
    return Object.assign(Object.assign({}, formField), { readOnlyIconNeedsTitle: checkboxGroupContext || radioGroupContext, inputProps: Object.assign(Object.assign({}, (checkboxGroupContext || radioGroupContext
            ? { "aria-invalid": formField.inputProps["aria-invalid"] }
            : {})), { 
            // Having both legend and description in labelledby seems to work best, ref. https://mortentollefsen.no/demo/radio-description.html
            "aria-labelledby": props["aria-labelledby"] ||
                cl(legendId, {
                    [formField.inputDescriptionId]: props.description && !containsReadMore(props.description),
                }) }) });
};
//# sourceMappingURL=useFieldset.js.map