import React, { Component } from 'react';
import { Dropdown } from 'antd';
import { Link } from 'react-router-dom';
import Nav from '../NavComponent/Index';


class ModeratorNav extends Component {

  render(){
    const { current_user , bread_crumb }=this.props;

    const forum_tag = bread_crumb && bread_crumb.forum_tag;
    const forum = bread_crumb && bread_crumb.forum;
    // {
    //     name:current_user && current_user.username,
    //     url:`/users/${current_user && current_user.login}`
    //   },
    const routerMap = [
      {
        name: forum && forum.title,
        url:"/forums"
      },
      {
        url:`/forums/theme/${forum_tag && forum_tag.id}`,
        name:forum_tag && forum_tag.title
      },
      {
        url:`/forums/theme/${forum_tag && forum_tag.children_bread_crumb && forum_tag.children_bread_crumb.id}`,
        name:forum_tag && forum_tag.children_bread_crumb && forum_tag.children_bread_crumb.title
      },{
        name:"版主管理"
      }
    ]; 

    // 板块导航dropdown显示内容
    const menu =(item)=> {
      // console.log("item",item);

      if(item){
        return(
        <div className="platePanel">
          <div className="plateItem">
            <ul className="plateUl ">
              {
                item.map((i,key)=>{
                  return(<li key={key}><Link to={`/forums/manage/${i.id}`}>{i.title}</Link></li>)
                })
              }
            </ul>
          </div>
        </div>
        )
      }
    }
   
    const titleFlag = () => {
      if (forum_tag ) {
        console.log(forum_tag.children_bread_crumb);
        if (bread_crumb && bread_crumb.is_children) {
          return (<div className="padding20-30 edu-back-white font-22 mb20">{forum_tag.children_bread_crumb && forum_tag.children_bread_crumb.title}</div>)
        } else {

          return (
            <div className="padding20-30 edu-back-white font-22 mb20">
              { forum_tag.children_bread_crumb ?
                <Dropdown overlay={menu(forum_tag.children_bread_crumb) } >
                  <div>{forum_tag.title}<i className="iconfont icon-xiajiantou font-16 ml10 color-dark-grey"></i></div>
                </Dropdown>
                :
                <span>{forum_tag.title}</span>
              }
            </div>
          )
        }
      }
      
    }
    return(
      <div>
        <Nav className="mt20 mb30" NavMap = {routerMap} ></Nav>
        {titleFlag()}
      </div>
    )
  }
}

export default ModeratorNav;