import { findTable } from '@atlaskit/editor-tables';

/*
 * Returns true if the current selection is inside a table nested within a table.
 *
 * ```typescript
 * const isNestedTable = isSelectionTableNestedInTable(state);
 * ```
 */
export var isSelectionTableNestedInTable = function isSelectionTableNestedInTable(state) {
  var table = findTable(state.selection);
  if (!table) {
    return false;
  }
  var parent = state.doc.resolve(table.pos).parent;
  var nodeTypes = state.schema.nodes;
  return [nodeTypes.tableHeader, nodeTypes.tableCell].includes(parent.type);
};