import Picker from '../picker';
import DatePanel from '../panel/date';
import MonthRangePanel from '../panel/month-range';
import DateRangePanel from '../panel/date-range';
import DateRangeIndepPanel from '../panel/date-range-indep';

const getPanel = function(type, dateSelectiveSeparation) {
  if (type === 'daterange' || type === 'datetimerange') {
    if (dateSelectiveSeparation) {
      return DateRangeIndepPanel; // 开始结束时间分开选择
    } else {
      return DateRangePanel;
    }
  } else if (type === 'monthrange') {
    return MonthRangePanel;
  }
  return DatePanel;
};

export default {
  mixins: [Picker],

  name: 'ElDatePicker',

  props: {
    type: {
      type: String,
      default: 'date'
    },
    timeArrowControl: Boolean,
    disableDate: Function
  },

  watch: {
    type(type) {
      if (this.picker) {
        this.unmountPicker();
        this.panel = getPanel(type);
        this.mountPicker();
      } else {
        this.panel = getPanel(type);
      }
    }
  },

  created() {
    this.dateSelectiveSeparation = !(this.pickerOptions && this.pickerOptions.dateSelectiveSeparation === false);
    this.panel = getPanel(this.type, this.dateSelectiveSeparation);
  }
};
