"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ThemeSelector = void 0;
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
const react_redux_1 = require("react-redux");
const Select_1 = require("../../components/Select");
const ThemeRedux = tslib_1.__importStar(require("../../Redux/ActionsReducers/ThemeRedux"));
const ModuleConstants_1 = require("../../Utilities/Constants/ModuleConstants");
const AdaptableContext_1 = require("../AdaptableContext");
const ThemeSelector = (props) => {
    const adaptable = (0, AdaptableContext_1.useAdaptable)();
    const dispatch = (0, react_redux_1.useDispatch)();
    const availableThemes = adaptable.api.themeApi.getThemes();
    const currentTheme = (0, react_redux_1.useSelector)((state) => state.Theme.CurrentTheme);
    const disabled = adaptable.api.entitlementApi.getEntitlementAccessLevelForModule(ModuleConstants_1.ThemeModuleId) === 'ReadOnly';
    const optionThemes = availableThemes.map((theme) => {
        if (typeof theme === 'string') {
            // protection against old state, which could be string
            theme = {
                Name: theme,
                Description: theme,
            };
        }
        return {
            value: theme.Name,
            label: theme.Description,
        };
    });
    return (React.createElement(Select_1.Select, { "aria-label": "Select Theme", "data-name": "select-theme-dropdown", options: optionThemes, value: currentTheme, disabled: disabled, size: props.size, onChange: (themeName) => {
            dispatch(ThemeRedux.ThemeSelect(themeName));
        } }));
};
exports.ThemeSelector = ThemeSelector;
