import { customToolbarButtonItemRenderer } from "../../custom-toolbar-item-renderer.js";
import { ToolbarButton } from "../../models/index.js";
const transformItemToButton = (toolbarItem, itemRenderers) => {
  const toolbarItemRender = getToolbarItemRender(toolbarItem, itemRenderers);
  if (!toolbarItemRender) {
    throw new Error(`Toolbar: missing toolbar item renderer for '${toolbarItem.id}'`);
  }
  const toolbarItemRenderElement = toolbarItemRender(toolbarItem);
  return new ToolbarButton(toolbarItem, toolbarItemRenderElement);
};
const getToolbarItemRender = (toolbarItem, itemRenderers) => {
  if (toolbarItem.presentation?.renderer) {
    return toolbarItem.presentation.renderer;
  }
  const allRenders = {
    ...customToolbarButtonItemRenderer,
    ...itemRenderers
  };
  const toolbarItemRender = allRenders[toolbarItem.id];
  if (!toolbarItemRender) {
    if (toolbarItem.presentation?.component) {
      return allRenders.custom;
    }
    return allRenders.default;
  }
  return toolbarItemRender;
};
export {
  transformItemToButton
};
//# sourceMappingURL=transform-item-to-button.js.map
