"use strict";var _baseComponent=_interopRequireDefault(require("../helpers/baseComponent")),_classNames=_interopRequireDefault(require("../helpers/classNames")),_index=_interopRequireDefault(require("./locales/index")),_props=require("./props");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function ownKeys(t,e){var a=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),a.push.apply(a,r)}return a}function _objectSpread(t){for(var e=1;e<arguments.length;e++){var a=null!=arguments[e]?arguments[e]:{};e%2?ownKeys(a,!0).forEach(function(e){_defineProperty(t,e,a[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(a)):ownKeys(a).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(a,e))})}return t}function _defineProperty(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}function isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(e){return!1}}function _construct(e,t,a){return(_construct=isNativeReflectConstruct()?Reflect.construct:function(e,t,a){var r=[null];r.push.apply(r,t);var n=new(Function.bind.apply(e,r));return a&&_setPrototypeOf(n,a.prototype),n}).apply(null,arguments)}function _setPrototypeOf(e,t){return(_setPrototypeOf=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function _toConsumableArray(e){return _arrayWithoutHoles(e)||_iterableToArray(e)||_nonIterableSpread()}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance")}function _iterableToArray(e){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e))return Array.from(e)}function _arrayWithoutHoles(e){if(Array.isArray(e)){for(var t=0,a=new Array(e.length);t<e.length;t++)a[t]=e[t];return a}}var DATETIME="datetime",DATE="date",TIME="time",MONTH="month",YEAR="year",ONE_DAY=864e5;function fomartArray(e,t){for(var a=2<arguments.length&&void 0!==arguments[2]?arguments[2]:1,r=e,n=[];r<=t;)n.push(r),r+=a;return n}function getDaysInMonth(e){return new Date(e.getFullYear(),e.getMonth()+1,0).getDate()}function pad(e){return e<10?"0".concat(e):e+""}function cloneDate(e){return new Date(+e)}function setMonth(e,t){e.setDate(Math.min(e.getDate(),getDaysInMonth(new Date(e.getFullYear(),t)))),e.setMonth(t)}function valueToDate(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};if(!Array.isArray(e))return"string"==typeof e&&(e=e.replace(/\-/g,"/")),isNaN(Number(e))||(e=Number(e)),new Date(e);var a=t.mode,r=t.use12Hours,n=new Date,i=n.getFullYear(),u=n.getMonth(),o=n.getDate(),s=e.map(function(e){return Number(e)});if(r&&[DATETIME,TIME].includes(a)){var l=a===DATETIME?3:0,c=s.length-1,h=Number(s[c]),f=Number(s[l]);f=1===h?(f<=12&&(f+=12),24<=f?0:f):(0===f&&(f=12),12<f&&(f-=12),12<=f?0:f),s.splice(l,1,f),s.splice(c,1)}for(a===TIME?(s.unshift(o),s.unshift(u),s.unshift(i)):a===MONTH?s.push(o):a===YEAR&&(s.push(u),s.push(o));s.length<=6;)s.push(0);return _construct(Date,_toConsumableArray(s))}(0,_baseComponent.default)({properties:_props.props,data:{inputValue:[],options:[]},observers:_defineProperty({inputValue:function(){this.updatedCols()},value:function(e){this.setValue(e)}},"mode, minuteStep, use12Hours, minDate, maxDate, minHour, maxHour, minMinute, maxMinute, lang",function(){this.setValue(this.data.inputValue)}),methods:{getDefaultMinDate:function(){return this.defaultMinDate||(this.defaultMinDate=new Date(2e3,1,1,0,0,0)),this.defaultMinDate},getDefaultMaxDate:function(){return this.defaultMaxDate||(this.defaultMaxDate=new Date(2030,1,1,23,59,59)),this.defaultMaxDate},getMinDate:function(){return this.data.minDate?valueToDate(this.data.minDate,this.data):this.getDefaultMinDate()},getMaxDate:function(){return this.data.maxDate?valueToDate(this.data.maxDate,this.data):this.getDefaultMaxDate()},getDateMember:function(e,t){var a=1<arguments.length&&void 0!==t?t:"year",r={min:"getMinDate",max:"getMaxDate",year:"getFullYear",month:"getMonth",day:"getDate",hour:"getHours",minute:"getMinutes"};return this[r[0<arguments.length&&void 0!==e?e:"min"]]()[r[a]]()},getDisplayHour:function(e){return this.data.use12Hours&&(0===e&&(e=12),12<e&&(e-=12)),e},setHours:function(e,t){if(this.data.use12Hours){var a=t;a=24<=(a=12<=e.getHours()?t+12:t)?0:a,e.setHours(a)}else e.setHours(t)},setAmPm:function(e,t){0===t?e.setTime(+e-ONE_DAY/2):e.setTime(+e+ONE_DAY/2)},getNewDate:function(e,t){var a=parseInt(e[t],10),r=this.data.mode,n=cloneDate(this.getDate());if(r===DATETIME||r===DATE||r===YEAR||r===MONTH)switch(t){case 0:n.setFullYear(a);break;case 1:setMonth(n,a);break;case 2:n.setDate(a);break;case 3:this.setHours(n,a);break;case 4:n.setMinutes(a);break;case 5:this.setAmPm(n,a)}else if(r===TIME)switch(t){case 0:this.setHours(n,a);break;case 1:n.setMinutes(a);break;case 2:this.setAmPm(n,a)}return this.clipDate(n)},clipDate:function(e){var t=this.data.mode,a=this.getMinDate(),r=this.getMaxDate();if(t===DATETIME){if(e<a)return cloneDate(a);if(r<e)return cloneDate(r)}else if(t===DATE||t===YEAR||t===MONTH){if(+e+ONE_DAY<=a)return cloneDate(a);if(+r+ONE_DAY<=e)return cloneDate(r)}else if(t===TIME){var n=r.getHours(),i=r.getMinutes(),u=a.getHours(),o=a.getMinutes(),s=e.getHours(),l=e.getMinutes();if(s<u||s===u&&l<o)return cloneDate(a);if(n<s||s===n&&i<l)return cloneDate(r)}return e},getDate:function(e){var t=e||this.data.value;return this.clipDate(t?valueToDate(t,this.data):this.getMinDate())},getDateData:function(e){var t=this.data,a=t.mode,r=t.lang,n=_index.default[r],i=e.getFullYear(),u=e.getMonth(),o=this.getDateMember("min","year"),s=this.getDateMember("max","year"),l=this.getDateMember("min","month"),c=this.getDateMember("max","month"),h=this.getDateMember("min","day"),f=this.getDateMember("max","day"),D=fomartArray(o,s).map(function(e){return{value:e+"",label:e+n.year+""}});if(a===YEAR)return[D];var m=fomartArray(o===i?l:0,s===i?c:11).map(function(e){return{value:e+"",label:e+1+n.month+""}});return a===MONTH?[D,m]:[D,m,fomartArray(o===i&&l===u?h:1,s===i&&c===u?f:getDaysInMonth(e)).map(function(e){return{value:e+"",label:e+n.day+""}})]},getTimeData:function(e){var t=this.data,a=t.minHour,r=t.maxHour,n=t.minMinute,i=t.maxMinute,u=this.data,o=u.mode,s=u.minuteStep,l=u.use12Hours,c=u.lang,h=_index.default[c],f=this.getDateMember("min","minute"),D=this.getDateMember("max","minute"),m=this.getDateMember("min","hour"),g=this.getDateMember("max","hour"),p=e.getHours();if(o===DATETIME){var d=e.getFullYear(),M=e.getMonth(),b=e.getDate(),y=this.getDateMember("min","year"),v=this.getDateMember("max","year"),_=this.getDateMember("min","month"),A=this.getDateMember("max","month"),T=this.getDateMember("min","day"),E=this.getDateMember("max","day");y===d&&_===M&&T===b&&(a=m)===p&&(n=f),v===d&&A===M&&E===b&&(r=g)===p&&(i=D)}else(a=m)===p&&(n=f),(r=g)===p&&(i=D);var O=[];0===a&&0===r||0!==a&&0!==r?a=this.getDisplayHour(a):0===a&&l&&(a=1,O.push({value:"0",label:h.hour?"12"+h.hour:"12"})),r=this.getDisplayHour(r),O=[].concat(_toConsumableArray(O),_toConsumableArray(fomartArray(a,r).map(function(e){return{value:e+"",label:h.hour?e+h.hour+"":pad(e)}})));for(var H=[],x=e.getMinutes(),w=n;w<=i;w+=s)H.push({value:w+"",label:h.minute?w+h.minute+"":pad(w)}),w<x&&x<w+s&&H.push({value:x+"",label:h.minute?x+h.minute+"":pad(x)});var N=[{value:"0",label:h.am},{value:"1",label:h.pm}];return[O,H].concat(l?[N]:[])},getValueCols:function(e){var t=this.data,a=t.mode,r=t.use12Hours,n=this.getDate(e),i=[],u=[];if(a===YEAR)return{cols:this.getDateData(n),value:[n.getFullYear()+""]};if(a===MONTH)return{cols:this.getDateData(n),value:[n.getFullYear()+"",n.getMonth()+""]};if(a!==DATETIME&&a!==DATE||(i=this.getDateData(n),u=[n.getFullYear()+"",n.getMonth()+"",n.getDate()+""]),a===DATETIME||a===TIME){i=i.concat(this.getTimeData(n));var o=n.getHours(),s=n.getMinutes(),l=[o+"",s+""];r&&(l=[(0===o?12:12<o?o-12:o)+"",s+"",(12<=o?1:0)+""]),u=u.concat(l)}return{value:u,cols:i}},onValueChange:function(e){var t=e.detail,a=t.value,r=t.index,n=this.getNewDate(a,r),i=this.getValueCols(n),u=i.value,o=i.cols,s=this.getValue(u,o);this.triggerEvent("valueChange",_objectSpread({},e.detail,{},s,{date:+n}))},updatedCols:function(){var e=this.getValueCols().cols;this.setData({cols:e})},updated:function(e){this.data.inputValue!==e&&this.setData({inputValue:e})},setValue:function(e){0<arguments.length&&void 0!==e||this.data.inputValue;var t=this.getValueCols().value;this.updated(t)},getValue:function(e,t){var a=0<arguments.length&&void 0!==e?e:this.data.inputValue,r=1<arguments.length&&void 0!==t?t:this.data.cols;return this.picker=this.picker||this.selectComponent("#wux-picker"),_objectSpread({},this.picker.getValue(a,r),{date:+this.getDate()})}},attached:function(){this.setValue(this.data.value)}});
|