"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 react_redux_1 = require("react-redux");
const appui_layout_react_1 = require("@itwin/appui-layout-react");
const itwinui_react_1 = require("@itwin/itwinui-react");
const UiFramework_1 = require("../UiFramework");
/**
 * Status Field React component. This component is designed to be specified in a status bar definition.
 * It is used to display the number of selected items based on the Presentation Rules Selection Manager.
 * The IModelApp should call either UiFramework.setIModelConnection or SyncUiEventDispatcher.initializeConnectionEvents
 * with the active iModelConnection each time a new iModel is opened so the selection scope data is properly updated
 * in the Redux state.
 * @public
 */
function SelectionScopeFieldComponent(props) {
    const label = UiFramework_1.UiFramework.translate("selectionScopeField.label");
    const toolTip = UiFramework_1.UiFramework.translate("selectionScopeField.toolTip");
    const options = React.useMemo(() => props.availableSelectionScopes.map((scope) => {
        return { value: scope.id, label: scope.label };
    }), [props.availableSelectionScopes]);
    const updateSelectValue = (newValue) => {
        // istanbul ignore else
        if (newValue) {
            UiFramework_1.UiFramework.setActiveSelectionScope(newValue);
        }
    };
    return (React.createElement(appui_layout_react_1.FooterIndicator, { className: (0, classnames_1.default)("uifw-statusFields-selectionScope", props.className), style: props.style },
        React.createElement("label", { className: "uifw-statusFields-selectionScope-label" },
            label,
            ":"),
        React.createElement(itwinui_react_1.Select, { className: "uifw-statusFields-selectionScope-selector", value: props.activeSelectionScope, options: options, onChange: updateSelectValue, "data-testid": "components-selectionScope-selector", title: toolTip, size: "small" })));
}
/** Function used by Redux to map state data in Redux store to props that are used to render this component. */
function mapStateToProps(state) {
    const frameworkState = state[UiFramework_1.UiFramework.frameworkStateKey]; // since app sets up key, don't hard-code name
    /* istanbul ignore next */
    if (!frameworkState)
        return undefined;
    return {
        activeSelectionScope: frameworkState.sessionState.activeSelectionScope,
        availableSelectionScopes: frameworkState.sessionState.availableSelectionScopes,
    };
}
// we declare the variable and export that rather than using export default.
/**
 * SelectionScopeField React component. This component is designed to be specified in a status bar definition. It will
 * display the active selection scope that is used by the PresentationManager to determine what elements are added to the selection nap mode.
 * This React component is Redux connected.
 * @public
 */
exports.SelectionScopeField = (0, react_redux_1.connect)(mapStateToProps)(SelectionScopeFieldComponent);
//# sourceMappingURL=SelectionScope.js.map