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.alertTriggerIntervalDay.id,
        id: "DAY",
    },
    {
        title: messages.alertTriggerIntervalWeek.id,
        id: "WEEK",
    },
    {
        title: messages.alertTriggerIntervalMonth.id,
        id: "MONTH",
    },
    {
        title: messages.alertTriggerIntervalQuarter.id,
        id: "QUARTER",
    },
    {
        title: messages.alertTriggerIntervalYear.id,
        id: "YEAR",
    },
];
export function AlertTriggerIntervalSelect({ id, selectedTriggerInterval, onTriggerIntervalChange, overlayPositionType, closeOnParentScroll, }) {
    const selectedOption = options.find((o) => o.id === selectedTriggerInterval);
    const intl = useIntl();
    return (_jsx("div", { className: "gd-alert-trigger-interval-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-interval-select__button s-alert-trigger-interval-select"), buttonRef: buttonRef, dropdownId: dropdownId, isOpen: isOpen, accessibilityConfig: {
                        ariaExpanded: isOpen,
                        popupType: "listbox",
                    } }));
            }, renderBody: ({ closeDropdown, ariaAttributes }) => {
                const listboxItems = options.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-interval-select-list", items: listboxItems, selectedItemId: selectedTriggerInterval, onSelect: (item) => {
                        if (selectedTriggerInterval !== item.id) {
                            onTriggerIntervalChange(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-interval-select__list-item" }));
                    } }));
            } }) }));
}
//# sourceMappingURL=AlertTriggerIntervalSelect.js.map