"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 Toolbar
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.Toolbar = void 0;
const React = require("react");
const components_react_1 = require("@itwin/components-react");
const toUIAToolbarItem_1 = require("./toUIAToolbarItem");
const SyncUiEventDispatcher_1 = require("../syncui/SyncUiEventDispatcher");
const PreviewFeatures_1 = require("../preview/PreviewFeatures");
const Toolbar_1 = require("../preview/new-toolbars/Toolbar");
/** Component that displays toolbar items.
 * @beta
 */
function Toolbar(props) {
    const previewFeatures = (0, PreviewFeatures_1.usePreviewFeatures)();
    if (previewFeatures.newToolbars) {
        return React.createElement(NewToolbar, { ...props });
    }
    return React.createElement(OriginalToolbar, { ...props });
}
exports.Toolbar = Toolbar;
function NewToolbar(props) {
    const expandsTo = toDirection(props.expandsTo);
    const panelAlignment = toPanelAlignment(props.panelAlignment);
    return (React.createElement(Toolbar_1.Toolbar, { expandsTo: expandsTo, panelAlignment: panelAlignment, items: props.items }));
}
function OriginalToolbar(props) {
    const { items, ...other } = props;
    const uiaItems = React.useMemo(() => {
        return items.map((item) => (0, toUIAToolbarItem_1.toUIAToolbarItem)(item));
    }, [items]);
    return (React.createElement(components_react_1.InternalToolbarComponent, { items: uiaItems, syncUiEvent: SyncUiEventDispatcher_1.SyncUiEventDispatcher.onSyncUiEvent, ...other }));
}
function toDirection(direction) {
    switch (direction) {
        case components_react_1.Direction.Bottom:
            return "bottom";
        case components_react_1.Direction.Left:
            return "left";
        case components_react_1.Direction.Right:
            return "right";
        case components_react_1.Direction.Top:
            return "top";
    }
    return undefined;
}
function toPanelAlignment(alignment) {
    switch (alignment) {
        case components_react_1.ToolbarPanelAlignment.End:
            return "end";
        case components_react_1.ToolbarPanelAlignment.Start:
            return "start";
    }
    return undefined;
}
//# sourceMappingURL=Toolbar.js.map