"use strict";var _baseComponent=_interopRequireDefault(require("../helpers/baseComponent")),_classNames=_interopRequireDefault(require("../helpers/libs/classNames"));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.")}function _toConsumableArray(e){return _arrayWithoutHoles(e)||_iterableToArray(e)||_unsupportedIterableToArray(e)||_nonIterableSpread()}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(e,t){var r;if(e)return"string"==typeof e?_arrayLikeToArray(e,t):"Map"===(r="Object"===(r=Object.prototype.toString.call(e).slice(8,-1))&&e.constructor?e.constructor.name:r)||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?_arrayLikeToArray(e,t):void 0}function _iterableToArray(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function _arrayWithoutHoles(e){if(Array.isArray(e))return _arrayLikeToArray(e)}function _arrayLikeToArray(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}var defaults={prefixCls:"wux-keyboard",className:"",titleText:"安全键盘",cancelText:"取消",inputText:"输入数字密码",showCancel:!0,disorder:!1,password:!0,maxlength:6,closeOnReject:!0,onChange:function(e){},callback:function(e){}},upsetNums=function(){var e=0<arguments.length&&void 0!==arguments[0]&&arguments[0],t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:[1,2,3,4,5,6,7,8,9,0];if(e)for(var r,n,o,a=Math.floor,i=Math.random,s=t.length,u=a(s/2)+1;u--;)(r=a(i()*s))!==(n=a(i()*s))&&(o=t[r],t[r]=t[n],t[n]=o);for(var l=[],c=0;c<4;c++)l.push(t.slice(3*c,3*(c+1)));return l};(0,_baseComponent.default)({useFunc:!0,data:defaults,computed:{classes:["prefixCls",function(e){return{wrap:(0,_classNames.default)(e),hd:"".concat(e,"__hd"),bd:"".concat(e,"__bd"),label:"".concat(e,"__label"),password:"".concat(e,"__password"),input:"".concat(e,"__input"),ft:"".concat(e,"__ft"),title:"".concat(e,"__title"),numbers:"".concat(e,"__numbers"),number:"".concat(e,"__number"),text:"".concat(e,"__text"),hover:"".concat(e,"__text--hover")}}]},methods:{hide:function(){this.$$setData({in:!1})},show:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=upsetNums(e.disorder),r=e.maxlength<=0?-1:e.maxlength,r=-1!==r?_toConsumableArray(new Array(r||defaults.maxlength)).map(function(){return 1}):[],t=this.$$mergeOptionsAndBindMethods(Object.assign({nums:t,keys:r,value:""},defaults,e));return this.$$setData(_objectSpread({in:!0},t)),this.hide.bind(this)},increase:function(e){var e=e.currentTarget.dataset,e=String(e.value),t=this.data,r=t.value,t=t.maxlength;r.length>=t&&-1!==t||this.updateValue(r+e)},decrease:function(e){var t=this.data.value;0!==t.length&&this.updateValue(t.substr(0,t.length-1))},updateValue:function(){var e,t,r,n=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"";this.$$setData({value:n}),"function"==typeof this.fns.onChange&&this.fns.onChange.call(this,n),n.length===this.data.maxlength&&(r=this.fns.onClose||this.fns.callback,e=this.hide.bind(this),t=this.data.closeOnReject?e:function(){},r&&"function"==typeof r?"object"===_typeof(r=r.call(this,n))?(r.closePromise||r).then(e,t):!1!==r&&e():e())}}});