// import "./index.css";
var formatDate = function formatDate(date) {
  if (!date) {
    return "";
  }

  var _date = new Date(date);

  var y = _date.getFullYear();

  var m = _date.getMonth() + 1;
  m = m < 10 ? "0" + m : m;

  var d = _date.getDate();

  d = d < 10 ? "0" + d : d;
  return y + "/" + m + "/" + d;
};

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

  var _h = _vm.$createElement;

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

  return _c('ks-popup', {
    staticClass: "ks-calendar-popup",
    attrs: {
      "value": _vm.value,
      "position": "bottom",
      "get-container": "body",
      "close-icon-position": "top-left",
      "close-icon": "arrow-left",
      "closeable": true
    },
    on: {
      "input": _vm.handleClosePopup
    }
  }, [_c('ks-calendar', _vm._g(_vm._b({
    class: ['ks-calendar', {
      'ks-calendar-horizontal': _vm.horizontal
    }],
    attrs: {
      "poppable": false,
      "default-date": _vm.currentDate,
      "min-date": _vm.currentMinDate,
      "type": _vm.type,
      "allow-same-day": true
    },
    on: {
      "select": _vm.handleSelect
    },
    scopedSlots: _vm._u([{
      key: "title",
      fn: function fn() {
        return [_c('div', {
          staticClass: "ks-calendar-header"
        }, [_c('span', {
          staticClass: "ks-calendar-header__title"
        }, [_vm._v(_vm._s(_vm.type === "range" ? "选择范围" : "选择日期"))]), _vm._v(" "), _c('span', {
          staticClass: "ks-calendar-header__daterange"
        }, [_vm._v("\n          " + _vm._s(_vm.dateRangeStr) + "\n        ")])])];
      },
      proxy: true
    }])
  }, 'ks-calendar', _vm.$attrs, false), _vm.$listeners))], 1);
};

var __vue_staticRenderFns__ = [];
export default {
  render: __vue_render__,
  staticRenderFns: __vue_staticRenderFns__,
  name: "ks-calendar-range",
  props: {
    value: Boolean,
    minDate: [Object, Date],
    defaultDate: [Array, Date],
    type: {
      type: String,
      default: "range"
    },
    horizontal: {
      type: Boolean,
      default: false
    }
  },
  data: function data() {
    return {
      currentDate: this.defaultDate
    };
  },
  watch: {
    defaultDate: function defaultDate() {
      this.currentDate = this.defaultDate;
    }
  },
  computed: {
    dateRangeStr: function dateRangeStr() {
      var defaultDate = this.currentDate;

      if (this.type === "range" && Array.isArray(defaultDate) && defaultDate.length === 2) {
        if (defaultDate[1]) {
          return formatDate(defaultDate[0]) + " - " + formatDate(defaultDate[1]);
        } else {
          return "" + formatDate(defaultDate[0]);
        }
      } else if (this.type === "single" && defaultDate) {
        return "" + formatDate(defaultDate);
      }

      return "";
    },
    currentMinDate: function currentMinDate() {
      if (!this.minDate) {
        var d = new Date();
        var m = d.getMonth() + 1;
        var y = d.getFullYear();

        if (m - 6 < 1) {
          return new Date(y - 1 + "/" + (12 + m - 6) + "/01");
        } else {
          return new Date(y + "/" + (m - 6) + "/01");
        }
      }

      return this.minDate;
    }
  },
  methods: {
    handleClosePopup: function handleClosePopup(e) {
      this.$emit("input", e);
    },
    handleSelect: function handleSelect(e) {
      this.currentDate = e;
      this.$emit("select", e);
    }
  }
};