<template>
  <router-link
    class="ui-navmenu-item"
    :class="['ui-navmenu-item--' + type, 'is-' + theme]"
    :to="url"
  >
    <span
      class="ui-navmenu-item__icon"
      v-if="icon || $slots.icon"
      :style="iconStyle"
    >
      <slot name="icon"></slot>
    </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
    },
    theme() {
      return this.UiNavmenu.theme
    },
    iconStyle() {
      const sy = {}
      if (this.icon) {
        sy['background-image'] = `url(${this.icon})`
        if (this.iconSize) {
          sy.width = this.iconSize
          sy.height = this.iconSize
          sy['background-size'] = this.iconSize
        }
      }
      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;
  text-decoration: none;
  &.router-link-active {
    font-weight: bold;
  }
  &.is-dark {
    color: #131313;
    &.router-link-active {
      background-color: #DFEBFF;
      color: #3385FF;
    }
  }
  &.is-light{
    color: rgba(255, 255, 255, .7);
    &.router-link-active {
      background-color: #3385FF;
      color: #fff;
    }
  }
}
.ui-navmenu-item--weight{
  display: block;
  height: 32px;
  line-height: 32px;
  padding: 4px 18px;
  text-decoration: none;
  position: relative;
  transition: all .25s;
  display: flex;
  flex-direction: row;
  align-items: center;
  border-radius: 4px;
  &.router-link-active {
    background-color: #c7602d;
  }
  &.is-dark {
    color: #455166;
    &:hover {
      color: #131313;
    }
    &.router-link-active {
      background-color: #e4e8f0;
      color: #131313;
    }
  }
  &.is-light{
    color: rgba(255, 255, 255, .7);
    &:hover {
      color: #fff;
    }
    &.router-link-active {
      background-color: #c7602d;
      color: #fff;
    }
  }
}
.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%;
  svg {
    width: 100%;
    height: 100%;
  }
}
</style>
