import {Component,render,createElement} from 'rax';
import "./index.less";
import App from '../App';
export default class FileListItem extends Component{
  constructor(props){
    super(props);
    this.state={
      chacked:false
    }
    App.inst.itemComs.push(this);
  }


  

  checked=()=>{
    
    if(App.inst.checked){
      App.inst.checked.unChecked();
    }
    App.inst.checked = this;
    this.setState({
      checked:true
    })
    App.inst.onEnterFile(this.props.data.msg.folderName);
  }

  unChecked=()=>{
    App.inst.checked = null;
    this.setState({
      checked:false
    })
  }

  getFolderName(){
    return this.props.data.msg.folderName;
  }

  delete=()=>{
    let isDelete = confirm("确定删除"+this.props.data.msg.folderName+"文件吗");
    if(isDelete){
      App.inst.deleteFolder(this.props.data.msg.folderName,()=>{
        App.inst.checked && App.inst.checked===this && App.inst.checked.unChecked();
      });
    }
  }

  render(){
    return (
      <div className={"fl_box"} style={{backgroundColor:this.state.checked?"#ff0000": this.props.data.bgColor}}>
        <div className={"fl_leftName"} onClick={this.checked} >
          {this.props.data.msg.folderName}
        </div>
        <input className={"fl_delete"} type="button" value="删除" onClick={this.delete} />
      </div>
    )
  }
}