
/**
 * Sets the current active toolbar group.
 * @method UI.setActiveTool
 * @param {string} dataElement The dataElement. Default values are: note, ink, highlight
 * @example
WebViewer(...)
  .then(function(instance) {
    // Change the toolbar group to the `Forms` group
    instance.UI.setActiveTool('note');
 */

export default (useViewer, useDocument) => (dataElement) => {
  const toolMode = useViewer.getToolMode
  if (toolMode) {
    const tools = useViewer.getToolItems[toolMode]
    const tool = tools.find(tool => tool.dataElement === dataElement)
    if (!tool) {
      console.warn('DataElement not match toolMode.');
      return
    }
    if (tool.hidden) {
      tool.hidden = false;
    }
    useDocument.setToolState(tool.type);
  } else {
    console.warn('DataElement not found.');
  }
}
