import { h, Component } from 'preact'

import client from '../../../client.js'

export default class Folder extends Component {
  constructor(props) {
    super()
    this.state = {
    }
    this.updateFiles = this.updateFiles.bind(this)
  }
  updateFiles(event){
    const name = event.target.name
    const files = event.target.files
    client.upload(this.props.folder.id, files).then( got_files => {
      this.props.addFiles(got_files)
    })
  }

  render() {
    const files = (this.props.folder.files || []).map( (file, i) => {
      return (
        <div key={i}>
          {file.name}
        </div>
      )
    })
    return (
      <div class='fileUploadButton'>
        <input type='file' multiple name='files' onChange={this.updateFiles} />
        <span>+ upload</span>
      </div>
    )
  }
}
