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

    if (icon) {
      vnodes.push(<svg-icon icon-class={icon} />)
    }

    if (title) {
      // Only show tooltip for potentially truncated titles
      if (title.length > 4) {
        vnodes.push(
          <el-tooltip slot='title' effect='dark' placement='right' content={title}>
            <span class='menu-title' title={title}>{title}</span>
          </el-tooltip>
        )
      } else {
        vnodes.push(<span slot='title' class='menu-title'>{title}</span>)
      }
    }
    return vnodes
  }
}
</script>
