import deprecate from 'util-deprecate';
import addons from '@storybook/addons';
import marked from 'marked';
import { WithNotes as ReactWithNotes } from './react';

export const withMarkdownNotes = text => {
  const channel = addons.getChannel();

  return getStory => context => {
    // send the notes to the channel before the story is rendered
    channel.emit('storybook/notes/add_notes', marked(text));
    return getStory(context);
  };
};

export const withNotes = textOrOptions => {
  const channel = addons.getChannel();
  const options = typeof textOrOptions === 'string' ? { text: textOrOptions } : textOrOptions;

  return getStory => context => {
    // send the notes to the channel before the story is rendered
    channel.emit('storybook/notes/add_notes', options.text);
    return getStory(context);
  };
};

Object.defineProperty(exports, 'WithNotes', {
  configurable: true,
  enumerable: true,
  get: deprecate(
    () => ReactWithNotes,
    '@storybook/addon-notes WithNotes Component is deprecated, use withNotes() instead. See https://github.com/storybooks/storybook/tree/master/addons/notes'
  ),
});

@@ -191,20 +191,31 @@
 Notes = 
+(
 text
+, options)
  =%3E %7B%0A  
@@ -251,17 +251,16 @@
 nnel();%0A
-%0A
   return
@@ -277,32 +277,88 @@
 =%3E context =%3E %7B%0A
+    marked.setOptions(%7B ...marked.defaults, options %7D);%0A
     // send the 

add marked options