import React, { Component } from 'react';

import { Button ,Modal } from "antd";

import axios from 'axios';

import { trace_collapse } from 'educoder'
const $ = window.$;

const { confirm } = Modal;
class RepositoryDirectories extends Component {
    constructor(props) {
        super(props)
        this.state = {

        }
	}
  componentDidMount() {
  }

  showDeleteConfirm =()=>{

    let that=this;

      confirm({
        title: '确认需要要删除该文件?',
        okText: '确定',
        cancelText: '取消',
        onOk() {
          that.onAttachmentRemove()
        }
      });

  }
  onAttachmentRemove=()=>{

    let shixunId = this.props.match.params.shixunId;
    let matchpath =this.props.match.path;
    let Repositoryflag =undefined;

    if( matchpath.indexOf("repository")>-1){
      Repositoryflag =undefined;
    }
    if(matchpath.indexOf("secret_repository")>-1){
      Repositoryflag =true;
    }

    let newfilspath=this.state.ischeckevalue;

    let path="";

    if(this.props.pathArray.length>0){
      this.props.pathArray.map((item,key)=>{
        if(key===0){
          path=item
        }else{
          path=path+"/"+item
        }
      })
    }

    if(path===undefined||path===""){
      path=newfilspath
    }else{
      path=path
    }

    const url = `/shixuns//${shixunId}/delete_git_file.json`;

    axios.delete(url, { data: {
        path:path,
        message:"删除"+path,
        secret_repository:Repositoryflag
      }})
      .then((response) => {
        if(response.data.status == 0) {
          this.props.showNotification("删除成功")
          this.props.oncodechanner()
        }
      })
      .catch(function (error) {

      });
  }
  render() {
    const { match, pathArray, fetchRepo,TPMRightSectionData
       } = this.props;
    let { RepositoryList } = this.state;
    return (
      <React.Fragment>

        { pathArray.length !== 0 &&
        <div className={this.props.tpmComment===true?" padding5-10 font-14 mb10":" bor-bottom-greyE padding5-10 font-14"}>
            <a className={this.props.tpmComment===true?"ml10 color888":"color-blue"}
            onClick={() => fetchRepo(0)}
            >
            {match.params.shixunId}
            </a>
            <span className={this.props.tpmComment===true?"color888 ml3 mr3":"ml3 mr3"}></span>
            { pathArray.map((item, index) => {

                return (
                  <React.Fragment>
                    { index===pathArray.length-1 && item.indexOf('.') === -1?<span className={"color888"}>
                      / {item} </span>:this.props.nameTypeMap[item] === 'tree' || item.indexOf('.') === -1
                      ? <a
                        onClick={() => fetchRepo(index + 1)}
                        className={this.props.tpmComment===true?"color888":"color-blue"}
                      >
                        / {item}</a>
                      :
                      <span  className={this.props.tpmComment===true?"color888":""}>
                       / {item}</span>
                    }
                    {index !== pathArray.length - 1 && <span className={this.props.tpmComment===true?"color888 ml3 mr3":"ml3 mr3"}></span>}
                  </React.Fragment>
                )

            })
            }
          {/*{ this.props.current_user && (this.props.current_user.admin ==true || (TPMRightSectionData && TPMRightSectionData.creator && TPMRightSectionData.creator.login == this.props.current_user.login)) ?*/}
          {/*  <Button size={"small"} className={"fr"} type="link" onClick={this.showDeleteConfirm}>删除</Button>:""}*/}
          <div className={"both"}></div>

        </div> }

      </React.Fragment>

    );
  }
}
export default RepositoryDirectories;
