<template>
    <abstract-button :href="href" :to="to" :tag="tag" :activeClass="activeClass"
        :event="event" :exact="exact" :append="append" :replace="replace"
        :disableTouchRipple="false" class="mu-buttom-item"
        :class="{'create-button': value=='create','mu-bottom-item-active': active, 'mu-bottom-item-simple':!icon, 'mu-bottom-item-reddot': reddot}"
        :center-ripple="false" wrapperClass="mu-buttom-item-wrapper"  @click.native="handleClick">

        <div class="semiCircle" v-if="value == 'create'"></div>
        <div class="semiCircle-shade" v-if="value == 'create'"></div>
        <icon class="mu-bottom-item-icon" :class="[active && value !== 'create'? icon + '-active' : icon]" v-if="icon"></icon>
        <slot></slot>
        <span v-if="title" class="mu-bottom-item-text" :class="[titleClass,{'create-text':value=='create'}]">{{title}}</span>
        <sub>
             <slot name='badge'></slot>
        </sub>
    </abstract-button>
</template>

<script>
import abstractButton from '../internal/abstractButton';

import icon from  '../chaos-icon/ChaosIcon';
import {isNotNull} from '../utils';
export default {
  name: 'mu-bottom-nav-item',

  props: {
    mode: {
      type: String,
    },
    to: {
      type: [String, Object]
    },
    tag: {
      type: String,
      default: 'a'
    },
    activeClass: {
      type: String,
      default: 'router-link-active'
    },
    event: {
      type: [String, Array],
      default: 'click'
    },
    reddot: {
      type: Boolean,
      default: false,
    },
    exact: Boolean,
    append: Boolean,
    replace: Boolean,
    icon: {
      type: String,
      default: ''
    },
    iconClass: {
      type: [String, Object, Array]
    },
    title: {
      type: String,
      default: ''
    },
    titleClass: {
      type: [String, Object, Array]
    },
    href: {
      type: String
    },
    value: {
        type: String
    }
  },
  data () {
    return {
      bottomNav: null
    }
  },
  created () {
    this.isBottomNavItem = true
  },
  computed: {
    active () {
      return this.bottomNav && isNotNull(this.value) && this.bottomNav.value === this.value
    },
    shift () {
      return this.bottomNav && this.bottomNav.shift
    },
  },
  methods: {
    handleClick () {
      if (this.bottomNav && this.bottomNav.handleItemClick) this.bottomNav.handleItemClick(this.value,this.index)
    }
  },
  mounted () {
    let children = this.$parent.$children
    for (let i = 0; i < children.length; i++) {
      if (children[i].$el === this.$el) {
        this.index = i
        break
      }
    }
  },
  components: {
    'abstract-button': abstractButton,
    icon
  }
}
</script>

<style lang="less">
@import "../styles/import.less";

.mu-buttom-item {
  flex: 1;
  position: relative;
  height: 100%;
  color: @secondaryTextColor;
  padding: 0;
  background: none;
  appearance: none;
  text-decoration: none;
  border: none;
  outline: none;
  transition: all .4s @easeInOutFunction;
  user-select: none;
  padding-top: 7px;
  padding-bottom: 4px;
  .mu-bottom-nav-shift & {
    color: fade(@alternateTextColor, 70%);
    padding: 8px 12px 10px;
    min-width: 56px;
    max-width: 168px;
  }
}
.mu-buttom-item-wrapper {
  display: block;
  height: 100%;
  overflow:hidden;
  margin-top: 1px;
}
.mu-bottom-item-active {
  .mu-bottom-nav-shift & {
    flex: 1.7;
    min-width: 96px;
    max-width: 168px;
    padding-top: 6px;
    padding-bottom: 5px;
  }
}

.mu-bottom-item-text{
  display: block;
  text-align: center;
  font-size: 10px;
  margin-top: 4px;
  backface-visibility: hidden;
  &.create-text {
      position: absolute;
      left: 0;
      right: 0;
      top: 9px;
  }
  .mu-bottom-item-active &{
    color: #2196f3;
  }
  .mu-bottom-nav-shift .mu-bottom-item-active &{
    color: @alternateTextColor;
  }
  .mu-bottom-nav-shift & {
    opacity: 0;
    transform: scale(1) translate3d(0, 6px, 0);
  }
  .mu-bottom-nav-shift .mu-bottom-item-active & {
    transform: scale(1) translate3d(0, 2px, 0);
    opacity: 1;
  }
}
.mu-bottom-item-icon {
  font-size: 20px;
  display: block;
  margin: auto;
  transition: all .45s @easeOutFunction;
  backface-visibility: hidden;
  width: 21px;
  height: 18px;
  display: inline-flex;
  &:before {
      top: 2px;
      position: relative;
  }

  .mu-bottom-nav-shift & {
    transform: translate3d(0, 8px, 0);
  }
  .mu-bottom-nav-shift .mu-bottom-item-active & {
    transform: scale(1) translateZ(0);
  }
  &.m-sys-xinjian {
      font-size: 42px;
      width: 43px;
      height: 44px;
      line-height: 44px;
      position: absolute;
      z-index:999;
      top: 0;
      left: 1px;
      right: 0;
      top: -35px;
  }
}
.mu-bottom-item-simple .mu-buttom-item-wrapper {
    line-height:38px;
    height: 38px;
}
.mu-bottom-item-reddot:after {
    content: "";
    position: absolute;
    display: block;
    width: 8px;
    height: 8px;
    border-radius: 5px;
    background-clip: padding-box;
}
.mu-bottom-item-reddot:after {
    background-color: #f74c31;
    right: 35px;
    top: 3px;
}
.semiCircle {
    left: 0;
    right: 0;
    position: absolute;
    width: 50px;
    height: 25px;
    top: -39px;
    margin: 0 auto;
    background: #fafafa;
    border-top-left-radius: 100px;
    border-top-right-radius: 100px;
    border-bottom-right-radius: 0;
    border-bottom-left-radius: 0;
    box-shadow: 0px 0px 3px 0px rgba(0, 0, 0, 0.1);
}
.semiCircle-shade {
height: 20px;
position: absolute;
z-index: 1;
width: 100%;
top: -22px;
background: #fafafa;
}
</style>
