import {element} from 'deku';
import Paragraph from './components/paragraph';
import setupBlockquote from './components/blockquote';
import Header from './components/header';
import startswith from 'lodash.startswith';

const isText = type => type === 'paragraph' || startswith(type, 'header');

const hasContent = ({children}) =>
  children.some(child => child.type !== 'linebreak' &&
    (child.content && child.content.trim()) || child.mark);

const setup = ({Embed}) => {
  const blockList = items => items.map(renderItem);
  const Blockquote = setupBlockquote({blockList});
  const renderItem = item => {
    const {type, children} = item;
    if (isText(type) && !hasContent(item)) {
      return '';
    }

    if (type === 'paragraph') {
      return <Paragraph items={children} />;
    }

    if (type === 'header1') {
      return <Header type={1} items={children} />;
    }

    if (type === 'header2') {
      return <Header type={2} items={children} />;
    }

    if (type === 'header3') {
      return <Header type={3} items={children} />;
    }

    if (type === 'header4') {
      return <Header type={4} items={children} />;
    }

    if (type === 'header5') {
      return <Header type={5} items={children} />;
    }

    if (type === 'header6') {
      return <Header type={6} items={children} />;
    }

    if (type === 'blockquote') {
      return <Blockquote items={children} />;
    }

    if (type === 'embed') {
      return Embed.test(item) ? <Embed {...item} /> : '';
    }

    return '';
  };

  return blockList;
};

export default setup;

@@ -481,364 +481,243 @@
 nst 
-blockList = items =%3E items.map(renderItem);%0A  const Blockquote = setupBlockquote(%7BblockList%7D);%0A  const renderItem = item =%3E %7B%0A    const %7Btype, children%7D = item;%0A    if (isText(type) && !hasConten
+types = %7B%0A    blockquote: (%7Bchildren%7D) =%3E %3CBlockquote items=%7Bchildren%7D /%3E,%0A    embed: item =%3E Embed.tes
 t(item)
-) %7B%0A      return '';%0A    %7D%0A%0A    if (type === 'paragraph') %7B%0A      return %3CParagraph items=%7Bchildren%7D /%3E;%0A    %7D%0A%0A    if (type === 'header1') %7B%0A      return
+ ? %3CEmbed %7B...item%7D /%3E : '',%0A    header1: (%7Bchildren%7D) =%3E %3CHeader level=%7B1%7D items=%7Bchildren%7D /%3E,%0A    header2: (%7Bchildren%7D) =%3E
  %3CHe
@@ -725,15 +725,16 @@
 der 
-type=%7B1
+level=%7B2
 %7D it
@@ -754,59 +754,38 @@
 %7D /%3E
-;%0A    %7D%0A%0A    if (type === 'header2') %7B%0A      return
+,%0A    header3: (%7Bchildren%7D) =%3E
  %3CHe
@@ -793,15 +793,16 @@
 der 
-type=%7B2
+level=%7B3
 %7D it
@@ -822,59 +822,38 @@
 %7D /%3E
-;%0A    %7D%0A%0A    if (type === 'header3') %7B%0A      return
+,%0A    header4: (%7Bchildren%7D) =%3E
  %3CHe
@@ -861,15 +861,16 @@
 der 
-type=%7B3
+level=%7B4
 %7D it
@@ -890,59 +890,38 @@
 %7D /%3E
-;
+,
 %0A    
-%7D%0A%0A    if (type === 'header4') %7B%0A      return
+header5: (%7Bchildren%7D) =%3E
  %3CHe
@@ -929,15 +929,16 @@
 der 
-type=%7B4
+level=%7B5
 %7D it
@@ -958,59 +958,38 @@
 %7D /%3E
-;
+,
 %0A    
-%7D%0A%0A    if (type === 'header5') %7B%0A      return
+header6: (%7Bchildren%7D) =%3E
  %3CHe
@@ -997,15 +997,16 @@
 der 
-type=%7B5
+level=%7B6
 %7D it
@@ -1026,76 +1026,51 @@
 %7D /%3E
-;%0A    %7D%0A%0A    if (type === 'header6') %7B%0A      return %3CHeader type=%7B6%7D
+,%0A    paragraph: (%7Bchildren%7D) =%3E %3CParagraph
  ite
@@ -1089,184 +1089,276 @@
 %7D /%3E
-;%0A  
+%0A
   %7D
+;
 %0A%0A  
-  if (type === 'blockquote') %7B%0A      return %3CBlockquote items=%7Bchildren%7D /%3E;%0A    %7D%0A%0A    if (type === 'embed') %7B%0A      return Embed.test(item) ? %3CEmbed %7B...item%7D /%3E :
+const blockList = items =%3E items.map(renderItem);%0A  const Blockquote = setupBlockquote(%7BblockList%7D);%0A  const renderItem = item =%3E %7B%0A    const %7Btype%7D = item;%0A    const typeFn = types%5Btype%5D;%0A    if (!typeFn %7C%7C (isText(type) && !hasContent(item))) %7B%0A      return
  '';
@@ -1372,26 +1372,36 @@
 %0A    return 
-''
+typeFn(item)
 ;%0A  %7D;%0A%0A  re

remove complex method