import _findInstanceProperty from "@babel/runtime-corejs3/core-js/instance/find";
import _Object$assign from "@babel/runtime-corejs3/core-js/object/assign";
import _bindInstanceProperty from "@babel/runtime-corejs3/core-js/instance/bind";
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js/instance/concat";
import _valuesInstanceProperty from "@babel/runtime-corejs3/core-js/instance/values";
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js/instance/map";
import _sliceInstanceProperty from "@babel/runtime-corejs3/core-js/instance/slice";
import Button from '../button';
import ScrollSelect from '../scrollSelect';
import Time from './time';
import { Row, Col } from '../grid';
import { strPad, _$ } from '../utils';
import { isEqual, isLT, isGT, getDateString, getTimeString, createDate, getYearBase, yearArray, monthArray } from './utils';
import { Tabs, Tab } from '../tabs';
import Icon from '../icon';
import dayjs from 'dayjs';
export default function (obj, _Vdt, blocks, $callee) {
  _Vdt || (_Vdt = Vdt);
  obj || (obj = {});
  blocks || (blocks = {});

  var h = _Vdt.miss.h,
      hc = _Vdt.miss.hc,
      hu = _Vdt.miss.hu,
      widgets = this && this.widgets || {},
      _blocks = {},
      __blocks = {},
      __u = _Vdt.utils,
      extend = __u.extend,
      _e = __u.error,
      _className = __u.className,
      __slice = _sliceInstanceProperty(__u),
      __noop = __u.noop,
      __m = _mapInstanceProperty(__u),
      __o = __u.Options,
      _getModel = __o.getModel,
      _setModel = __o.setModel,
      _setCheckboxModel = __u.setCheckboxModel,
      _detectCheckboxChecked = __u.detectCheckboxChecked,
      _setSelectModel = __u.setSelectModel,
      self = this.data,
      $this = this,
      scope = obj,
      Animate = self && self.Animate,
      parent = ($callee || {})._super;

  var _self$get = self.get(),
      dayClassNames = _self$get.dayClassNames,
      multiple = _self$get.multiple,
      onMouseEnterDay = _self$get.onMouseEnterDay,
      type = _self$get.type,
      hours = _self$get.hours,
      minutes = _self$get.minutes,
      seconds = _self$get.seconds,
      disabledHours = _self$get.disabledHours,
      disabledMinutes = _self$get.disabledMinutes,
      disabledSeconds = _self$get.disabledSeconds,
      _isShowYearPicker = _self$get._isShowYearPicker,
      _isShowMonthPicker = _self$get._isShowMonthPicker,
      _isShowDatePicker = _self$get._isShowDatePicker,
      _isSelectTime = _self$get._isSelectTime,
      _now = _self$get._now,
      _showDate = _self$get._showDate,
      _focusDate = _self$get._focusDate,
      _id = _self$get._id;

  var _self$_getRealValue = self._getRealValue(),
      value = _self$_getRealValue.value,
      values = _valuesInstanceProperty(_self$_getRealValue);

  var valueDate = value || _now;
  var showDate = _showDate || valueDate;

  var _showYear = Math.floor(showDate.get('year') / 10);

  var yearMonthFormat = _$('yearMonthFormat');

  if (yearMonthFormat === 'yearMonthFormat') {
    yearMonthFormat = 'YYYY MM';
  }

  var isYearOrMonth = self._isYearOrMonth();

  return h('div', {
    'tabindex': '0',
    'ev-keydown': function () {
      try {
        return self._onKeydown;
      } catch (e) {
        _e(e);
      }
    }.call($this)
  }, [(_blocks['title'] = function (parent) {
    return null;
  }) && (__blocks['title'] = function (parent) {
    var _context;

    var args = arguments;
    return blocks['title'] ? blocks['title'].apply($this, _concatInstanceProperty(_context = [function () {
      return _blocks['title'].apply($this, args);
    }]).call(_context, __slice.call(args, 1))) : _blocks['title'].apply($this, args);
  }) && __blocks['title'].apply($this, [__noop]), function () {
    try {
      return type === 'datetime';
    } catch (e) {
      _e(e);
    }
  }.call($this) ? h(Tabs, {
    'type': 'border-card',
    'value': function () {
      try {
        return _isSelectTime ? "time" : "date";
      } catch (e) {
        _e(e);
      }
    }.call($this),
    'children': [h(Tab, {
      'value': 'date',
      'children': function () {
        try {
          return value ? getDateString(valueDate.toDate()) : '0000-00-00';
        } catch (e) {
          _e(e);
        }
      }.call($this),
      '_context': $this
    }), h(Tab, {
      'value': 'time',
      'children': function () {
        try {
          return value ? getTimeString(valueDate.toDate()) : '00:00:00';
        } catch (e) {
          _e(e);
        }
      }.call($this),
      '_context': $this
    })],
    '_context': $this,
    'ev-$change:value': function () {
      try {
        return self._onChangeTab;
      } catch (e) {
        _e(e);
      }
    }.call($this)
  }) : undefined, function () {
    try {
      return !_isSelectTime;
    } catch (e) {
      _e(e);
    }
  }.call($this) ? h('div', null, [h('div', null, [h('div', null, [h(Button, {
    'icon': function () {
      try {
        return true;
      } catch (e) {
        _e(e);
      }
    }.call($this),
    'type': 'none',
    'size': 'small',
    'className': 'k-prev',
    'tagName': 'div',
    'tabindex': function () {
      try {
        return null;
      } catch (e) {
        _e(e);
      }
    }.call($this),
    'children': [h(Icon, {
      'className': 'ion-ios-arrow-left',
      'size': 'small',
      '_context': $this
    }), h(Icon, {
      'className': 'ion-ios-arrow-left',
      'size': 'small',
      '_context': $this
    })],
    '_context': $this,
    'ev-click': function () {
      try {
        return self.prevYear;
      } catch (e) {
        _e(e);
      }
    }.call($this)
  }), function () {
    try {
      return _isShowDatePicker;
    } catch (e) {
      _e(e);
    }
  }.call($this) ? h(Button, {
    'icon': function () {
      try {
        return true;
      } catch (e) {
        _e(e);
      }
    }.call($this),
    'type': 'none',
    'size': 'small',
    'className': 'k-prev',
    'tagName': 'div',
    'tabindex': function () {
      try {
        return null;
      } catch (e) {
        _e(e);
      }
    }.call($this),
    'children': h(Icon, {
      'className': 'ion-ios-arrow-left',
      'size': 'small',
      '_context': $this
    }),
    '_context': $this,
    'ev-click': function () {
      try {
        return self.prevMonth;
      } catch (e) {
        _e(e);
      }
    }.call($this)
  }) : undefined], 'k-left-btns'), h('div', null, [h(Button, {
    'icon': function () {
      try {
        return true;
      } catch (e) {
        _e(e);
      }
    }.call($this),
    'type': 'none',
    'size': 'small',
    'className': 'k-next',
    'tagName': 'div',
    'tabindex': function () {
      try {
        return null;
      } catch (e) {
        _e(e);
      }
    }.call($this),
    'children': [h(Icon, {
      'className': 'ion-ios-arrow-right',
      'size': 'small',
      '_context': $this
    }), h(Icon, {
      'className': 'ion-ios-arrow-right',
      'size': 'small',
      '_context': $this
    })],
    '_context': $this,
    'ev-click': function () {
      try {
        return self.nextYear;
      } catch (e) {
        _e(e);
      }
    }.call($this)
  }), function () {
    try {
      return _isShowDatePicker;
    } catch (e) {
      _e(e);
    }
  }.call($this) ? h(Button, {
    'icon': function () {
      try {
        return true;
      } catch (e) {
        _e(e);
      }
    }.call($this),
    'type': 'none',
    'size': 'small',
    'className': 'k-next',
    'tagName': 'div',
    'tabindex': function () {
      try {
        return null;
      } catch (e) {
        _e(e);
      }
    }.call($this),
    'children': h(Icon, {
      'className': 'ion-ios-arrow-right',
      'size': 'small',
      '_context': $this
    }),
    '_context': $this,
    'ev-click': function () {
      try {
        return self.nextMonth;
      } catch (e) {
        _e(e);
      }
    }.call($this)
  }) : undefined], 'k-right-btns'), h('div', null, function () {
    try {
      return _isShowYearPicker;
    } catch (e) {
      _e(e);
    }
  }.call($this) ? h('span', null, function () {
    try {
      return _$("{n}\u5E74 - {m}\u5E74", {
        n: _showYear * 10,
        m: _showYear * 10 + 9
      });
    } catch (e) {
      _e(e);
    }
  }.call($this), 'k-text') : h('span', null, [h('span', {
    'ev-click': function () {
      try {
        return self.showYearPicker;
      } catch (e) {
        _e(e);
      }
    }.call($this)
  }, function () {
    try {
      return _$(showDate.get('year') + "\u5E74");
    } catch (e) {
      _e(e);
    }
  }.call($this), 'k-text'), h('span', {
    'ev-click': function () {
      try {
        return isYearOrMonth ? undefined : self.showMonthPicker;
      } catch (e) {
        _e(e);
      }
    }.call($this)
  }, function () {
    try {
      return _$(showDate.get('month') + 1 + "\u6708");
    } catch (e) {
      _e(e);
    }
  }.call($this), 'k-text')]), 'k-text-wrapper')], 'k-month-year-btn c-clearfix'), function () {
    try {
      return _isShowDatePicker;
    } catch (e) {
      _e(e);
    }
  }.call($this) ? h('div', null, __m(function () {
    try {
      return [_$('日'), _$('一'), _$('二'), _$('三'), _$('四'), _$('五'), _$('六')];
    } catch (e) {
      _e(e);
    }
  }.call($this), function (value, key) {
    return h('div', null, function () {
      try {
        return value;
      } catch (e) {
        _e(e);
      }
    }.call($this), 'k-weekday');
  }, $this), 'k-weekdays') : undefined, function () {
    try {
      return _isShowDatePicker;
    } catch (e) {
      _e(e);
    }
  }.call($this) ? h('div', {
    'ev-mouseleave': function () {
      try {
        return self._onMouseLeaveDays;
      } catch (e) {
        _e(e);
      }
    }.call($this)
  }, function () {
    try {
      return function () {
        var ret = []; // dayjs is immutable, so we use js Date

        var start = showDate.toDate();
        var month = start.getMonth();
        start.setDate(1);
        start.setHours(0);
        start.setMinutes(0);
        start.setSeconds(0);
        var startWeekday = start.getDay();
        start.setDate(1 - startWeekday);

        var _loop = function _loop(i) {
          var dayjsDate = dayjs(start);

          var _date = start.getDate();

          var _month = start.getMonth();

          var disabled = self._isDisabledDate(dayjsDate);

          var isOut = _month !== month;
          var classNames = dayClassNames ? dayClassNames.call(self, dayjsDate, isOut) : null;
          ret.push(h('div', {
            'ev-click': function () {
              try {
                var _context2;

                return !disabled && _bindInstanceProperty(_context2 = self.select).call(_context2, self, dayjsDate);
              } catch (e) {
                _e(e);
              }
            }.call($this),
            'ev-mouseenter': function () {
              try {
                var _context3;

                return _bindInstanceProperty(_context3 = self._onMouseEnter).call(_context3, self, dayjsDate, isOut);
              } catch (e) {
                _e(e);
              }
            }.call($this)
          }, function () {
            try {
              return _date;
            } catch (e) {
              _e(e);
            }
          }.call($this), _className(function () {
            try {
              return _Object$assign({
                "k-day": true,
                "k-out": isOut,
                "k-active": !isOut && _findInstanceProperty(values).call(values, function (value) {
                  return isEqual(value, dayjsDate, 'date');
                }),
                "k-today": isEqual(_now, dayjsDate, 'date'),
                "k-disabled": disabled,
                "k-hover": isEqual(_focusDate, dayjsDate, 'date')
              }, classNames);
            } catch (e) {
              _e(e);
            }
          }.call($this))));
          start.setDate(start.getDate() + 1);
        };

        for (var i = 0; i < 42; i++) {
          _loop(i);
        }

        var result = [];

        var _loop2 = function _loop2(_i) {
          result.push(h('div', null, function () {
            try {
              return _sliceInstanceProperty(ret).call(ret, 7 * _i, 7 * (_i + 1));
            } catch (e) {
              _e(e);
            }
          }.call($this)));
        };

        for (var _i = 0; _i < 6; _i++) {
          _loop2(_i);
        }

        return result;
      }();
    } catch (e) {
      _e(e);
    }
  }.call($this), 'k-calendar') : undefined, h('div', null, [function () {
    try {
      return _isShowMonthPicker;
    } catch (e) {
      _e(e);
    }
  }.call($this) ? h('div', null, function () {
    try {
      return function () {
        var ret = [];
        var start = showDate.toDate();

        var _loop3 = function _loop3(i) {
          var _month = i;

          var disabled = self._isDisabledMonth(_month);

          start.setMonth(_month);
          var dayjsDate = dayjs(start);
          ret.push(h('div', {
            'ev-click': function () {
              try {
                var _context4;

                return !disabled && _bindInstanceProperty(_context4 = self.onChangeMonth).call(_context4, self, _month);
              } catch (e) {
                _e(e);
              }
            }.call($this),
            'ev-mouseenter': function () {
              try {
                var _context5;

                return _bindInstanceProperty(_context5 = self._onMouseEnter).call(_context5, self, dayjsDate, false);
              } catch (e) {
                _e(e);
              }
            }.call($this)
          }, [function () {
            try {
              return _month + 1;
            } catch (e) {
              _e(e);
            }
          }.call($this), '月'], _className(function () {
            try {
              return {
                "k-month-year": true,
                "k-disabled": disabled,
                "k-active": isEqual(value, dayjsDate, 'month'),
                "k-today": isEqual(_now, dayjsDate, 'month'),
                "k-hover": isEqual(_focusDate, dayjsDate, 'month')
              };
            } catch (e) {
              _e(e);
            }
          }.call($this))));
        };

        for (var i = 0; i < 12; i++) {
          _loop3(i);
        }

        var result = [];

        var _loop4 = function _loop4(_i2) {
          result.push(h('div', null, function () {
            try {
              return _sliceInstanceProperty(ret).call(ret, 4 * _i2, 4 * (_i2 + 1));
            } catch (e) {
              _e(e);
            }
          }.call($this), 'k-month-year-row'));
        };

        for (var _i2 = 0; _i2 < 3; _i2++) {
          _loop4(_i2);
        }

        return result;
      }();
    } catch (e) {
      _e(e);
    }
  }.call($this)) : undefined, function () {
    try {
      return _isShowYearPicker;
    } catch (e) {
      _e(e);
    }
  }.call($this) ? h('div', null, function () {
    try {
      return function () {
        var ret = [];
        var start = showDate.toDate();
        start.setFullYear(_showYear * 10 - 1);

        var _loop5 = function _loop5(i) {
          var dayjsDate = dayjs(start);

          var _year = start.getFullYear();

          var disabled = self._isDisabledYear(_year);

          var isOut = Math.floor(_year / 10) !== _showYear;

          ret.push(h('div', {
            'ev-click': function () {
              try {
                var _context6;

                return !disabled && _bindInstanceProperty(_context6 = self.onChangeYear).call(_context6, self, _year);
              } catch (e) {
                _e(e);
              }
            }.call($this),
            'ev-mouseenter': function () {
              try {
                var _context7;

                return _bindInstanceProperty(_context7 = self._onMouseEnter).call(_context7, self, dayjsDate, isOut);
              } catch (e) {
                _e(e);
              }
            }.call($this)
          }, function () {
            try {
              return _year;
            } catch (e) {
              _e(e);
            }
          }.call($this), _className(function () {
            try {
              return {
                "k-month-year": true,
                "k-disabled": disabled,
                "k-out": isOut,
                "k-active": !isOut && isEqual(value, dayjsDate, 'year'),
                "k-today": isEqual(_now, dayjsDate, 'year'),
                "k-hover": isEqual(_focusDate, dayjsDate, 'year')
              };
            } catch (e) {
              _e(e);
            }
          }.call($this))));
          start.setFullYear(start.getFullYear() + 1);
        };

        for (var i = 0; i < 12; i++) {
          _loop5(i);
        }

        var result = [];

        var _loop6 = function _loop6(_i3) {
          result.push(h('div', null, function () {
            try {
              return _sliceInstanceProperty(ret).call(ret, 4 * _i3, 4 * (_i3 + 1));
            } catch (e) {
              _e(e);
            }
          }.call($this), 'k-month-year-row'));
        };

        for (var _i3 = 0; _i3 < 3; _i3++) {
          _loop6(_i3);
        }

        return result;
      }();
    } catch (e) {
      _e(e);
    }
  }.call($this)) : undefined], 'k-calendar')], 'k-date-picker') : h('div', {
    'ev-wheel': function () {
      try {
        return self._onWheel;
      } catch (e) {
        _e(e);
      }
    }.call($this)
  }, (_blocks['time-body'] = function (parent) {
    return h(Time, {
      'data': function () {
        try {
          return [_mapInstanceProperty(hours).call(hours, function (v) {
            return strPad(v, 2);
          }), _mapInstanceProperty(minutes).call(minutes, function (v) {
            return strPad(v, 2);
          }), _mapInstanceProperty(seconds).call(seconds, function (v) {
            return strPad(v, 2);
          })];
        } catch (e) {
          _e(e);
        }
      }.call($this),
      'value': function () {
        try {
          return value || // if exists _id, it indicate that this is a range time selection of Timepicker
          // we don't let Time to trigger $change:value in initial
          // otherwise the start time will be disabled due to the end time is 00:00:00
          // #119
          self.get('_id') ? [strPad(valueDate.hour(), 2), strPad(valueDate.minute(), 2), strPad(valueDate.second(), 2)] : ['', '', ''];
        } catch (e) {
          _e(e);
        }
      }.call($this),
      'disabledItems': function () {
        try {
          return [disabledHours, disabledMinutes, disabledSeconds];
        } catch (e) {
          _e(e);
        }
      }.call($this),
      'min': function () {
        try {
          return self._getMinDate();
        } catch (e) {
          _e(e);
        }
      }.call($this),
      'max': function () {
        try {
          return self._getMaxDate();
        } catch (e) {
          _e(e);
        }
      }.call($this),
      'date': function () {
        try {
          return scope.date || valueDate;
        } catch (e) {
          _e(e);
        }
      }.call($this),
      'isDisabledTime': function () {
        try {
          return self._isDisabledTime;
        } catch (e) {
          _e(e);
        }
      }.call($this),
      '_context': $this,
      'ev-change': function () {
        try {
          return self.onChangeTime;
        } catch (e) {
          _e(e);
        }
      }.call($this)
    });
  }) && (__blocks['time-body'] = function (parent) {
    var _context8;

    var args = arguments;
    return blocks['time-body'] ? blocks['time-body'].apply($this, _concatInstanceProperty(_context8 = [function () {
      return _blocks['time-body'].apply($this, args);
    }]).call(_context8, __slice.call(args, 1))) : _blocks['time-body'].apply($this, args);
  }) && __blocks['time-body'].apply($this, [__noop]), 'k-time-picker', 'time')], _className(function () {
    try {
      return {
        "k-calendar-wrapper": true,
        "k-datetime": type === 'datetime'
      };
    } catch (e) {
      _e(e);
    }
  }.call($this)));
}