import convertToCSSPTValue from './convertToCSSPTValue.js';
import toCSSLineSpacing from './ui/toCSSLineSpacing.js';
import { Node } from 'prosemirror-model';
// This assumes that every 36pt maps to one indent level.
export var INDENT_MARGIN_PT_SIZE = 36;
export var MIN_INDENT_LEVEL = 0;
export var MAX_INDENT_LEVEL = 7;
export var ATTRIBUTE_INDENT = 'data-indent';
export var ATTRIBUTE_STYLE_LEVEL = 'data-style-level';
export var RESERVED_STYLE_NONE = 'None';
export var RESERVED_STYLE_NONE_NUMBERING = RESERVED_STYLE_NONE + '-@#$-';
var cssVal = new Set(['', '0%', '0pt', '0px']);
export var EMPTY_CSS_VALUE = cssVal;
var ALIGN_PATTERN = /(left|right|center|justify)/;

// https://github.com/ProseMirror/prosemirror-schema-basic/blob/master/src/schema-basic.js
// :: NodeSpec A plain paragraph textblock. Represented in the DOM
// as a `<p>` element.
var ParagraphNodeSpec = {
  attrs: {
    align: {
      "default": null
    },
    color: {
      "default": null
    },
    id: {
      "default": null
    },
    indent: {
      "default": null
    },
    lineSpacing: {
      "default": null
    },
    // TODO: Add UI to let user edit / clear padding.
    paddingBottom: {
      "default": null
    },
    // TODO: Add UI to let user edit / clear padding.
    paddingTop: {
      "default": null
    }
  },
  content: 'inline*',
  group: 'block',
  parseDOM: [{
    tag: 'p',
    getAttrs: getAttrs
  }],
  toDOM: toDOM
};
function getAttrs(dom) {
  var _dom$style = dom.style,
    lineHeight = _dom$style.lineHeight,
    textAlign = _dom$style.textAlign,
    marginLeft = _dom$style.marginLeft,
    paddingTop = _dom$style.paddingTop,
    paddingBottom = _dom$style.paddingBottom;
  var align = dom.getAttribute('align') || textAlign || '';
  align = ALIGN_PATTERN.test(align) ? align : null;
  var indent = parseInt(dom.getAttribute(ATTRIBUTE_INDENT), 10);
  if (!indent && marginLeft) {
    indent = convertMarginLeftToIndentValue(marginLeft);
  }
  indent = indent || MIN_INDENT_LEVEL;
  var lineSpacing = lineHeight ? toCSSLineSpacing(lineHeight) : null;
  var id = dom.getAttribute('id') || '';
  return {
    align: align,
    indent: indent,
    lineSpacing: lineSpacing,
    paddingTop: paddingTop,
    paddingBottom: paddingBottom,
    id: id
  };
}
function getStyle(attrs) {
  return getStyleEx(attrs.align, attrs.lineSpacing, attrs.paddingTop, attrs.paddingBottom);
}
function getStyleEx(align, lineSpacing, paddingTop, paddingBottom) {
  var style = '';
  if (align && align !== 'left') {
    style += "text-align: ".concat(align, ";");
  }
  if (lineSpacing) {
    var cssLineSpacing = toCSSLineSpacing(lineSpacing);
    style += "line-height: ".concat(cssLineSpacing, ";") + // This creates the local css variable `--czi-content-line-height`
    // that its children may apply.
    "--czi-content-line-height: ".concat(cssLineSpacing, ";");
  }
  if (paddingTop && !EMPTY_CSS_VALUE.has(paddingTop)) {
    style += "padding-top: ".concat(paddingTop, ";");
  }
  if (paddingBottom && !EMPTY_CSS_VALUE.has(paddingBottom)) {
    style += "padding-bottom: ".concat(paddingBottom, ";");
  }
  return {
    style: style
  };
}
function toDOM(node) {
  var _node$attrs = node.attrs,
    indent = _node$attrs.indent,
    id = _node$attrs.id;
  var attrs = {};
  var _getStyle = getStyle(node.attrs),
    style = _getStyle.style;
  style && (attrs.style = style);
  if (indent) {
    attrs[ATTRIBUTE_INDENT] = String(indent);
  }
  if (id) {
    attrs.id = id;
  }
  return ['p', attrs, 0];
}
export var toParagraphDOM = toDOM;
export var getParagraphNodeAttrs = getAttrs;
export var getParagraphStyle = getStyle;
export function convertMarginLeftToIndentValue(marginLeft) {
  var ptValue = convertToCSSPTValue(marginLeft);
  return Math.min(Math.max(Math.floor(ptValue / INDENT_MARGIN_PT_SIZE), MIN_INDENT_LEVEL), MAX_INDENT_LEVEL);
}
export default ParagraphNodeSpec;
import { bpfrpt_proptype_NodeSpec } from "./Types.js";