"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
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;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ToggleGroupItem = exports.ToggleGroup = void 0;
const react_1 = __importStar(require("react"));
const typography_1 = require("../typography");
const utils_external_1 = require("../utils-external");
const helpers_1 = require("../utils/helpers");
const ToggleGroup_context_1 = require("./ToggleGroup.context");
const ToggleItem_1 = __importDefault(require("./parts/ToggleItem"));
exports.ToggleGroupItem = ToggleItem_1.default;
const useToggleGroup_1 = require("./useToggleGroup");
/**
 * 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>
 * ```
 */
exports.ToggleGroup = (0, react_1.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 = (0, useToggleGroup_1.useToggleGroup)({
        defaultValue,
        value,
        onChange,
    });
    /**
     * ToggleGroupProvider handles memoization.
     */
    const context = Object.assign(Object.assign({}, toggleGroupContext), { size });
    const labelId = (0, utils_external_1.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_1.default.createElement(ToggleGroup_context_1.ToggleGroupProvider, Object.assign({}, context),
        react_1.default.createElement("div", { className: (0, helpers_1.cl)("aksel-toggle-group__wrapper", className, {
                "aksel-toggle-group__wrapper--fill": fill,
            }), "data-color": color !== null && color !== void 0 ? color : variantToColor(variant) },
            label && (react_1.default.createElement(typography_1.Label, { as: "div", size: size, className: "aksel-toggle-group__label", id: labelId }, label)),
            react_1.default.createElement("div", Object.assign({ "aria-labelledby": label ? labelId : undefined }, rest, { ref: ref, className: (0, helpers_1.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;
    }
}
exports.ToggleGroup.Item = ToggleItem_1.default;
exports.default = exports.ToggleGroup;
//# sourceMappingURL=ToggleGroup.js.map