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, useState } from "react";
import { Popover } from "../popover/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 { HelpTextIcon } from "./HelpTextIcon.js";
/**
 * A component that displays a help text button with a popover.
 *
 * @see [📝 Documentation](https://aksel.nav.no/komponenter/core/helptext)
 * @see 🏷️ {@link HelpTextProps}
 *
 * @example
 * ```jsx
 * <HelpText title="Hvor kommer dette fra?">
 *   Informasjonen er hentet fra X sin statistikk fra 2021
 * </HelpText>
 * ```
 */
export const HelpText = forwardRef((_a, ref) => {
    var { className, children, placement, strategy = "absolute", title, onClick, wrapperClassName, "data-color": color = "info" } = _a, rest = __rest(_a, ["className", "children", "placement", "strategy", "title", "onClick", "wrapperClassName", "data-color"]);
    const buttonRef = useRef(null);
    const mergedRef = useMergeRefs(buttonRef, ref);
    const [open, setOpen] = useState(false);
    const translate = useI18n("HelpText");
    const titleWithFallback = title || translate("title");
    return (React.createElement("div", { className: cl("aksel-help-text", wrapperClassName), "data-color": color },
        React.createElement("button", Object.assign({}, rest, { ref: mergedRef, onClick: composeEventHandlers(onClick, () => setOpen((x) => !x)), className: cl(className, "aksel-help-text__button"), type: "button", "aria-expanded": open, "aria-label": titleWithFallback }),
            React.createElement(HelpTextIcon, null),
            React.createElement(HelpTextIcon, { filled: true })),
        React.createElement(Popover, { onClose: () => setOpen(false), className: "aksel-help-text__popover", open: open, anchorEl: buttonRef.current, placement: placement, strategy: strategy },
            React.createElement(Popover.Content, { className: "aksel-body-short" }, children))));
});
export default HelpText;
//# sourceMappingURL=HelpText.js.map