"use strict";

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

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

var _calendar = _interopRequireDefault(require("../calendar"));

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('ks-calendar', {
    attrs: {
      "default-date": _vm.currentDate,
      "poppable": false,
      "show-confirm": false,
      "show-title": false,
      "show-subtitle": false,
      "min-date": _vm.currentMin,
      "max-date": _vm.currentMax,
      "lazy-render": false,
      "row-height": "50",
      "type": "single"
    },
    on: {
      "select": _vm.handleSelect
    }
  });
};

var __vue_staticRenderFns__ = [];
var _default = {
  render: __vue_render__,
  staticRenderFns: __vue_staticRenderFns__,
  name: 'date-select',
  components: {
    ksCalendar: _calendar.default
  },
  props: {
    defaultValue: {
      type: [Date, String, Number],
      default: new Date()
    },
    min: [String, Number, Date],
    max: [String, Number, Date]
  },
  data: function data() {
    return {
      currentDate: null,
      currentMin: new Date(),
      currentMax: new Date()
    };
  },
  created: function created() {
    this.init();
  },
  methods: {
    init: function init() {
      this.currentDate = (0, _utils.formatToDate)(this.defaultValue);

      if (!this.min) {
        var _date = new Date();

        var y = _date.getFullYear();

        var m = _date.getMonth() + 1;
        this.currentMin = m - 6 < 1 ? new Date(y - 1, 12 + m - 5, 1) : new Date(y, m - 5, 1);
      } else {
        this.currentMin = (0, _utils.formatToDate)(this.min);
      }

      if (!this.max) {
        var _date2 = new Date();

        var _y = _date2.getFullYear();

        var _m = _date2.getMonth() + 1;

        this.currentMax = _m + 6 > 12 ? new Date(_y + 1, _m + 6 - 12, 0) : new Date(_y, _m + 6, 0);
      } else {
        this.currentMax = (0, _utils.formatToDate)(this.max);
      }
    },
    handleSelect: function handleSelect(e) {
      this.$emit('select', {
        date: e,
        str: (0, _utils.formatToString)(e)
      });
    }
  }
};
exports.default = _default;