import React from 'react'

export default class App extends React.Component {
  constructor(props) {
    super()
    this.state = {
      prints: []
    }
    fetch('/_services/awprint/index')
    .then( res => {
      return res.json()
    }).then( prints => {
      this.setState({ prints })
    }).catch( e => {
      console.error(e)
    })
  }
  render() {
    const prints = this.state.prints.map( (print,i) => {
      const className = print.printed ? 'print printed' : 'print'
      const date = print.date.replace(/T/,' - ').replace(/:\d\d\..*/,'')
      return (
        <div key={i} className={className} onClick={() => this.print(print)}>
          <img src={print.url} />
          <div className='date'>{date}</div>
        </div>
      )
    })
    return (
      <div>
        {prints}
      </div>
    )
  }
}