<template>
  <router-link
    class="ui-navmenu-item"
    :class="['ui-navmenu-item--' + type]"
    :to="url"
  >
    <span
      class="ui-navmenu-item__icon"
      v-if="icon"
      :style="iconStyle"
    >
    </span>
    <slot />
  </router-link>
</template>
<script>
export default {
  name: 'UiNavmenuItem',
  inject: ['UiNavmenu'],
  props: {
    url: {
      type: String,
      default: ''
    },
    icon: {
      type: String
    },
    iconSize: {
      type: String,
      default: '20px'
    }
  },
  computed: {
    type() {
      return this.UiNavmenu.type
    },
    iconStyle() {
      const sy = {}
      if (this.iconSize) {
        sy.width = this.iconSize
        sy.height = this.iconSize
        sy['background-size'] = this.iconSize
      }
      if (this.icon) {
        sy['background-image'] = `url(${this.icon})`
      }
      return sy
    }
  }
}
</script>
<style lang="less">
.ui-navmenu-item--simple{
  display: block;
  height: 32px;
  line-height: 32px;
  padding: 1px 15px;
  margin: 3px 0;
  border-radius: 5px;
  color: #131313;
  text-decoration: none;
  &.router-link-active {
    background-color: #DFEBFF;
    color: #3385FF;
    font-weight: bold;
  }
}
.ui-navmenu-item--weight{
  display: block;
  height: 32px;
  line-height: 32px;
  padding: 4px 18px;
  text-decoration: none;
  position: relative;
  transition: all .25s;
  color: #455166;
  display: flex;
  flex-direction: row;
  align-items: center;
  &:hover {
    color: #131313;
  }
  &.router-link-active {
    background-color: #e4e8f0;
    color: #131313;
    &:after {
      top: 0;
      bottom: 0;
      opacity: 1;
    }
  }
  &:after {
    content: '';
    position: absolute;
    top: 30%;
    bottom: 30%;
    left: 0;
    transition: all .25s;
    opacity: 0;
    background-color: #3385FF;
    width: 3px;
  }
}
.ui-navmenu-item{
  display: flex;
  flex-direction: row;
  align-items: center;
}
.ui-navmenu-item__icon{
  display: inline-block;
  width: 20px;
  height: 20px;
  margin-right: 6px;
  line-height: 1em;
  background-repeat: no-repeat;
  background-position: 50% 50%;
}
</style>
