import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
import { findParentNode } from '@atlaskit/editor-prosemirror/utils';
import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
export function findInsertLocation(selection) {
  var _selection$$from$doc$ = selection.$from.doc.type,
    schema = _selection$$from$doc$.schema,
    name = _selection$$from$doc$.name;
  if (selection instanceof NodeSelection) {
    return selection.node.type.name;
  }
  if (selection instanceof CellSelection) {
    return schema.nodes.table.name;
  }

  // Text selection
  var parentNodeInfo = findParentNode(function (node) {
    return node.type !== schema.nodes.paragraph;
  })(selection);
  return parentNodeInfo ? parentNodeInfo.node.type.name : name;
}