import { jsx as _jsx } from "react/jsx-runtime";
import cx from "classnames";
import { useIntl } from "react-intl";
import { Dropdown, DropdownButton, SingleSelectListItem, UiListbox, } from "@gooddata/sdk-ui-kit";
import { messages } from "../messages.js";
const options = [
    {
        title: messages.alertTriggerModeAlways.id,
        id: "ALWAYS",
    },
    {
        title: messages.alertTriggerModeOnce.id,
        id: "ONCE",
    },
    {
        title: messages.alertTriggerModeOncePerInterval.id,
        id: "ONCE_PER_INTERVAL",
    },
];
export function AlertTriggerModeSelect({ id, selectedTriggerMode, onTriggerModeChange, overlayPositionType, closeOnParentScroll, enableAlertOncePerInterval, }) {
    const selectedOption = options.find((o) => o.id === selectedTriggerMode);
    const intl = useIntl();
    return (_jsx("div", { className: "gd-alert-trigger-mode-select", children: _jsx(Dropdown, { closeOnParentScroll: closeOnParentScroll, overlayPositionType: overlayPositionType, autofocusOnOpen: true, renderButton: ({ isOpen, toggleDropdown, buttonRef, dropdownId }) => {
                return (_jsx(DropdownButton, { id: id, value: selectedOption ? intl.formatMessage({ id: selectedOption.title }) : "", onClick: toggleDropdown, className: cx("gd-edit-alert-trigger-mode-select__button s-alert-trigger-mode-select"), buttonRef: buttonRef, dropdownId: dropdownId, isOpen: isOpen, accessibilityConfig: {
                        ariaExpanded: isOpen,
                        popupType: "listbox",
                    } }));
            }, renderBody: ({ closeDropdown, ariaAttributes }) => {
                const listboxItems = options
                    .filter((item) => item.id !== "ONCE_PER_INTERVAL" || enableAlertOncePerInterval)
                    .map((option) => ({
                    type: "interactive",
                    id: option.id,
                    stringTitle: intl.formatMessage({ id: option.title }),
                    data: option,
                }));
                return (_jsx(UiListbox, { shouldKeyboardActionStopPropagation: true, shouldKeyboardActionPreventDefault: true, dataTestId: "s-alert-trigger-mode-select-list", items: listboxItems, selectedItemId: selectedTriggerMode, onSelect: (item) => {
                        if (selectedTriggerMode !== item.id) {
                            onTriggerModeChange(item.id);
                        }
                    }, onClose: closeDropdown, ariaAttributes: ariaAttributes, InteractiveItemComponent: ({ item, isSelected, onSelect, isFocused }) => {
                        return (_jsx(SingleSelectListItem, { title: item.stringTitle, isSelected: isSelected, isFocused: isFocused, onClick: onSelect, className: "gd-alert-trigger-mode-select__list-item" }));
                    } }));
            } }) }));
}
//# sourceMappingURL=AlertTriggerModeSelect.js.map