"use strict";
/*---------------------------------------------------------------------------------------------
 * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
 * See LICENSE.md in the project root for license terms and full copyright notice.
 *--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
 * @module StatusBar
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.SelectionScopeField = void 0;
require("./SelectionScope.scss");
const classnames_1 = require("classnames");
const React = require("react");
const itwinui_react_1 = require("@itwin/itwinui-react");
const UiFramework_1 = require("../UiFramework");
const useTranslation_1 = require("../hooks/useTranslation");
const useReduxFrameworkState_1 = require("../uistate/useReduxFrameworkState");
/** `SelectionScopeField` component is designed to be specified in a status bar.
 * It displays the active selection scope and the list of scopes from which the user can change the active selection scope.
 * @public
 */
function SelectionScopeField(props) {
    const { translate } = (0, useTranslation_1.useTranslation)();
    const reduxActiveSelectionScope = (0, useReduxFrameworkState_1.useReduxFrameworkState)(
    // eslint-disable-next-line deprecation/deprecation
    (state) => state?.sessionState.activeSelectionScope);
    const reduxAvailableSelectionScopes = (0, useReduxFrameworkState_1.useReduxFrameworkState)(
    // eslint-disable-next-line deprecation/deprecation
    (state) => state?.sessionState.availableSelectionScopes);
    const activeSelectionScope = props.activeScope ?? reduxActiveSelectionScope ?? "";
    const availableSelectionScopes = React.useMemo(() => props.selectionScopes ??
        reduxAvailableSelectionScopes ?? [{ id: "element", label: "Element" }], [props.selectionScopes, reduxAvailableSelectionScopes]);
    const options = React.useMemo(() => availableSelectionScopes.map((scope) => {
        return { value: scope.id, label: scope.label };
    }), [availableSelectionScopes]);
    const updateSelectValue = (newValue) => {
        if (!newValue)
            return;
        if (props.onChange) {
            props.onChange(newValue);
            return;
        }
        // eslint-disable-next-line deprecation/deprecation
        UiFramework_1.UiFramework.setActiveSelectionScope(newValue);
    };
    return (React.createElement("div", { className: (0, classnames_1.default)("uifw-statusFields-selectionScope", props.className), style: props.style },
        React.createElement(itwinui_react_1.LabeledSelect, { className: "uifw-statusFields-selectionScope-selector", label: `${translate("selectionScopeField.label")}:`, labelProps: { className: "uifw-statusFields-selectionScope-label" }, displayStyle: "inline", value: activeSelectionScope, options: options, onChange: updateSelectValue, "data-testid": "components-selectionScope-selector", title: translate("selectionScopeField.toolTip"), size: "small" })));
}
exports.SelectionScopeField = SelectionScopeField;
//# sourceMappingURL=SelectionScope.js.map