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

import Modal from '../Modal.jsx'

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

export default class Folder extends Component {
  constructor(props) {
    super()
    this.state = {
      adding: false,
    }
  }
  toggle(folder) {
    folder.open = ! folder.open
    if (folder.open && ! folder.files) {
      client.files.index({ 'folder_id': folder.id }).then( files => {
        this.props.openFolder(folder)
      })
    }
  }
  render() {
    console.log(this.props)
    const folders = (this.props.folders || []).map( (folder,i) => {
      return (
        <div key={i} onClick={() => this.toggle(folder)}>
          {folder.name}
        </div>
      )
    })
    return (
      <div class='folders'>
        <b>{this.props.folder.name}</b> <button onClick={() => {}}>+ file</button>
        {folders}
      </div>
    )
  }
}
