<template>
  <component :is="url ? 'router-link' : 'div'" :to="url" class="ui-link-menu-item" :class="['ui-link-menu-item--' + type, { 'is-show-arrow': innerShowArrow }]" @click="handleClick">
    <div class="ui-link-menu-item__main">
      <span
        v-if="icon"
        class="ui-link-menu-item__icon"
        :style="{'background-image': `url(${icon})`}"
      ></span>
      <span
        class="ui-link-menu-item__label"
      >{{label}}</span>
      <span
        class="ui-link-menu-item__value"
      >{{value}}</span>
    </div>
    <span class="ui-link-menu-item__arrow">
      <ui-arrow dir="right" size="small" :type="type"></ui-arrow>
    </span>
  </component>
</template>
<script>
import UiArrow from '@huntianning/components/packages/arrow'

export default {
  name: 'UiLinkMenuItem',
  inject: ['UiLinkMenu'],
  components: {
    UiArrow
  },
  props: {
    label: {
      type: String
    },
    value: {
      type: [String, Number]
    },
    url: {
      type: String
    },
    icon: {
      type: String
    },
    showArrow: {
      type: Boolean
    }
  },
  computed: {
    type() {
      return this.UiLinkMenu.type
    },
    innerShowArrow() {
      return this.showArrow || !!this.url
    }
  },
  methods: {
    handleClick(evt) {
      this.$emit('click', evt)
    }
  }
}
</script>
<style lang="less">
a.ui-link-menu-item{
  text-decoration: none;
}
.ui-link-menu-item{
  height: 32px;
  line-height: 32px;
  padding: 4px 0 4px 12px;
  border-radius: 4px;
  display: flex;
  flex-direction: row;
  align-items: center;
  transition: all .25s;
  cursor: pointer;
  color: #131313;
  &.is-show-arrow {
    .ui-link-menu-item__arrow{
      display: block;
    }
  }
}
.ui-link-menu-item__icon{
  width: 16px;
  height: 16px;
  margin-right: 8px;
  background-repeat: no-repeat;
  background-size: 100%;
  background-position: 50% 50%;
}
.ui-link-menu-item__value {
  color: #FF871F;
  font-weight: bold;
  margin-left: 8px;
}
.ui-link-menu-item__main{
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: row;
  align-items: center;
}
.ui-link-menu-item--warning {
  &:hover {
    background-color: #fae4ce;
  }
}
.ui-link-menu-item__arrow{
  display: none;
}
</style>
