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