"use strict";var _baseComponent=_interopRequireDefault(require("../helpers/baseComponent")),_classNames2=_interopRequireDefault(require("../helpers/libs/classNames")),_styleToCssString=_interopRequireDefault(require("../helpers/libs/styleToCssString"));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 o,n=Object.keys(t);return Object.getOwnPropertySymbols&&(o=Object.getOwnPropertySymbols(t),e&&(o=o.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,o)),n}function _objectSpread(t){for(var e=1;e<arguments.length;e++){var o=null!=arguments[e]?arguments[e]:{};e%2?ownKeys(Object(o),!0).forEach(function(e){_defineProperty(t,e,o[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(o)):ownKeys(Object(o)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(o,e))})}return t}function _defineProperty(e,t,o){return(t=_toPropertyKey(t))in e?Object.defineProperty(e,t,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[t]=o,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 o=e[Symbol.toPrimitive];if(void 0===o)return("string"===t?String:Number)(e);o=o.call(e,t||"default");if("object"!=_typeof(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}(0,_baseComponent.default)({properties:{prefixCls:{type:String,value:"wux-search-bar"},defaultValue:{type:String,value:""},value:{type:String,value:"",observer:function(e){this.data.controlled&&this.updated(e)}},placeholder:{type:String,value:"搜索"},placeholderStyle:{type:[String,Object],value:"",observer:function(e){this.setData({extStyle:(0,_styleToCssString.default)(e)})}},placeholderClass:{type:String,value:"input-placeholder"},disabled:{type:Boolean,value:!1},maxlength:{type:Number,value:140},cursorSpacing:{type:Number,value:11},focus:{type:Boolean,value:!1,observer:function(e){this.setData({inputFocus:e})}},confirmType:{type:String,value:"search"},confirmHold:{type:Boolean,value:!1},cursor:{type:Number,value:-1},selectionStart:{type:Number,value:-1},selectionEnd:{type:Number,value:-1},adjustPosition:{type:Boolean,value:!0},clear:{type:Boolean,value:!1},cancelText:{type:String,value:"取消"},showCancel:{type:Boolean,value:!1},controlled:{type:Boolean,value:!1},onlyShowClearWhenFocus:{type:Boolean,value:!0}},data:{inputValue:"",inputFocus:!1,shouldShowClear:!1,extStyle:""},observers:_defineProperty({},"clear, disabled, inputValue, inputFocus, onlyShowClearWhenFocus",function(){for(var e=arguments.length,t=new Array(e),o=0;o<e;o++)t[o]=arguments[o];var n=t[0],r=t[1],a=t[2],i=t[3],u=t[4];this.setClear({clear:n,disabled:r,inputValue:a,inputFocus:i,onlyShowClearWhenFocus:u})}),computed:{classes:["prefixCls, disabled, inputFocus",function(e,t,o){return{wrap:(0,_classNames2.default)(e,_defineProperty(_defineProperty({},"".concat(e,"--focus"),o),"".concat(e,"--disabled"),t)),form:"".concat(e,"__form"),box:"".concat(e,"__box"),search:"".concat(e,"__search"),input:"".concat(e,"__input"),clear:"".concat(e,"__clear"),label:"".concat(e,"__label"),icon:"".concat(e,"__icon"),text:"".concat(e,"__text"),cancel:"".concat(e,"__cancel")}}]},methods:{setClear:function(e){e=!(!e.clear||!e.inputValue||e.disabled)&&(!e.onlyShowClearWhenFocus||e.inputFocus);this.data.shouldShowClear!==e&&this.setData({shouldShowClear:e})},updated:function(e){this.data.inputValue!==e&&this.setData({inputValue:e})},onChange:function(e){this.data.controlled||this.updated(e.detail.value),this.data.inputFocus||this.setData({inputFocus:!0}),this.triggerEvent("change",e.detail)},onFocus:function(e){this.setData({inputFocus:!0}),this.triggerEvent("focus",e.detail)},onBlur:function(e){this.setData({inputFocus:!1}),this.triggerEvent("blur",e.detail)},onConfirm:function(e){this.triggerEvent("confirm",e.detail)},onClear:function(){var e=this.data,t=e.controlled,e=e.inputValue;this.setData({inputValue:t?e:"",inputFocus:!0}),this.triggerEvent("clear",{value:""})},onCancel:function(){this.triggerEvent("cancel",{value:this.data.inputValue})},onClick:function(){this.data.disabled||this.setData({inputFocus:!0})}},attached:function(){var e=this.data,t=e.defaultValue,o=e.value,e=e.controlled?o:t;this.updated(e),this.setClear(_objectSpread(_objectSpread({},this.data),{},{inputValue:e}))}});