import * as React from 'react'
import Markdown, { ReactMarkdownProps } from 'react-markdown'

import 'github-markdown-css'

interface Props extends ReactMarkdownProps {
  asset?: { content: string }
}

interface State {}

export default class extends React.Component<Props, State> {
  state = {} as State

  render() {
    const { asset } = this.props
    let source: string

    if (asset) {
      source = new Buffer(asset.content, 'base64').toString('utf-8')
    }

    return (
      <article className="markdown-body">
        <Markdown source={source} {...this.props} />
      </article>
    )
  }
}
