import { EDITOR_APPEARANCE_CONTEXT } from '@atlaskit/analytics-namespaced-context/FabricEditorAnalyticsContext';
import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
import { findParentNode } from '@atlaskit/editor-prosemirror/utils';
import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
export var getAnalyticsAppearance = function getAnalyticsAppearance(appearance) {
  switch (appearance) {
    case 'full-page':
      return EDITOR_APPEARANCE_CONTEXT.FIXED_WIDTH;
    case 'full-width':
      return EDITOR_APPEARANCE_CONTEXT.FULL_WIDTH;
    case 'comment':
      return EDITOR_APPEARANCE_CONTEXT.COMMENT;
    case 'chromeless':
      return EDITOR_APPEARANCE_CONTEXT.CHROMELESS;
    case 'mobile':
      return EDITOR_APPEARANCE_CONTEXT.MOBILE;
    case 'max':
      return EDITOR_APPEARANCE_CONTEXT.MAX;
  }
};
export var getAnalyticsEditorAppearance = function getAnalyticsEditorAppearance(editorAppearance) {
  return editorAppearance ? "editor_".concat(getAnalyticsAppearance(editorAppearance)) : '_unknown';
};
export var getAnalyticsEventSeverity = function getAnalyticsEventSeverity(duration, normalThreshold, degradedThreshold) {
  if (duration > normalThreshold && duration <= degradedThreshold) {
    return SEVERITY.DEGRADED;
  }
  if (duration > degradedThreshold) {
    return SEVERITY.BLOCKING;
  }
  return SEVERITY.NORMAL;
};
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;
}
export var SEVERITY = /*#__PURE__*/function (SEVERITY) {
  SEVERITY["NORMAL"] = "normal";
  SEVERITY["DEGRADED"] = "degraded";
  SEVERITY["BLOCKING"] = "blocking";
  return SEVERITY;
}({});
export var analyticsEventKey = 'EDITOR_ANALYTICS_EVENT';
var EDITOR_BREAKPOINT_WIDTH = {
  S: 760,
  M: 1600,
  L: Infinity
};
var TABLE_BREAKPOINT_KEYS = Object.keys(EDITOR_BREAKPOINT_WIDTH);
export var getBreakpointKey = function getBreakpointKey(width) {
  return TABLE_BREAKPOINT_KEYS.find(function (key) {
    return width <= EDITOR_BREAKPOINT_WIDTH[key];
  }) || 'L';
};