import { h, Component } from 'preact'
import { Link } from 'react-router-dom'

import Modal from '../Modal.jsx'

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

import FileUploadButton from './FileUploadButton.jsx'

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
    console.log(name, files)

    client.upload(this.props.folder.id, files).then( got_files => {
      console.log(got_files)
      this.props.addFiles(got_files)
    })
  }

  render() {
    console.log(this.props)
    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>+ file</span>
      </div>
    )
  }
}
