"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

exports.__esModule = true;
exports.default = void 0;

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

var _info = _interopRequireDefault(require("../info"));

var _icon = _interopRequireDefault(require("../icon"));

var _create = _interopRequireDefault(require("../utils/create"));

var _router = require("../utils/router");

var _utils = require("../utils");

var _relation = require("../mixins/relation");

var _default = (0, _create.default)({
  render: function render() {
    var _vm = this;

    var _h = _vm.$createElement;

    var _c = _vm._self._c || _h;

    return _c('div', {
      class: _vm.b({
        active: _vm.myActive
      }),
      style: {
        color: _vm.color
      },
      on: {
        "click": _vm.onClick
      }
    }, [_c('div', {
      class: _vm.b('icon')
    }, [_vm._t("icon", [_vm.icon ? _c('Icon', {
      attrs: {
        "name": _vm.icon,
        "classPrefix": _vm.iconPrefix
      }
    }) : _vm._e()], {
      "active": _vm.myActive
    }), _c('Info', {
      attrs: {
        "dot": _vm.dot,
        "info": _vm.info || _vm.badge
      }
    })], 2), _c('div', {
      class: _vm.b('text')
    }, [_vm._t("default", null, {
      "active": _vm.myActive
    })], 2)]);
  },
  name: "tabbar-item",
  components: {
    Info: _info.default,
    Icon: _icon.default
  },
  mixins: [(0, _relation.ChildrenMixin)("vmTabbar")],
  props: (0, _extends2.default)({}, _router.routeProps, {
    dot: Boolean,
    icon: String,
    name: [Number, String],
    info: [Number, String],
    badge: [Number, String],
    iconPrefix: String
  }),
  data: function data() {
    return {
      active: false
    };
  },
  computed: {
    routeActive: function routeActive() {
      var to = this.to,
          $route = this.$route;

      if (to && $route) {
        var config = (0, _utils.isObj)(to) ? to : {
          path: to
        };
        var pathMatched = config.path === $route.path;
        var nameMatched = (0, _utils.isObj)(config.name) && config.name === $route.name;
        return pathMatched || nameMatched;
      }
    },
    color: function color() {
      return this.parents[this.myActive ? "activeColor" : "inactiveColor"];
    },
    myActive: function myActive() {
      return this.parents.route ? this.routeActive : this.active;
    }
  },
  methods: {
    onClick: function onClick(event) {
      this.parents.onChange(this.name || this.index);
      this.$emit("click", event);
      (0, _router.route)(this.$router, this);
    }
  }
});

exports.default = _default;