const Editor = require('simplemde')
const $ = require('jquery')

module.exports = () => {
  const elements = $('textarea[data-simplemde]')

  elements.each((i, element) => {
    $(element).removeClass('form-control')

    new Editor({
      element: element,
      forceSync: true,
      autoDownloadFontAwesome: false,
      spellChecker: false,
      styleSelectedText: false,
      toolbar: [
        {
          name: 'bold',
          action: Editor.toggleBold,
          className: 'fa fa-bold',
          title: 'Bold'
        },
        {
          name: 'italic',
          action: Editor.toggleItalic,
          className: 'fa fa-italic',
          title: 'Italic'
        },
        {
          name: 'heading',
          action: Editor.toggleHeadingSmaller,
          className: 'fa fa-heading',
          title: 'Heading'
        },
        '|',
        {
          name: 'quote',
          action: Editor.toggleBlockquote,
          className: 'fa fa-quote-left',
          title: 'Quote'
        },
        {
          name: 'unordered-list',
          action: Editor.toggleUnorderedList,
          className: 'fa fa-list-ul',
          title: 'Generic List'
        },
        {
          name: 'ordered-list',
          action: Editor.toggleOrderedList,
          className: 'fa fa-list-ol',
          title: 'Numbered List'
        },
        {
          name: 'table',
          action: Editor.drawTable,
          className: 'fa fa-table',
          title: 'Insert Table'
        },
        '|',
        {
          name: 'link',
          action: Editor.drawLink,
          className: 'fa fa-link',
          title: 'Create Link'
        },
        {
          name: 'image',
          action: Editor.drawImage,
          className: 'fa fa-image',
          title: 'Insert Image'
        },
        '|',
        {
          name: 'preview',
          action: Editor.togglePreview,
          className: 'fa fa-eye no-disable',
          title: 'togglePreview'
        },
        {
          name: 'side-by-side',
          action: Editor.toggleSideBySide,
          className: 'fa fa-columns no-disable no-mobile',
          title: 'Toggle Side by Side'
        },
        {
          name: 'fullscreen',
          action: Editor.toggleFullScreen,
          className: 'fa fa-arrows-alt no-disable no-mobile',
          title: 'Toggle Fullscreen'
        }
      ]
    })
  })
}
