"use strict";

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

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

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

var _interceptor = require("../utils/interceptor");

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

var _default = (0, _create.default)({
  render: function render() {
    var _obj, _obj$1;

    var _vm = this;

    var _h = _vm.$createElement;

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

    return _c('div', [_vm.placeholder && _vm.fixed ? _c('div', {
      class: _vm.b('placeholder'),
      style: {
        height: _vm.height + "px"
      }
    }, [_c('div', {
      ref: "tabbar",
      class: [(_obj = {}, _obj['vm-hairline--top-bottom'] = _vm.border, _obj), _vm.b({
        unfit: !_vm.fit,
        fixed: _vm.fixed
      })],
      style: {
        zIndex: _vm.zIndex
      }
    }, [_vm._t("default")], 2)]) : _c('div', {
      ref: "tabbar",
      class: [(_obj$1 = {}, _obj$1['vm-hairline--top-bottom'] = _vm.border, _obj$1), _vm.b({
        unfit: !_vm.fit,
        fixed: _vm.fixed
      })],
      style: {
        zIndex: _vm.zIndex
      }
    }, [_vm._t("default")], 2)]);
  },
  name: "tabbar",
  mixins: [(0, _relation.ParentMixin)("vmTabbar")],
  data: function data() {
    return {
      height: null
    };
  },
  props: {
    route: Boolean,
    zIndex: [Number, String],
    placeholder: Boolean,
    activeColor: String,
    beforeChange: Function,
    inactiveColor: String,
    value: {
      type: [Number, String],
      default: 0
    },
    border: {
      type: Boolean,
      default: true
    },
    fixed: {
      type: Boolean,
      default: true
    },
    safeAreaInsetBottom: {
      type: Boolean,
      default: null
    }
  },
  mounted: function mounted() {
    if (this.placeholder && this.fixed) {
      this.height = this.$refs.tabbar.getBoundingClientRect().height;
    }
  },
  computed: {
    fit: function fit() {
      if (this.safeAreaInsetBottom !== null) {
        return this.safeAreaInsetBottom;
      } // enable safe-area-inset-bottom by default when fixed


      return this.fixed;
    }
  },
  watch: {
    value: "setActiveItem",
    children: "setActiveItem"
  },
  methods: {
    setActiveItem: function setActiveItem() {
      var _this = this;

      this.children.forEach(function (item, index) {
        item.active = (item.name || index) === _this.value;
      });
    },
    onChange: function onChange(active) {
      var _this2 = this;

      if (active !== this.value) {
        (0, _interceptor.callInterceptor)({
          interceptor: this.beforeChange,
          args: [active],
          done: function done() {
            _this2.$emit("input", active);

            _this2.$emit("change", active);
          }
        });
      }
    }
  }
});

exports.default = _default;