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,
      imgSrc1: './image/fileicon.png'
    };
    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 = () => {
    console.log('子文件删除');
    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 ? '#f5f5f5' : this.props.data.bgColor }}>
        <div className={'fl_leftName'} onClick={this.checked} >
          <img src={this.state.imgSrc1} alt="" />
          {this.props.data.msg.folderName}
        </div>
        <div className={'delete_box'}>
          <input className={'fl_delete'} type="button" value="删除" onClick={this.delete} />
        </div>
      </div>
    );
  }
}