import React, { Component } from 'react'
import Accordion from '../Accordion/Accordion'
import CheckItem from './CheckItem'

class DatasetDataAvailability extends Component {
  check() {
    const distributions = this.props.distributions

    if (!!distributions && distributions.some((distribution) => distribution.available)) {
      return {
        valid: true,
        msg: 'Au moins une des distribution est disponible.',
        content: distributions.map((distribution, idx) => <CheckItem key={idx} name={distribution.typeName || distribution.layer} valid={distribution.available} />),
      }
    }

    return {msg: 'Aucune distribution n\'a été trouvée.', valid: false}
  }

  render() {
    const check = this.check()

    return <Accordion
              title={<CheckItem name={'Disponibilité de la donnée'} valid={check.valid} />}
              content={check.content}
              msg={check.msg} />
    }
}

export default DatasetDataAvailability

@@ -483,35 +483,33 @@
  =%3E 
-%3CCheckItem key=%7Bidx%7D
+%7B%0A          const
  name
-=%7B
+ = 
 dist
@@ -547,16 +547,86 @@
 on.layer
+ %7C%7C distribution.name%0A          return %3CCheckItem key=%7Bidx%7D name=%7Bname
 %7D valid=
@@ -652,16 +652,26 @@
 able%7D /%3E
+%0A        %7D
 ),%0A     

Fix distribution name when distribution is non vector