/* eslint-disable react/no-array-index-key */
import classnames from 'classnames';
import customizable from "../../../../utils/css/customizable.js";
import getTagFromType from '../getTagFromType';
import isEmptyParagraph from './isEmptyParagraph';
import Leaf from './Leaf';
const Node = function Node(props) {
  const {
    data,
    context
  } = props;
  const {
    type,
    leaves,
    isVoid,
    nodes: children = []
  } = data;
  const {
    classes,
    components
  } = context;
  if (isEmptyParagraph(data)) {
    return null;
  }
  if (leaves) {
    return leaves.map((leaf, i) => <Leaf key={i} data={leaf} context={context} />);
  }
  const {
    Tag,
    name,
    nodeToProps
  } = getTagFromType(type, components);
  const tagProps = {
    className: classnames(customizable(`RenderedContent__${name}`), classes[name]),
    ...nodeToProps(data, context)
  };
  if (isVoid) {
    return <Tag {...tagProps} />;
  }
  return <Tag {...tagProps}>
      {children.map((child, i) => <Node key={i} data={child} context={context} />)}
    </Tag>;
};
export default Node;