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, useRef } from "react";
import { BodyShort, Heading } from "../../typography/index.js";
import { cl, composeEventHandlers } from "../../utils/helpers/index.js";
import { useMergeRefs } from "../../utils/hooks/index.js";
import { useI18n } from "../../utils/i18n/i18n.hooks.js";
import ErrorSummaryItem from "./ErrorSummaryItem.js";
/**
 * Summary of errors in a form.
 *
 * @see [📝 Documentation](https://aksel.nav.no/komponenter/core/errorsummary)
 * @see 🏷️ {@link ErrorSummaryProps}
 *
 * @example
 * ```jsx
 * <ErrorSummary heading="Du må rette disse feilene før du kan sende inn søknaden:">
 *   <ErrorSummary.Item href="#1">
 *     Felt må fylles ut med alder
 *   </ErrorSummary.Item>
 *   <ErrorSummary.Item href="#2">
 *     Tekstfeltet må ha en godkjent e-post
 *   </ErrorSummary.Item>
 * </ErrorSummary>
 * ```
 */
export const ErrorSummary = forwardRef((_a, ref) => {
    var { children, className, size = "medium", headingTag = "h2", heading } = _a, rest = __rest(_a, ["children", "className", "size", "headingTag", "heading"]);
    const translate = useI18n("ErrorSummary");
    const wrapperRef = useRef(null);
    const headingRef = useRef(null);
    const mergedRef = useMergeRefs(ref, wrapperRef);
    return (React.createElement("div", Object.assign({ ref: mergedRef }, rest, { className: cl(className, "aksel-error-summary", `aksel-error-summary--${size}`), tabIndex: -1, onFocus: composeEventHandlers(rest.onFocus, (event) => {
            var _a;
            if (event.target === wrapperRef.current) {
                (_a = headingRef === null || headingRef === void 0 ? void 0 : headingRef.current) === null || _a === void 0 ? void 0 : _a.focus();
            }
        }) }),
        React.createElement(Heading, { className: "aksel-error-summary__heading", as: headingTag, size: size === "medium" ? "small" : "xsmall", ref: headingRef, tabIndex: -1 }, heading !== null && heading !== void 0 ? heading : translate("heading")),
        React.createElement(BodyShort, { as: "ul", size: size, className: "aksel-error-summary__list" }, children)));
});
ErrorSummary.Item = ErrorSummaryItem;
export default ErrorSummary;
//# sourceMappingURL=ErrorSummary.js.map