"use strict";var _baseComponent=_interopRequireDefault(require("../helpers/baseComponent")),_classNames3=_interopRequireDefault(require("../helpers/libs/classNames"));function _interopRequireDefault(t){return t&&t.__esModule?t:{default:t}}function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function ownKeys(e,t){var r,n=Object.keys(e);return Object.getOwnPropertySymbols&&(r=Object.getOwnPropertySymbols(e),t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)),n}function _objectSpread(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?ownKeys(Object(r),!0).forEach(function(t){_defineProperty(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):ownKeys(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function _defineProperty(t,e,r){return(e=_toPropertyKey(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function _toPropertyKey(t){t=_toPrimitive(t,"string");return"symbol"==_typeof(t)?t:String(t)}function _toPrimitive(t,e){if("object"!=_typeof(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0===r)return("string"===e?String:Number)(t);r=r.call(t,e||"default");if("object"!=_typeof(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}var EMPTY="empty",LOADING="loading",LOADED="loaded",ERROR="error",UNMOUNTED="unmounted",calcStyle=function(t){return"number"==typeof t?"".concat(t,"px"):t};(0,_baseComponent.default)({properties:{prefixCls:{type:String,value:"wux-image"},src:{type:String,value:""},mode:{type:String,value:"scaleToFill"},webp:{type:Boolean,value:!1},lazyLoad:{type:Boolean,value:!1},showMenuByLongpress:{type:Boolean,value:!1},shape:{type:String,value:"normal"},width:{type:null,value:300},height:{type:null,value:225},unmountOnEmpty:{type:Boolean,value:!1},unmountOnError:{type:Boolean,value:!1},empty:{type:String,value:""},loading:{type:String,value:""},error:{type:String,value:""}},data:{status:""},computed:{classes:["prefixCls, shape, mode, status, empty, loading, error",function(t,e,r,n,o,a,i){return{wrap:(0,_classNames3.default)(t,_defineProperty(_defineProperty(_defineProperty({},"".concat(t,"--").concat(e),e),"".concat(t,"--").concat(r),r),"".concat(t,"--").concat(n),n)),inner:"".concat(t,"__inner"),thumb:"".concat(t,"__thumb"),mask:(0,_classNames3.default)("".concat(t,"__mask"),_defineProperty({},"".concat(t,"__mask--text"),o||a||i)),text:"".concat(t,"__text")}}]},observers:_defineProperty({src:function(t){this.updated(t)}},"width, height",function(){this.updateStyle.apply(this,arguments)}),methods:{updated:function(t){this.updateStatus(t?LOADING:this.data.unmountOnEmpty?UNMOUNTED:EMPTY)},updateStyle:function(t,e){t="width: ".concat(calcStyle(t),"; height: ").concat(calcStyle(e));this.setData({style:t})},updateStatus:function(t){this.data.status!==t&&this.setData({status:t}),this.triggerEvent("change",{status:t})},onLoad:function(t){this.updateStatus(LOADED),this.triggerEvent("load",_objectSpread(_objectSpread({},t.detail),{},{status:LOADED}))},onError:function(t){var e=this.data.unmountOnError?UNMOUNTED:ERROR;this.updateStatus(e),this.triggerEvent("error",_objectSpread(_objectSpread({},t.detail),{},{status:e}))},onTap:function(t){this.triggerEvent("click",_objectSpread(_objectSpread({},t.detail),{},{status:this.data.status}))}},attached:function(){var t=this.data,e=t.width,r=t.height,t=t.src;this.updateStyle(e,r),this.updated(t)}});