"use strict";var _baseComponent=_interopRequireDefault(require("../helpers/baseComponent")),_classNames=_interopRequireDefault(require("../helpers/libs/classNames")),_index=require("./core/index"),_index2=_interopRequireDefault(require("./locales/index"));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}(0,_baseComponent.default)({properties:{prefixCls:{type:String,value:"wux-timeago"},to:{type:null,value:null,observer:function(e){var t=this.data,r=t.from,t=t.lang;this.updated(e,r,t)}},from:{type:null,value:null,observer:function(e){var t=this.data,r=t.to,t=t.lang;this.updated(r,e,t)}},refreshable:{type:Boolean,value:!1,observer:function(e){var t=this.data,r=t.to,a=t.from,t=t.lang;this.updated(r,a,t,!0)}},lang:{type:String,value:"zh_CN",observer:function(e){var t=this.data,r=t.to,t=t.from;this.updated(r,t,e,!0)}}},data:{currentTo:null,currentFrom:null,timeago:null},methods:{updated:function(t,r,a,e){var i=this;this.clearTimer(),t===this.data.currentTo&&r===this.data.currentFrom&&!e||(e=(0,_index.diff)(t,r),e=(0,_index.format)(e,_index2.default[a]),this.setData({currentTo:t,currentFrom:r,timeago:e},function(){var e;i.data.refreshable&&!i.data.from&&(e=(0,_index.diff)(t,r,"minute"),i.timeout=setTimeout(function(){i.updated(t,i.getNow(),a)},1e3*((e<1?1:e<60&&30)||(e<180?300:3600))))}))},clearTimer:function(){this.timeout&&(clearTimeout(this.timeout),this.timeout=null)},getNow:function(){var e=this.data.from;return e?(0,_index.parse)(e):new Date}},detached:function(){this.clearTimer()}});