import React, { Component } from 'react'

import Check from './Check'

import { ACCEPTED_LICENSES } from '../../../../helpers/dataGouvChecks'

class CheckLicense extends Component {
  check() {
    const { license } = this.props
    let msg = ''
    let content = (
      <div>
        Les licenses reconnue sont :
        <ul>
          { Object.keys(ACCEPTED_LICENSES).map( (licence, idx) => <li key={idx}>{licence.name}</li>) }
        </ul>
      </div>
    )

    if (!license) {
      msg = 'Aucune licence n\'a pu être trouvée.'
    } else if (ACCEPTED_LICENSES[license]) {
      msg = `La licence ${ACCEPTED_LICENSES[license].name} est valide.`
      content = undefined
    } else {
      msg = `La licence ${license} n'est pas reconnue.`
    }

    return {msg, content}
  }

  render() {
    const { valid } = this.props
    const { msg, content } = this.check()

    return (
      <Check title='Licence' isValid={valid} msg={msg}>
        {content}
      </Check>
      )
    }
}

export default CheckLicense

@@ -368,17 +368,16 @@
 ES).map(
- 
 (licence
@@ -390,41 +390,141 @@
  =%3E 
-%3Cli key=%7Bidx%7D%3E%7Blicence.name%7D%3C/li%3E
+%7B%0A            const li = ACCEPTED_LICENSES%5Blicence%5D%0A            return %3Cli key=%7Bidx%7D%3E%3Ca href=%7Bli.link%7D%3E%7Bli.name%7D%3C/a%3E%3C/li%3E%0A          %7D
 ) %7D%0A

Fix accepted licences list