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 } from "react";
import { Label } from "../typography/index.js";
import { useId } from "../utils-external/index.js";
import { cl } from "../utils/helpers/index.js";
import { ToggleGroupProvider } from "./ToggleGroup.context.js";
import ToggleItem from "./parts/ToggleItem.js";
import { useToggleGroup } from "./useToggleGroup.js";
/**
 * A component that displays a group of toggle buttons.
 *
 * @see [📝 Documentation](https://aksel.nav.no/komponenter/core/toggle-group)
 * @see 🏷️ {@link ToggleGroupProps}
 *
 * @example
 * ```jsx
 * <ToggleGroup defaultValue="lest" onChange={console.log} size="small">
 *   <ToggleGroup.Item value="ulest" label="Ulest" />
 *   <ToggleGroup.Item value="lest" label="Leste" />
 *   <ToggleGroup.Item value="sendt" label="Sendt" />
 * </ToggleGroup>
 * ```
 */
export const ToggleGroup = forwardRef((_a, ref) => {
    var { className, children, onChange, size = "medium", label, value, defaultValue, variant, fill = false, "data-color": color } = _a, rest = __rest(_a, ["className", "children", "onChange", "size", "label", "value", "defaultValue", "variant", "fill", "data-color"]);
    const toggleGroupContext = useToggleGroup({
        defaultValue,
        value,
        onChange,
    });
    /**
     * ToggleGroupProvider handles memoization.
     */
    const context = Object.assign(Object.assign({}, toggleGroupContext), { size });
    const labelId = useId();
    if (!value && !defaultValue) {
        console.error("ToggleGroup without value or defaultvalue is not allowed");
    }
    if (!value && !defaultValue) {
        console.error("ToggleGroup needs either a value or defaultValue");
    }
    return (React.createElement(ToggleGroupProvider, Object.assign({}, context),
        React.createElement("div", { className: cl("aksel-toggle-group__wrapper", className, {
                "aksel-toggle-group__wrapper--fill": fill,
            }), "data-color": color !== null && color !== void 0 ? color : variantToColor(variant) },
            label && (React.createElement(Label, { as: "div", size: size, className: "aksel-toggle-group__label", id: labelId }, label)),
            React.createElement("div", Object.assign({ "aria-labelledby": label ? labelId : undefined }, rest, { ref: ref, className: cl("aksel-toggle-group", `aksel-toggle-group--${size}`), role: "radiogroup", "data-aksel-toggle-group": true }), children))));
});
function variantToColor(variant) {
    switch (variant) {
        case "action":
            return "accent";
        case "neutral":
            return "neutral";
        default:
            return undefined;
    }
}
ToggleGroup.Item = ToggleItem;
export default ToggleGroup;
export { ToggleItem as ToggleGroupItem };
//# sourceMappingURL=ToggleGroup.js.map