"use strict";var _baseComponent=_interopRequireDefault(require("../helpers/baseComponent")),_classNames2=_interopRequireDefault(require("../helpers/libs/classNames")),_styleToCssString=_interopRequireDefault(require("../helpers/libs/styleToCssString")),_safeAreaBehavior=require("../helpers/mixins/safeAreaBehavior");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function ownKeys(t,e){var r,n=Object.keys(t);return Object.getOwnPropertySymbols&&(r=Object.getOwnPropertySymbols(t),e&&(r=r.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,r)),n}function _objectSpread(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?ownKeys(Object(r),!0).forEach(function(e){_defineProperty(t,e,r[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):ownKeys(Object(r)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))})}return t}function _defineProperty(e,t,r){return(t=_toPropertyKey(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function _toPropertyKey(e){e=_toPrimitive(e,"string");return"symbol"==_typeof(e)?e:String(e)}function _toPrimitive(e,t){if("object"!=_typeof(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0===r)return("string"===t?String:Number)(e);r=r.call(e,t||"default");if("object"!=_typeof(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}(0,_baseComponent.default)({relations:{"../tabbar-item/index":{type:"child",observer:function(){this.callDebounceFn(this.updated)}}},properties:_objectSpread({prefixCls:{type:String,value:"wux-tabbar"},defaultCurrent:{type:String,value:""},current:{type:String,value:""},controlled:{type:Boolean,value:!1},theme:{type:String,value:"balanced"},backgroundColor:{type:String,value:"#fff"},position:{type:String,value:""}},_safeAreaBehavior.safeAreaProps),data:{tabbarStyle:"",activeKey:"",keys:[]},computed:{classes:["prefixCls, position",function(e,t){return{wrap:(0,_classNames2.default)(e,_defineProperty({},"".concat(e,"--").concat(t),t)),tabbar:"".concat(e,"-wrap")}}]},observers:{current:function(e){this.data.controlled&&this.updated(e)},backgroundColor:function(e){this.updateStyle(e)}},methods:{updated:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:this.data.activeKey;this.data.activeKey!==e&&this.setData({activeKey:e}),this.changeCurrent(e)},changeCurrent:function(r){var n=this,o=this.getRelationsByName("../tabbar-item/index");0<o.length&&o.forEach(function(e,t){t=e.data.key||String(t);e.changeCurrent(t===r,t,n.data.theme,o.length)}),this.data.keys.length!==o.length&&this.setData({keys:o.map(function(e){return e.data})})},emitEvent:function(e){this.triggerEvent("change",{key:e,keys:this.data.keys})},setActiveKey:function(e){this.data.controlled||this.updated(e),this.emitEvent(e)},updateStyle:function(e){e=(0,_styleToCssString.default)({backgroundColor:e});e!==this.data.tabbarStyle&&this.setData({tabbarStyle:e})}},ready:function(){var e=this.data,t=e.defaultCurrent,r=e.current,n=e.controlled,e=e.backgroundColor;this.updated(n?r:t),this.updateStyle(e)}});