import React from 'react'
import { TextAreaApp } from 'tracim_frontend_lib'
import { MODE } from '../helper.js'

const HtmlDocument = props => {
  return (
    <div className='wsContentHtmlDocument__contentpage__textnote html-document__contentpage__textnote'>
      {props.isArchived &&
        <div className='html-document__contentpage__textnote__state'>
          <div className='html-document__contentpage__textnote__state__msg'>
            <i className='fa fa-fw fa-archive' />
            This content is archived.
          </div>

          <button className='html-document__contentpage__textnote__state__btnrestore btn' onClick={props.onClickRestoreArchived}>
            <i className='fa fa-fw fa-archive' />
            Restore
          </button>
        </div>
      }

      {props.isDeleted &&
        <div className='html-document__contentpage__textnote__state'>
          <div className='html-document__contentpage__textnote__state__msg'>
            <i className='fa fa-fw fa-trash' />
            Ce contenu est supprimé.
          </div>

          <button className='html-document__contentpage__textnote__state__btnrestore btn' onClick={props.onClickRestoreDeleted}>
            <i className='fa fa-fw fa-trash' />
            Restore
          </button>
        </div>
      }

      {(props.mode === MODE.VIEW || props.mode === MODE.REVISION) &&
        <div>
          <div className='html-document__contentpage__textnote__version'>
            version n°
            <div dangerouslySetInnerHTML={{__html: props.mode === MODE.VIEW ? props.lastVersion : props.version}} />
            {props.mode === MODE.REVISION &&
              <div className='html-document__contentpage__textnote__lastversion'>
                (dernière version : {props.lastVersion})
              </div>
            }
          </div>
          {/* need try to inject html in stateless component () => <span>{props.text}</span> */}
          <div className='html-document__contentpage__textnote__text' dangerouslySetInnerHTML={{__html: props.text}} />
        </div>
      }

      {props.mode === MODE.EDIT &&
        <TextAreaApp
          id={props.wysiwygNewVersion}
          customClass={'html-document__editionmode'}
          customColor={props.customColor}
          onClickCancelBtn={props.onClickCloseEditMode}
          onClickValidateBtn={props.onClickValidateBtn}
          text={props.text}
          onChangeText={props.onChangeText}
        />
      }
    </div>
  )
}

export default HtmlDocument
