"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.SnapModeField = void 0;
const React = require("react");
const react_redux_1 = require("react-redux");
const core_frontend_1 = require("@itwin/core-frontend");
const appui_layout_react_1 = require("@itwin/appui-layout-react");
const UiFramework_1 = require("../UiFramework");
const core_react_1 = require("@itwin/core-react");
const LabelIndicator_1 = require("../statusbar/LabelIndicator");
const appui_abstract_1 = require("@itwin/appui-abstract");
const snaps_svg_1 = require("@bentley/icons-generic/icons/snaps.svg");
const snaps_intersection_svg_1 = require("@bentley/icons-generic/icons/snaps-intersection.svg");
const snaps_center_svg_1 = require("@bentley/icons-generic/icons/snaps-center.svg");
const snaps_nearest_svg_1 = require("@bentley/icons-generic/icons/snaps-nearest.svg");
const snaps_origin_svg_1 = require("@bentley/icons-generic/icons/snaps-origin.svg");
const snaps_midpoint_svg_1 = require("@bentley/icons-generic/icons/snaps-midpoint.svg");
const snaps_bisector_svg_1 = require("@bentley/icons-generic/icons/snaps-bisector.svg");
function getIconFromIconName(iconName) {
    let iconSpec = appui_abstract_1.IconSpecUtilities.createWebComponentIconSpec(snaps_svg_1.default);
    switch (iconName) {
        case "snaps":
            iconSpec = appui_abstract_1.IconSpecUtilities.createWebComponentIconSpec(snaps_svg_1.default);
            break;
        case "snaps-intersection":
            iconSpec =
                appui_abstract_1.IconSpecUtilities.createWebComponentIconSpec(snaps_intersection_svg_1.default);
            break;
        case "snaps-center":
            iconSpec = appui_abstract_1.IconSpecUtilities.createWebComponentIconSpec(snaps_center_svg_1.default);
            break;
        case "snaps-nearest":
            iconSpec = appui_abstract_1.IconSpecUtilities.createWebComponentIconSpec(snaps_nearest_svg_1.default);
            break;
        case "snaps-origin":
            iconSpec = appui_abstract_1.IconSpecUtilities.createWebComponentIconSpec(snaps_origin_svg_1.default);
            break;
        case "snaps-midpoint":
            iconSpec = appui_abstract_1.IconSpecUtilities.createWebComponentIconSpec(snaps_midpoint_svg_1.default);
            break;
        case "snaps-bisector":
            iconSpec = appui_abstract_1.IconSpecUtilities.createWebComponentIconSpec(snaps_bisector_svg_1.default);
            break;
    }
    return iconSpec;
}
/**
 * Snap Mode Field React component. This component is designed to be specified in a status bar definition. It will
 * display the active snap mode that AccuSnap will use and allow the user to select a new snap mode.
 */
function SnapModeFieldComponent(props) {
    const snapModes = React.useMemo(() => [
        {
            label: UiFramework_1.UiFramework.translate("snapModeField.keypoint"),
            value: core_frontend_1.SnapMode.NearestKeypoint,
            iconName: "snaps",
        },
        {
            label: UiFramework_1.UiFramework.translate("snapModeField.intersection"),
            value: core_frontend_1.SnapMode.Intersection,
            iconName: "snaps-intersection",
        },
        {
            label: UiFramework_1.UiFramework.translate("snapModeField.center"),
            value: core_frontend_1.SnapMode.Center,
            iconName: "snaps-center",
        },
        {
            label: UiFramework_1.UiFramework.translate("snapModeField.nearest"),
            value: core_frontend_1.SnapMode.Nearest,
            iconName: "snaps-nearest",
        },
        {
            label: UiFramework_1.UiFramework.translate("snapModeField.origin"),
            value: core_frontend_1.SnapMode.Origin,
            iconName: "snaps-origin",
        },
        {
            label: UiFramework_1.UiFramework.translate("snapModeField.midpoint"),
            value: core_frontend_1.SnapMode.MidPoint,
            iconName: "snaps-midpoint",
        },
        {
            label: UiFramework_1.UiFramework.translate("snapModeField.bisector"),
            value: core_frontend_1.SnapMode.Bisector,
            iconName: "snaps-bisector",
        },
    ], []);
    /** Return icon class name for a specific snapMode. */
    const getSnapModeIconNameFromMode = React.useCallback(function (snapMode) {
        for (const mode of snapModes) {
            if (mode.value === snapMode)
                return mode.iconName;
        }
        /* istanbul ignore else */
        if (snapMode > 0)
            return "snaps-multione";
        /* istanbul ignore next */
        return "placeholder";
    }, [snapModes]);
    const title = UiFramework_1.UiFramework.translate("snapModeField.snapMode");
    return (React.createElement(LabelIndicator_1.StatusBarLabelIndicator, { iconSpec: getIconFromIconName(getSnapModeIconNameFromMode(props.snapMode)), title: title, label: title, popup: React.createElement(appui_layout_react_1.SnapModePanel, { title: title }, snapModes.map((item, index) => (React.createElement(appui_layout_react_1.Snap, { key: `SM_${index}`, onClick: () => UiFramework_1.UiFramework.setAccudrawSnapMode(item.value), isActive: (props.snapMode & item.value) === item.value, icon: React.createElement(core_react_1.Icon, { className: `icon`, iconSpec: getIconFromIconName(item.iconName) }) }, item.label)))) }));
}
/** 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 { snapMode: frameworkState.configurableUiState.snapMode };
}
// we declare the variable and export that rather than using export default.
/**
 * Snap Mode Field React component. This component is designed to be specified in a status bar definition. It will
 * display the active snap mode that AccuSnap will use and allow the user to select a new snap mode.
 * This Field React component is Redux connected.
 * @public
 */
exports.SnapModeField = (0, react_redux_1.connect)(mapStateToProps)(SnapModeFieldComponent);
//# sourceMappingURL=SnapMode.js.map