import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
// (C) 2026 GoodData Corporation
import { useId, useState } from "react";
import { useIntl } from "react-intl";
import { bem } from "../@ui/@utils/bem.js";
import { UiIcon } from "../@ui/UiIcon/UiIcon.js";
import { UiIconButton } from "../@ui/UiIconButton/UiIconButton.js";
import { commonDialogMessages } from "../locales.js";
const { b, e } = bem("gd-ui-kit-widget-notice");
const ICON_BY_TYPE = {
    info: "infoCircle",
    success: "checkCircle",
    warning: "warning",
    error: "exclamationCircle",
};
const ICON_COLOR_BY_TYPE = {
    info: "primary",
    success: "success",
    warning: "warning",
    error: "error",
};
/**
 * @internal
 */
export function WidgetNotice({ type = "info", message, action, detail, detailAction, expandLabel, collapseLabel, defaultExpanded = false, showIcon = true, onClose, closeButtonLabel, dataTestId, }) {
    const intl = useIntl();
    const detailId = useId();
    const [isExpanded, setIsExpanded] = useState(defaultExpanded);
    const hasDetail = Boolean(detail);
    const effectiveCloseButtonLabel = closeButtonLabel ?? intl.formatMessage(commonDialogMessages.close);
    return (_jsxs("div", { className: b({ type, expandable: hasDetail }), "data-testid": dataTestId, children: [
            _jsxs("div", { className: e("header"), children: [
                    _jsxs("div", { className: e("content"), children: [showIcon ? (_jsx("span", { className: e("icon"), "aria-hidden": "true", children: _jsx(UiIcon, { type: ICON_BY_TYPE[type], size: 16, color: ICON_COLOR_BY_TYPE[type] }) })) : null, _jsxs("div", { className: e("text"), children: [
                                    _jsx("span", { className: e("message"), children: message }), action ? _jsx("span", { className: e("action"), children: action }) : null, hasDetail ? (_jsx("button", { type: "button", className: e("toggle"), "data-testid": "widget-notice-toggle", "aria-expanded": isExpanded, "aria-controls": isExpanded ? detailId : undefined, onClick: () => setIsExpanded((wasExpanded) => !wasExpanded), children: isExpanded ? collapseLabel : expandLabel })) : null] })
                        ] }), onClose ? (_jsx(UiIconButton, { icon: "cross", variant: "tertiary", size: "xsmall", label: effectiveCloseButtonLabel, onClick: onClose, dataTestId: "widget-notice-close" })) : null] }), hasDetail && isExpanded ? (_jsxs("div", { id: detailId, className: e("detail"), children: [
                    _jsx("div", { className: e("detail-text"), children: detail }), detailAction ? _jsx("div", { className: e("detail-action"), children: detailAction }) : null] })) : null] }));
}
