import React from 'react';
import { Modal, Button, Menu, Dropdown, Icon } from 'antd';

export default props => {
  const handleMenuClick = e => {
    if (e.key === 'add') {
      props.onAdd(props.data)
    } else {
      Modal.confirm({
        title: '删除',
        content: '确认进行此操作?',
        onOk: () => {
          props.onDelete(props.data)
        }
      })
    }
  }

  const menu = (
    <Menu onClick={handleMenuClick}>
      {
        props.data.type !== 'end' && (<Menu.Item key="add">增加子节点</Menu.Item>)
      }
      <Menu.Item key="delete">删除</Menu.Item>
    </Menu>
  );

  return (
    <Dropdown overlay={menu} size="small">
      <Button type="link" size="small">
        <span>{props.data.name}</span>
        <Icon type="edit" />
      </Button>
    </Dropdown>
  )
}
