var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
import React, { forwardRef, useContext } from "react";
import { useId } from "../../utils-external/index.js";
import { cl } from "../../utils/helpers/index.js";
import { Fieldset } from "../fieldset/index.js";
import { FieldsetContext } from "../fieldset/context.js";
import { RadioGroupContext } from "./RadioGroup.context.js";
/**
 * Form radio group
 * @see [📝 Documentation](https://aksel.nav.no/komponenter/core/radio)
 * @see 🏷️ {@link RadioGroupProps}
 * @example
 * <RadioGroup legend="Får du AAP nå?">
 *    <Radio value="ja">Ja</Radio>
 *    <Radio value="Nei">Nei</Radio>
 * </RadioGroup>
 */
export const RadioGroup = forwardRef((_a, ref) => {
    var _b, _c;
    var { children, className, name, defaultValue, value, onChange = () => { }, required, readOnly } = _a, rest = __rest(_a, ["children", "className", "name", "defaultValue", "value", "onChange", "required", "readOnly"]);
    const fieldset = useContext(FieldsetContext);
    const nameId = useId();
    return (React.createElement(RadioGroupContext.Provider, { value: {
            name: name !== null && name !== void 0 ? name : `radioGroupName-${nameId}`,
            defaultValue,
            value,
            onChange,
            required,
        } },
        React.createElement(Fieldset, Object.assign({ role: "radiogroup" }, rest, { readOnly: readOnly, ref: ref, className: cl(className, "aksel-radio-group", `aksel-radio-group--${(_c = (_b = rest.size) !== null && _b !== void 0 ? _b : fieldset === null || fieldset === void 0 ? void 0 : fieldset.size) !== null && _c !== void 0 ? _c : "medium"}`) }),
            React.createElement("div", { className: "aksel-radio-buttons" }, children))));
});
export default RadioGroup;
//# sourceMappingURL=RadioGroup.js.map