"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useFieldset = void 0;
const react_1 = require("react");
const helpers_1 = require("../../utils/helpers");
const CheckboxGroup_context_1 = require("../checkbox/CheckboxGroup.context");
const RadioGroup_context_1 = require("../radio/RadioGroup.context");
const useFormField_1 = require("../useFormField");
/**
 * Handles props for Fieldset in context with parent Fieldset.
 */
const useFieldset = (props, legendId) => {
    const formField = (0, useFormField_1.useFormField)(props, "fieldset");
    const checkboxGroupContext = (0, react_1.useContext)(CheckboxGroup_context_1.CheckboxGroupContext);
    const radioGroupContext = (0, react_1.useContext)(RadioGroup_context_1.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"] ||
                (0, helpers_1.cl)(legendId, {
                    [formField.inputDescriptionId]: props.description && !(0, useFormField_1.containsReadMore)(props.description),
                }) }) });
};
exports.useFieldset = useFieldset;
//# sourceMappingURL=useFieldset.js.map