<script>
import Vue from 'vue'
export default {
  name: 'MenuItem',
  functional: true,
  props: {
    icon: {
      type: String,
      default: ''
    },
    title: {
      type: String,
      default: ''
    },
    hasChildren: {
      type: Boolean,
      default: false
    }
  },
  render(h, context) {
    const { icon, title, hasChildren } = context.props
    const vnodes = []

    if (icon) {
      vnodes.push(<div style='display: inline-block;'><svg-icon icon-class={icon}/></div>)
    }

    if (title) {
      let width = '130px'
      if (hasChildren) {
        // 当是父菜单时，为了使后面的三角能显示出来，需要将宽度设小点
        width = '100px'
      }
      const className = Vue.prototype.className
      if (className && className === 'blue2') {
        // blue2样式的左侧菜单宽度为240px
        width = '230px'
        if (hasChildren) {
        // 当是父菜单时，为了使后面的三角能显示出来，需要将宽度设小点
          width = '200px'
        }
      }
      vnodes.push(<div slot='title' style='display: inline-block'>
        <div title={title} style={'display: inline-block;width:' + width + ';overflow:hidden;text-overflow:ellipsis;white-space:nowrap;word-break:keep-all;'}>{(title)}</div>
      </div>)
    }
    return vnodes
  }
}
</script>
