"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

exports.__esModule = true;
exports.default = void 0;

var _button = _interopRequireDefault(require("../button"));

var _utils = require("./utils");

var __vue_render__ = function __vue_render__() {
  var _vm = this;

  var _h = _vm.$createElement;

  var _c = _vm._self._c || _h;

  return _c('div', {
    class: ['ks-month', {
      'ks-month-single-horizontal': _vm.horizontal
    }]
  }, [_c('div', {
    ref: "body",
    staticClass: "van-calendar__body ks-month-body"
  }, _vm._l(_vm.years, function (y) {
    return _c('div', {
      key: y,
      staticClass: "van-calendar__month"
    }, [_c('div', {
      staticClass: "van-calendar__month-title"
    }, [_vm._v(_vm._s(y) + "年")]), _vm._v(" "), _c('div', {
      staticClass: "van-calendar__days"
    }, _vm._l(_vm.months, function (m) {
      return _c('div', {
        key: m,
        staticClass: "van-calendar__day ks-month__day",
        class: {
          'van-calendar__day--disabled': _vm.min && +new Date(y + "/" + m + "/01") < _vm.min || _vm.max && +new Date(y + "/" + m + "/01") > _vm.max
        },
        on: {
          "click": function click($event) {
            _vm.handleSelectDay(y, m, _vm.min && +new Date(y + "/" + m + "/01") < _vm.min || _vm.max && +new Date(y + "/" + m + "/01") > _vm.max);
          }
        }
      }, [_c('div', {
        class: {
          'van-calendar__selected-day': _vm.currentMonth === +new Date(y + "/" + m + "/01")
        }
      }, [_vm._v(_vm._s(m) + "月")])]);
    }), 0)]);
  }), 0), _vm._v(" "), _c('div', {
    staticClass: "ks-month-header"
  }, [_c('span', {
    staticClass: "ks-month-header__title"
  }, [_vm._v("月份选择")]), _vm._v(" "), _c('span', {
    staticClass: "ks-month-header__daterange"
  }, [_vm._v(_vm._s(_vm.monthRangeStr))])]), _vm._v(" "), _vm.showConfirm ? _c('div', {
    staticClass: "van-calendar__footer van-calendar__footer--safe-area-inset-bottom"
  }, [_c('Button', {
    staticClass: "van-calendar__confirm",
    attrs: {
      "type": "primary",
      "disabled": !_vm.currentMonth,
      "round": "",
      "block": ""
    },
    on: {
      "click": _vm.handleSelect
    }
  }, [_vm._v("确定")])], 1) : _vm._e()]);
};

var __vue_staticRenderFns__ = [];
var _default2 = {
  render: __vue_render__,
  staticRenderFns: __vue_staticRenderFns__,
  name: "ks-month-single",
  components: {
    Button: _button.default
  },
  props: {
    defaultMonth: {
      type: [String, Date, Number, Object],
      default: function _default() {
        return new Date();
      }
    },
    yearRange: {
      type: Array,
      default: function _default() {
        return [new Date().getFullYear() - 5, new Date().getFullYear()];
      }
    },
    horizontal: {
      type: Boolean,
      default: false
    },
    showConfirm: {
      type: Boolean,
      default: true
    },
    minMonth: String,
    maxMonth: String
  },
  data: function data() {
    return {
      months: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],
      years: (0, _utils.getYears)(this.yearRange),
      currentMonth: (0, _utils.formatMonth)(this.defaultMonth)
    };
  },
  watch: {
    defaultMonth: function defaultMonth() {
      this.currentMonth = (0, _utils.formatMonth)(this.defaultMonth);
    }
  },
  computed: {
    monthRangeStr: function monthRangeStr() {
      if (this.currentMonth) {
        return "" + (0, _utils.format)(this.currentMonth);
      }

      return '';
    },
    min: function min() {
      return this.minMonth ? (0, _utils.formatMonth)(this.minMonth) : null;
    },
    max: function max() {
      return this.maxMonth ? (0, _utils.formatMonth)(this.maxMonth) : null;
    }
  },
  methods: {
    handleSelectDay: function handleSelectDay(y, m, disabled) {
      if (!disabled) {
        this.currentMonth = (0, _utils.formatMonth)(y + "/" + m);
        this.$emit('select', new Date(this.currentMonth));
      }
    },
    handleSelect: function handleSelect() {
      this.$emit("confirm", new Date(this.currentMonth));
    },
    scrollInto: function scrollInto() {
      var _this = this;

      setTimeout(function () {
        if (_this.currentMonth) {
          var top = _this.$el.querySelector('.van-calendar__selected-day');

          _this.$refs.body.scrollTop = top && top.getBoundingClientRect().top - 120;
        }
      }, 240);
    },
    scrollClear: function scrollClear() {
      this.$refs.body.scrollTop = 0;
    }
  }
};
exports.default = _default2;