/**
 * Copyright 2019 Google LLC
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * version 3 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 */

import { EventEmitter } from 'events'
import Tone, { Buffer } from 'tone'
import FileReader from 'promise-file-reader'
import { html, render } from 'lit-html'
import { FileDrop } from '../interface/FileDrop'

export class Upload extends EventEmitter {
	constructor(){
		super()

		this.fileDrop = new FileDrop('buffer')
		this.fileDrop.on('dropped', () => this.emit('dropped'))
		this.fileDrop.on('file', this._readFile.bind(this))
	}

	click(){
		this.fileDrop.openDialog()
	}

	_readFile(file, buffer){
		this.emit('buffer', buffer)
	}

	set disabled(d){
		this.fileDrop.disabled = d
	}

	get buttonElement(){
		return this.fileDrop.element
	}
}
