"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 snaps_bisector_svg_1 = require("@bentley/icons-generic/icons/snaps-bisector.svg");
const snaps_center_svg_1 = require("@bentley/icons-generic/icons/snaps-center.svg");
const snaps_intersection_svg_1 = require("@bentley/icons-generic/icons/snaps-intersection.svg");
const snaps_midpoint_svg_1 = require("@bentley/icons-generic/icons/snaps-midpoint.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_svg_1 = require("@bentley/icons-generic/icons/snaps.svg");
const core_frontend_1 = require("@itwin/core-frontend");
const core_react_1 = require("@itwin/core-react");
const React = require("react");
const UiFramework_1 = require("../UiFramework");
const Panel_1 = require("../layout/footer/snap-mode/Panel");
const Snap_1 = require("../layout/footer/snap-mode/Snap");
const useTranslation_1 = require("../hooks/useTranslation");
const useReduxFrameworkState_1 = require("../uistate/useReduxFrameworkState");
const itwinui_react_1 = require("@itwin/itwinui-react");
const StatusBarPopover_1 = require("../statusbar/popup/StatusBarPopover");
// eslint-disable-next-line deprecation/deprecation
function getIconFromIconName(iconName) {
    let iconSpec = snaps_svg_1.default;
    switch (iconName) {
        case "snaps":
            iconSpec = snaps_svg_1.default;
            break;
        case "snaps-intersection":
            iconSpec = snaps_intersection_svg_1.default;
            break;
        case "snaps-center":
            iconSpec = snaps_center_svg_1.default;
            break;
        case "snaps-nearest":
            iconSpec = snaps_nearest_svg_1.default;
            break;
        case "snaps-origin":
            iconSpec = snaps_origin_svg_1.default;
            break;
        case "snaps-midpoint":
            iconSpec = snaps_midpoint_svg_1.default;
            break;
        case "snaps-bisector":
            iconSpec = snaps_bisector_svg_1.default;
            break;
    }
    return iconSpec;
}
/** Return icon class name for a specific snapMode. */
const getSnapModeIconNameFromMode = (modeEntries, snapMode) => {
    for (const modeEntry of modeEntries) {
        if (modeEntry.value === snapMode)
            return modeEntry.iconName;
    }
    if (snapMode > 0)
        return "snaps-multione";
    return "placeholder";
};
/** `SnapModeField` component designed to be specified in a status bar. It will
 * display the active snap mode that AccuSnap will use and allow the user to select a new snap mode.
 * @public
 */
function SnapModeField(props) {
    const { translate } = (0, useTranslation_1.useTranslation)();
    const reduxSnapMode = (0, useReduxFrameworkState_1.useReduxFrameworkState)(
    // eslint-disable-next-line deprecation/deprecation
    (state) => state?.configurableUiState.snapMode);
    const snapMode = props.snapMode ?? reduxSnapMode ?? core_frontend_1.SnapMode.NearestKeypoint;
    const snapModes = [
        {
            label: translate("snapModeField.keypoint"),
            value: core_frontend_1.SnapMode.NearestKeypoint,
            iconName: "snaps",
        },
        {
            label: translate("snapModeField.intersection"),
            value: core_frontend_1.SnapMode.Intersection,
            iconName: "snaps-intersection",
        },
        {
            label: translate("snapModeField.center"),
            value: core_frontend_1.SnapMode.Center,
            iconName: "snaps-center",
        },
        {
            label: translate("snapModeField.nearest"),
            value: core_frontend_1.SnapMode.Nearest,
            iconName: "snaps-nearest",
        },
        {
            label: translate("snapModeField.origin"),
            value: core_frontend_1.SnapMode.Origin,
            iconName: "snaps-origin",
        },
        {
            label: translate("snapModeField.midpoint"),
            value: core_frontend_1.SnapMode.MidPoint,
            iconName: "snaps-midpoint",
        },
        {
            label: translate("snapModeField.bisector"),
            value: core_frontend_1.SnapMode.Bisector,
            iconName: "snaps-bisector",
        },
    ];
    const iconName = getSnapModeIconNameFromMode(snapModes, snapMode);
    const title = translate("snapModeField.snapMode");
    return (React.createElement(StatusBarPopover_1.StatusBarPopover, { content: React.createElement(Panel_1.SnapModePanel, { title: title }, snapModes.map((item, index) => (React.createElement(Snap_1.Snap, { key: `SM_${index}`, onClick: () => {
                if (props.onChange) {
                    props.onChange(item.value);
                    return;
                }
                // eslint-disable-next-line deprecation/deprecation
                UiFramework_1.UiFramework.setAccudrawSnapMode(item.value);
            }, isActive: (snapMode & item.value) === item.value, icon: 
            // eslint-disable-next-line deprecation/deprecation
            React.createElement(core_react_1.Icon, { className: `icon`, iconSpec: getIconFromIconName(item.iconName) }) }, item.label)))) },
        React.createElement(itwinui_react_1.Button, { styleType: "borderless", title: title, 
            // eslint-disable-next-line deprecation/deprecation
            endIcon: React.createElement(core_react_1.Icon, { iconSpec: getIconFromIconName(iconName) }) },
            title,
            React.createElement(StatusBarPopover_1.StatusBarPopover.ExpandIndicator, null))));
}
exports.SnapModeField = SnapModeField;
//# sourceMappingURL=SnapMode.js.map