import * as _vue from "vue";

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

import PropTypes from '../../../_util/vue-types';
import BaseMixin from '../../../_util/BaseMixin';
import { getOptionProps, getComponent } from '../../../_util/props-util';
import { cloneElement } from '../../../_util/vnode';
import CalendarHeader from '../calendar/CalendarHeader';
import DateTable from '../date/DateTable';
import DateInput from '../date/DateInput';
import { getTimeConfig } from '../util/index';

function noop() {}

var CalendarPart = {
  name: 'CalendarPart',
  inheritAttrs: false,
  mixins: [BaseMixin],
  props: {
    prefixCls: PropTypes.string,
    value: PropTypes.any,
    hoverValue: PropTypes.any,
    selectedValue: PropTypes.any,
    direction: PropTypes.any,
    locale: PropTypes.any,
    showDateInput: PropTypes.bool,
    showTimePicker: PropTypes.bool,
    showWeekNumber: PropTypes.bool,
    format: PropTypes.any,
    placeholder: PropTypes.any,
    disabledDate: PropTypes.any,
    timePicker: PropTypes.any,
    disabledTime: PropTypes.any,
    disabledMonth: PropTypes.any,
    mode: PropTypes.any,
    // onInputSelect: PropTypes.func,
    timePickerDisabledTime: PropTypes.object,
    enableNext: PropTypes.any,
    enablePrev: PropTypes.any,
    clearIcon: PropTypes.any,
    dateRender: PropTypes.func,
    inputMode: PropTypes.string,
    inputReadOnly: PropTypes.bool
  },
  render: function render() {
    var props = this.$props;
    var prefixCls = props.prefixCls,
        value = props.value,
        hoverValue = props.hoverValue,
        selectedValue = props.selectedValue,
        mode = props.mode,
        direction = props.direction,
        locale = props.locale,
        format = props.format,
        placeholder = props.placeholder,
        disabledDate = props.disabledDate,
        timePicker = props.timePicker,
        disabledTime = props.disabledTime,
        timePickerDisabledTime = props.timePickerDisabledTime,
        showTimePicker = props.showTimePicker,
        enablePrev = props.enablePrev,
        enableNext = props.enableNext,
        disabledMonth = props.disabledMonth,
        showDateInput = props.showDateInput,
        dateRender = props.dateRender,
        showWeekNumber = props.showWeekNumber,
        showClear = props.showClear,
        inputMode = props.inputMode,
        inputReadOnly = props.inputReadOnly;
    var clearIcon = getComponent(this, 'clearIcon');
    var _this$$attrs = this.$attrs,
        _this$$attrs$onInputC = _this$$attrs.onInputChange,
        onInputChange = _this$$attrs$onInputC === void 0 ? noop : _this$$attrs$onInputC,
        _this$$attrs$onInputS = _this$$attrs.onInputSelect,
        onInputSelect = _this$$attrs$onInputS === void 0 ? noop : _this$$attrs$onInputS,
        _this$$attrs$onValueC = _this$$attrs.onValueChange,
        onValueChange = _this$$attrs$onValueC === void 0 ? noop : _this$$attrs$onValueC,
        _this$$attrs$onPanelC = _this$$attrs.onPanelChange,
        onPanelChange = _this$$attrs$onPanelC === void 0 ? noop : _this$$attrs$onPanelC,
        _this$$attrs$onSelect = _this$$attrs.onSelect,
        onSelect = _this$$attrs$onSelect === void 0 ? noop : _this$$attrs$onSelect,
        _this$$attrs$onDayHov = _this$$attrs.onDayHover,
        onDayHover = _this$$attrs$onDayHov === void 0 ? noop : _this$$attrs$onDayHov;
    var shouldShowTimePicker = showTimePicker && timePicker;
    var disabledTimeConfig = shouldShowTimePicker && disabledTime ? getTimeConfig(selectedValue, disabledTime) : null;
    var rangeClassName = "".concat(prefixCls, "-range");
    var newProps = {
      locale: locale,
      value: value,
      prefixCls: prefixCls,
      showTimePicker: showTimePicker
    };
    var index = direction === 'left' ? 0 : 1;
    var timePickerEle = null;

    if (shouldShowTimePicker) {
      var timePickerProps = getOptionProps(timePicker);
      timePickerEle = cloneElement(timePicker, _objectSpread(_objectSpread(_objectSpread(_objectSpread({
        showHour: true,
        showMinute: true,
        showSecond: true
      }, timePickerProps), disabledTimeConfig), timePickerDisabledTime), {}, {
        defaultOpenValue: value,
        value: selectedValue[index],
        onChange: onInputChange
      }));
    }

    var dateInputElement = showDateInput && _vue.createVNode(DateInput, {
      "format": format,
      "locale": locale,
      "prefixCls": prefixCls,
      "timePicker": timePicker,
      "disabledDate": disabledDate,
      "placeholder": placeholder,
      "disabledTime": disabledTime,
      "value": value,
      "showClear": showClear || false,
      "selectedValue": selectedValue[index],
      "onChange": onInputChange,
      "onSelect": onInputSelect,
      "clearIcon": clearIcon,
      "inputMode": inputMode,
      "inputReadOnly": inputReadOnly
    }, null);

    var headerProps = _objectSpread(_objectSpread({}, newProps), {}, {
      mode: mode,
      enableNext: enableNext,
      enablePrev: enablePrev,
      disabledMonth: disabledMonth,
      onValueChange: onValueChange,
      onPanelChange: onPanelChange
    });

    var tableProps = _objectSpread(_objectSpread({}, newProps), {}, {
      hoverValue: hoverValue,
      selectedValue: selectedValue,
      dateRender: dateRender,
      disabledDate: disabledDate,
      showWeekNumber: showWeekNumber,
      onSelect: onSelect,
      onDayHover: onDayHover
    });

    return _vue.createVNode("div", {
      "class": "".concat(rangeClassName, "-part ").concat(rangeClassName, "-").concat(direction)
    }, [dateInputElement, _vue.createVNode("div", {
      "style": {
        outline: 'none'
      }
    }, [_vue.createVNode(CalendarHeader, headerProps, null), showTimePicker ? _vue.createVNode("div", {
      "class": "".concat(prefixCls, "-time-picker")
    }, [_vue.createVNode("div", {
      "class": "".concat(prefixCls, "-time-picker-panel")
    }, [timePickerEle])]) : null, _vue.createVNode("div", {
      "class": "".concat(prefixCls, "-body")
    }, [_vue.createVNode(DateTable, tableProps, null)])])]);
  }
};
export default CalendarPart;