import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
// (C) 2023-2025 GoodData Corporation
import { useCallback } from "react";
import { useIntl } from "react-intl";
import { LOCALES } from "@gooddata/sdk-ui";
import { ToggleSwitch } from "./ToggleSwitch.js";
import { Dropdown, DropdownButton, DropdownList } from "../../../../Dropdown/index.js";
import { SingleSelectListItem } from "../../../../List/index.js";
import { dialogChangeMessageLabels } from "../../../../locales.js";
import { DEFAULT_LOCALE } from "../types.js";
/**
 * @internal
 */
export function LocaleSetting({ isChecked, selectedLocal, onChecked, onLocaleSelected, }) {
    const intl = useIntl();
    return (_jsxs(_Fragment, { children: [_jsx(ToggleSwitch, { id: "locale", className: "bottom-space", label: intl.formatMessage({
                    id: "embedInsightDialog.webComponents.options.locale",
                }), checked: isChecked, onChange: onChecked, questionMarkMessage: intl.formatMessage(dialogChangeMessageLabels.locale) }), isChecked ? (_jsx(LocaleSelect, { selectedLocale: selectedLocal || DEFAULT_LOCALE, onSelectLocale: onLocaleSelected })) : null] }));
}
const localeItems = LOCALES.map((u) => ({ id: u, title: u }));
function LocaleSelect(props) {
    const { selectedLocale, onSelectLocale } = props;
    const renderDropdownBody = useCallback(({ closeDropdown }) => {
        return (_jsx(DropdownList, { items: localeItems, width: 60, renderItem: ({ item }) => {
                return (_jsx(SingleSelectListItem, { title: item.title, isSelected: item.id === selectedLocale, onClick: () => {
                        onSelectLocale(item.id);
                        closeDropdown();
                    } }));
            } }));
    }, [onSelectLocale, selectedLocale]);
    const renderDropdownButton = useCallback(({ openDropdown, isOpen }) => {
        return _jsx(DropdownButton, { value: selectedLocale, isOpen: isOpen, onClick: openDropdown });
    }, [selectedLocale]);
    return (_jsx("div", { className: "locale-setting-component bottom-space", children: _jsx(Dropdown, { renderBody: renderDropdownBody, renderButton: renderDropdownButton }) }));
}
//# sourceMappingURL=LocaleSetting.js.map