import Tweet from './custom/Tweet';
import Code from './custom/Code';
import YouTube from './custom/YouTube';
import Iframe from './custom/Iframe';
const tagTypes = {
  // Marks
  bold: {
    name: 'strong',
    Tag: 'strong'
  },
  italic: {
    name: 'emphasis',
    Tag: 'em'
  },
  underlined: {
    name: 'underlined',
    Tag: 'u'
  },
  small: {
    name: 'small',
    Tag: 'small'
  },
  // Blocks
  paragraph: {
    name: 'paragraph',
    Tag: 'p'
  },
  link: {
    name: 'link',
    Tag: 'a',
    nodeToProps: node => ({
      href: node.data.href
    })
  },
  image: {
    name: 'image',
    Tag: 'img',
    nodeToProps: node => ({
      src: node.data.canonical,
      alt: ''
    })
  },
  blockquote: {
    name: 'blockquote',
    Tag: 'blockquote'
  },
  // Lists
  'bulleted-list': {
    name: 'bulleted-list',
    Tag: 'ul'
  },
  'numbered-list': {
    name: 'numbered-list',
    Tag: 'ol'
  },
  'list-item': {
    name: 'list-item',
    Tag: 'li'
  },
  // Custom
  tweet: {
    name: 'tweet',
    Tag: Tweet,
    nodeToProps: Tweet.nodeToProps
  },
  iframe: {
    name: 'iframe',
    Tag: Iframe,
    nodeToProps: Iframe.nodeToProps
  },
  code: {
    name: 'code',
    Tag: Code,
    nodeToProps: Code.nodeToProps
  },
  youtube: {
    name: 'youtube',
    Tag: YouTube,
    nodeToProps: YouTube.nodeToProps
  }
};
const Null = function Null() {
  return null;
};
const getTagFromType = function getTagFromType(type, components = {}) {
  const {
    Tag: defaultTag = Null,
    nodeToProps = () => ({}),
    ...restTag
  } = tagTypes[type] || {};
  const Tag = components[type] || defaultTag;
  const isCustomComponent = !!components[type];
  return {
    name: type,
    Tag,
    nodeToProps: (node, context) => {
      const props = nodeToProps(node, context);
      if (!isCustomComponent) return props;
      return {
        node,
        ...props
      };
    },
    ...restTag
  };
};
export default getTagFromType;