import { useContext, useRef, useState, useEffect } from "react";
import Trigger from "../Trigger/index.js";
import InputRange from "../_class/picker/input-range.js";
import { isUndefined, isArray, isDayjs, isObject } from "../_util/is.js";
import cs from "../_util/classNames.js";
import { pickDataAttributes } from "../_util/pick.js";
import { ConfigContext } from "../ConfigProvider/index.js";
import { getDayjsValue, getNow, toTimezone, toLocal, methods, isValidTimeString, isDayjsArrayChange, getSortedDayjsArray, getValueWithTime } from "../_util/dayjs.js";
import IconCalendar from "../../icon/react-icon/IconCalendar/index.js";
import IconCalendarClock from "../../icon/react-icon/IconCalendarClock/index.js";
import RangePicker from "./panels/range/index.js";
import Footer from "./panels/footer.js";
import Shortcuts from "./panels/shortcuts.js";
import { getDefaultWeekStart, getAvailableDayjsLength, getLocaleDayjsValue } from "./util.js";
import useMergeProps from "../_util/hooks/useMergeProps.js";
import usePrevious from "../_util/hooks/usePrevious.js";
import useUpdate from "../_util/hooks/useUpdate.js";
import PickerContext from "./context.js";
import { jsx, jsxs, Fragment } from "../../../../../../@emotion_react@11.10.4_3toe27fv7etiytxb5kxc7fxaw4/node_modules/@emotion/react/jsx-runtime/dist/emotion-react-jsx-runtime.browser.esm.js";
var __assign = globalThis && globalThis.__assign || function() {
  __assign = Object.assign || function(t) {
    for (var s, i = 1, n = arguments.length; i < n; i++) {
      s = arguments[i];
      for (var p in s)
        if (Object.prototype.hasOwnProperty.call(s, p))
          t[p] = s[p];
    }
    return t;
  };
  return __assign.apply(this, arguments);
};
var __read = globalThis && globalThis.__read || function(o, n) {
  var m = typeof Symbol === "function" && o[Symbol.iterator];
  if (!m)
    return o;
  var i = m.call(o), r, ar = [], e;
  try {
    while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
      ar.push(r.value);
  } catch (error) {
    e = {
      error
    };
  } finally {
    try {
      if (r && !r.done && (m = i["return"]))
        m.call(i);
    } finally {
      if (e)
        throw e.error;
    }
  }
  return ar;
};
var __spreadArray = globalThis && globalThis.__spreadArray || function(to, from, pack) {
  if (pack || arguments.length === 2)
    for (var i = 0, l = from.length, ar; i < l; i++) {
      if (ar || !(i in from)) {
        if (!ar)
          ar = Array.prototype.slice.call(from, 0, i);
        ar[i] = from[i];
      }
    }
  return to.concat(ar || Array.prototype.slice.call(from));
};
function getFormat(props) {
  var format = props.format, showTime = props.showTime, mode = props.mode;
  var valueFormat;
  switch (mode) {
    case "date":
      valueFormat = showTime ? "YYYY-MM-DD HH:mm:ss" : "YYYY-MM-DD";
      break;
    case "month":
      valueFormat = "YYYY-MM";
      break;
    case "year":
      valueFormat = "YYYY";
      break;
    case "week":
      valueFormat = "YYYY-wo";
      break;
    case "quarter":
      valueFormat = "YYYY-[Q]Q";
      break;
    default:
      valueFormat = "YYYY-MM-DD";
  }
  if (format) {
    valueFormat = format;
  }
  return valueFormat;
}
var defaultProps = {
  allowClear: true,
  unmountOnExit: true,
  position: "bl",
  editable: true,
  mode: "date"
};
var Picker = function(baseProps) {
  var _a, _b;
  var _c = useContext(ConfigContext), getPrefixCls = _c.getPrefixCls, locale = _c.locale, ctxSize = _c.size, componentConfig = _c.componentConfig, rtl = _c.rtl;
  if (rtl) {
    defaultProps.position = "br";
  }
  var props = useMergeProps(baseProps, defaultProps, componentConfig === null || componentConfig === void 0 ? void 0 : componentConfig.DatePicker);
  var allowClear = props.allowClear, className = props.className, style = props.style, placeholder = props.placeholder, getPopupContainer = props.getPopupContainer, disabled = props.disabled, position = props.position, error = props.error, unmountOnExit = props.unmountOnExit, editable = props.editable, triggerProps = props.triggerProps, shortcuts = props.shortcuts, onSelect = props.onSelect, onVisibleChange = props.onVisibleChange, propsValue = props.value, onChange = props.onChange, icons = props.icons, disabledDate = props.disabledDate, disabledTime = props.disabledTime, mode = props.mode, showTime = props.showTime, onSelectShortcut = props.onSelectShortcut, extra = props.extra, shortcutsPlacementLeft = props.shortcutsPlacementLeft, onOk = props.onOk, defaultPickerValue = props.defaultPickerValue, pickerValue = props.pickerValue, panelRender = props.panelRender, onPickerValueChange = props.onPickerValueChange, triggerElement = props.triggerElement, clearRangeOnReselect = props.clearRangeOnReselect, separator = props.separator, utcOffset = props.utcOffset, timezone = props.timezone;
  var prefixCls = getPrefixCls("picker-range");
  var weekStart = isUndefined(props.dayStartOfWeek) ? getDefaultWeekStart(locale.dayjsLocale) : props.dayStartOfWeek;
  var refInput = useRef(null);
  var refPanel = useRef(null);
  var refShortcuts = useRef(null);
  var shortcutEnterTimer = useRef(null);
  var shortcutLeaveTimer = useRef(null);
  var format = getFormat(props);
  function getAvailableInputIndex() {
    if (isArray(disabled)) {
      if (disabled[0] && !disabled[1]) {
        return 1;
      }
      if (disabled[1] && !disabled[0]) {
        return 0;
      }
    }
  }
  var availableInputIndex = getAvailableInputIndex();
  var isHalfAvailable = typeof availableInputIndex === "number";
  var disabledTimePickerIndex = isHalfAvailable ? 1 ^ availableInputIndex : void 0;
  var _d = __read(useState(isHalfAvailable ? availableInputIndex : 0), 2), focusedInputIndex = _d[0], setFocusedInputIndex = _d[1];
  useEffect(function() {
    if (isHalfAvailable) {
      setFocusedInputIndex(availableInputIndex);
    }
  }, [disabled]);
  var nextFocusedInputIndex = 1 ^ focusedInputIndex;
  var _e = __read(useState(), 2), inputValue = _e[0], setInputValue = _e[1];
  var _f = __read(useState(), 2), hoverPlaceholderValue = _f[0], setHoverPlaceholderValue = _f[1];
  var _g = __read(useState(getDefaultValue()), 2), value = _g[0], setValue = _g[1];
  var _h = __read(useState(), 2), valueShow = _h[0], setValueShow = _h[1];
  var _j = __read(useState(), 2), valueShowHover = _j[0], setValueShowHover = _j[1];
  var _k = __read(useState(), 2), shortcutsValue = _k[0], setShortcutsValue = _k[1];
  var _l = __read(useState(props.popupVisible), 2), popupVisible = _l[0], setPopupVisible = _l[1];
  var _m = __read(useState([mode, mode]), 2), panelModes = _m[0], setPanelModes = _m[1];
  var _o = __read(useState(false), 2), isTimePanel = _o[0], setIsTimePanel = _o[1];
  var mergedPopupVisible = "popupVisible" in props ? props.popupVisible : popupVisible;
  var propsValueDayjs = getDayjsValue(propsValue, format, utcOffset, timezone);
  var mergedValue = "value" in props ? propsValueDayjs : value;
  var panelValue = shortcutsValue || valueShow || mergedValue || [];
  var selectedLength = getAvailableDayjsLength(valueShow || mergedValue);
  var firstRange = useRef(true);
  var now = getNow();
  var zoneNow = toTimezone(now, utcOffset, timezone);
  function getTimeValues() {
    var timeValues2 = [];
    var defaultTimeValue = isObject(showTime) && showTime.defaultValue ? getDayjsValue(showTime.defaultValue, showTime.format || "HH:mm:ss", utcOffset, timezone) : [];
    timeValues2[0] = panelValue[0] || defaultTimeValue[0] || zoneNow;
    timeValues2[1] = panelValue[1] || defaultTimeValue[1] || zoneNow;
    return timeValues2;
  }
  var timeValues = getTimeValues();
  var selectedDisabledDate = isHalfAvailable ? function(current) {
    return availableInputIndex === 0 ? current.isAfter(panelValue[1], mode) : current.isBefore(panelValue[0], mode);
  } : void 0;
  var customTriggerElement = triggerElement !== void 0;
  var resetRange = customTriggerElement || clearRangeOnReselect;
  function getDefaultValue() {
    var value2;
    if (props.value) {
      value2 = getDayjsValue(props.value, format, utcOffset, timezone);
    } else {
      value2 = getDayjsValue(props.defaultValue, format, utcOffset, timezone);
    }
    if (isHalfAvailable && (!value2 || value2 && !value2[nextFocusedInputIndex])) {
      var nv = [];
      nv[nextFocusedInputIndex] = getNow(utcOffset, timezone);
      return nv;
    }
    return value2;
  }
  var defaultPageShowDates = mergedValue || getDayjsValue(defaultPickerValue, format) || [now, now];
  var _p = __read(useState(getShowDatesFromFocused(defaultPageShowDates)), 2), pageShowDates = _p[0], setPageShowDates = _p[1];
  var mergedPageShowDate = getShowDatesFromFocused(getDayjsValue(pickerValue, format, utcOffset, timezone)) || pageShowDates;
  var previousUtcOffset = usePrevious(utcOffset);
  var previousTimezone = usePrevious(timezone);
  useUpdate(function() {
    if (isArray(value) && (previousUtcOffset !== utcOffset || timezone !== previousTimezone)) {
      var localValue = value.map(function(v) {
        return toLocal(v, previousUtcOffset, previousTimezone);
      });
      var zoneValue = localValue.map(function(v) {
        return toTimezone(v, utcOffset, timezone);
      });
      setValue(zoneValue);
    }
  }, [utcOffset, previousUtcOffset, timezone, previousTimezone]);
  useEffect(function() {
    setPanelModes([mode, mode]);
  }, [mode]);
  useEffect(function() {
    setHoverPlaceholderValue(void 0);
    setInputValue(void 0);
    if (mergedPopupVisible) {
      setIsTimePanel(false);
      setPanelModes([mode, mode]);
      setPageShowDates(getShowDatesFromFocused(defaultPageShowDates));
      setValueShow(mergedValue);
      if (shortcutsPlacementLeft) {
        refShortcuts.current.style.maxHeight = refPanel.current.clientHeight + "px";
      }
    } else {
      setValueShow(void 0);
      setValueShowHover(void 0);
      setShortcutsValue(void 0);
      blurInput();
    }
    firstRange.current = mergedPopupVisible;
  }, [mergedPopupVisible]);
  var startStr = (_a = propsValueDayjs === null || propsValueDayjs === void 0 ? void 0 : propsValueDayjs[0]) === null || _a === void 0 ? void 0 : _a.format(format);
  var endStr = (_b = propsValueDayjs === null || propsValueDayjs === void 0 ? void 0 : propsValueDayjs[1]) === null || _b === void 0 ? void 0 : _b.format(format);
  useEffect(function() {
    setValueShow(void 0);
    setValueShowHover(void 0);
  }, [startStr, endStr]);
  function setFixedPageShowDates(innerValue, index) {
    if (index === void 0) {
      index = focusedInputIndex;
    }
    var newPageShowDates = getShowDatesFromFocused(innerValue, index);
    setPageShowDates(newPageShowDates);
    handlePickerValueChange(newPageShowDates);
  }
  function handlePickerValueChange(v) {
    if (!isSamePanel([v[0], pageShowDates[0]], mode)) {
      onPickerValueChange && onPickerValueChange(isArray(v) ? v.map(function(v2) {
        return v2 && v2.format(format);
      }) : void 0, v);
    }
  }
  function getShowDatesFromFocused(dates, index) {
    if (index === void 0) {
      index = focusedInputIndex;
    }
    var prev = index === 0 || isSamePanel(dates, mode);
    if (isArray(dates) && dates.length < 2) {
      return getPageShowDatesByValue(dates[0] || getNow(utcOffset, timezone), mode, "prev");
    }
    if (isArray(dates) && dates.length === 2) {
      if (dates[index]) {
        return getPageShowDatesByValue(dates[index], mode, prev ? "prev" : "next");
      }
      return getPageShowDatesByValue(dates[index === 0 ? 1 : 0] || getNow(utcOffset, timezone), mode, prev && !dates[index === 0 ? 1 : 0] ? "prev" : "next");
    }
  }
  function isSamePanel(innerValue, pickerMode) {
    if (innerValue && innerValue.length === 2 && isValidDayjsArray(innerValue)) {
      return (pickerMode === "date" || pickerMode === "week") && innerValue[0].isSame(innerValue[1], "month") || (pickerMode === "month" || pickerMode === "quarter") && innerValue[0].isSame(innerValue[1], "year") || pickerMode === "year" && Math.floor(innerValue[0].year() / 10) === Math.floor(innerValue[1].year() / 10);
    }
  }
  function getPageShowDatesByValue(value2, pickerMode, type) {
    if (value2 === void 0) {
      value2 = getNow(utcOffset, timezone);
    }
    if (pickerMode === void 0) {
      pickerMode = mode;
    }
    if (type === void 0) {
      type = "prev";
    }
    var prev = type === "prev";
    switch (pickerMode) {
      case "date":
      case "week":
        return prev ? [value2, methods.add(value2, 1, "month")] : [methods.subtract(value2, 1, "month"), value2];
      case "month":
      case "quarter":
        return prev ? [value2, methods.add(value2, 1, "year")] : [methods.subtract(value2, 1, "year"), value2];
      case "year":
        return prev ? [value2, methods.add(value2, 10, "year")] : [methods.subtract(value2, 10, "year"), value2];
      default:
        return [];
    }
  }
  function focusInput(index) {
    refInput.current && refInput.current.focus && refInput.current.focus(isHalfAvailable ? availableInputIndex : index);
  }
  function blurInput() {
    refInput.current && refInput.current.blur && refInput.current.blur();
  }
  function visibleChange(visible) {
    if (visible) {
      setTimeout(function() {
        return focusInput();
      });
      setOpen(visible);
    } else {
      setOpen(false);
    }
  }
  function setOpen(visible) {
    onVisibleChange && onVisibleChange(visible);
    setPopupVisible(visible);
  }
  function onClear(e) {
    e.stopPropagation();
    var newValueShow = __spreadArray([], __read(panelValue), false);
    if (isHalfAvailable) {
      newValueShow[availableInputIndex] = void 0;
    } else {
      newValueShow = void 0;
    }
    setValue(newValueShow);
    setValueShow(newValueShow);
    onHandleChange(newValueShow);
    props.onClear && props.onClear();
  }
  function changeFocusedInputIndex(index, silent) {
    setInputValue(void 0);
    setFocusedInputIndex(index);
    if (panelValue && panelValue.length && !silent) {
      var newPageShowDates = getShowDatesFromFocused(panelValue, index);
      setPageShowDates(newPageShowDates);
      handlePickerValueChange(newPageShowDates);
    }
  }
  function isDisabledDate(date) {
    var selectedDisabled = typeof selectedDisabledDate === "function" ? selectedDisabledDate(date) : false;
    var originDisabledDate = typeof disabledDate === "function" ? disabledDate(date) : false;
    return originDisabledDate || selectedDisabled;
  }
  function isValid(time) {
    return isValidTimeString(time, format) && !isDisabledDate(getDayjsValue(time, format));
  }
  function onChangeInput(e) {
    var newValueShow = __spreadArray([], __read(panelValue || []), false);
    var niv = e.target.value;
    setInputValue(niv);
    if (!mergedPopupVisible) {
      setOpen(true);
    }
    if (isValid(niv)) {
      newValueShow[focusedInputIndex] = getDayjsValue(niv, format);
      setValueShow(newValueShow);
      setFixedPageShowDates(newValueShow);
      setInputValue(void 0);
    }
  }
  function onHandleChange(newValue) {
    if (isDayjsArrayChange(mergedValue, newValue)) {
      var localValue = isArray(newValue) ? newValue.map(function(v) {
        return getLocaleDayjsValue(toLocal(v, utcOffset, timezone), locale.dayjsLocale);
      }) : void 0;
      onChange && onChange(isArray(localValue) ? localValue.map(function(v) {
        return v && v.format(format);
      }) : void 0, localValue);
    }
  }
  function onPressEnter() {
    if (isArray(valueShow) && valueShow.length) {
      if (inputValue && !isValid(inputValue)) {
        setInputValue(void 0);
      } else if (selectedLength !== 2) {
        switchFocusedInput();
      } else if (selectedLength === 2) {
        onConfirmValue(valueShow);
      }
    } else if (mergedPopupVisible) {
      setOpen(false);
    }
  }
  function onPressTab(e) {
    e.preventDefault();
  }
  function onConfirmValue(date, keepOpen) {
    var confirmValue = date || panelValue;
    if (!confirmValue || !confirmValue[0] || !confirmValue[1]) {
      return;
    }
    var sortedValues = getSortedDayjsArray(confirmValue);
    setValue(sortedValues);
    onHandleChange(sortedValues);
    if (triggerElement !== null && !keepOpen) {
      setOpen(false);
    }
  }
  function onClickConfirmBtn() {
    onConfirmValue();
    var localePanelValue = panelValue.map(function(v) {
      return getLocaleDayjsValue(v, locale.dayjsLocale);
    });
    onOk && onOk(localePanelValue.map(function(v) {
      return v && v.format(format);
    }), localePanelValue);
  }
  function getUnit() {
    switch (mode) {
      case "date":
      case "week":
        return "date";
      case "month":
        return "month";
      case "year":
        return "year";
      default:
        return void 0;
    }
  }
  function outOfRange(date) {
    if (selectedLength !== 2) {
      return false;
    }
    var v = valueShow || mergedValue;
    if (focusedInputIndex === 0 && date.isAfter(v[1], getUnit())) {
      return true;
    }
    if (focusedInputIndex === 1 && date.isBefore(v[0], getUnit())) {
      return true;
    }
    return false;
  }
  function onSelectPanel(_, date) {
    var isOutOfRange = outOfRange(date) && firstRange.current;
    var newValueShow = resetRange && selectedLength === 2 && !isHalfAvailable ? [] : __spreadArray([], __read(panelValue), false);
    var focusedIndex = customTriggerElement ? selectedLength === 0 || selectedLength === 2 ? 0 : 1 : focusedInputIndex;
    var newDate = showTime ? getValueWithTime(date, timeValues[focusedIndex]) : date;
    if (isOutOfRange) {
      newValueShow[focusedIndex] = newDate;
      newValueShow[1 ^ focusedIndex] = void 0;
    } else {
      newValueShow[focusedIndex] = newDate;
    }
    var sortedValueShow = getSortedDayjsArray(newValueShow);
    onSelectValueShow(sortedValueShow);
    setFixedPageShowDates(sortedValueShow);
    setInputValue(void 0);
    setHoverPlaceholderValue(void 0);
    var newSelectedLength = getAvailableDayjsLength(newValueShow);
    if (resetRange) {
      if (selectedLength === 0 || selectedLength === 2 && !isHalfAvailable) {
        customTriggerElement ? setFocusedInputIndex(1) : switchFocusedInput(true);
      } else if (!showTime) {
        onConfirmValue(newValueShow);
      }
    } else if (newSelectedLength <= 1) {
      switchFocusedInput(true);
    } else if (selectedLength === 2 && firstRange.current && !isHalfAvailable) {
      firstRange.current = false;
      switchFocusedInput(true);
      if (!showTime && !isOutOfRange) {
        onConfirmValue(newValueShow, true);
      }
    } else {
      firstRange.current = false;
      if (!showTime && !isOutOfRange) {
        onConfirmValue(newValueShow);
      }
    }
  }
  function onTimePickerSelect(index, _, time) {
    var newValueShow = isArray(panelValue) ? __spreadArray([], __read(panelValue), false) : [];
    var newTimeValue = getValueWithTime(newValueShow[index] || getNow(utcOffset, timezone), time);
    newValueShow[index] = newTimeValue;
    onSelectValueShow(newValueShow);
  }
  function onSelectValueShow(newValueShow) {
    setValueShow(newValueShow);
    setValueShowHover(void 0);
    var sortedValues = getSortedDayjsArray(newValueShow);
    var zoneValues = sortedValues.map(function(v) {
      return getLocaleDayjsValue(toLocal(v, utcOffset, timezone), locale.dayjsLocale);
    });
    onSelect && onSelect(zoneValues.map(function(v) {
      return v && v.format(format);
    }), zoneValues, {
      type: focusedInputIndex === 1 ? "end" : "start"
    });
  }
  function switchFocusedInput(silent) {
    changeFocusedInputIndex(nextFocusedInputIndex, silent);
    setTimeout(function() {
      return focusInput(nextFocusedInputIndex);
    });
  }
  function onMouseEnterCell(date, disabled2) {
    var newValueShowHover = __spreadArray([], __read(panelValue || []), false);
    var needShowHover = resetRange ? selectedLength === 1 : selectedLength !== 0;
    if (!disabled2 && needShowHover && !outOfRange(date)) {
      newValueShowHover[focusedInputIndex] = getValueWithTime(date, timeValues[focusedInputIndex]);
      setValueShowHover(newValueShowHover);
      setInputValue(void 0);
    }
    if (!disabled2) {
      var placeHolderValue = showTime ? getValueWithTime(date, timeValues[focusedInputIndex]) : date;
      setHoverPlaceholderValue(placeHolderValue.locale(locale.dayjsLocale).format(format));
    }
  }
  function onMouseLeaveCell() {
    setValueShowHover(void 0);
    setHoverPlaceholderValue(void 0);
  }
  function isValidDayjsArray(sv) {
    return sv && isArray(sv) && sv.length === 2 && isDayjs(sv[0]) && isDayjs(sv[1]);
  }
  function isValidShortcut(shortcut) {
    var sv = typeof shortcut.value === "function" && shortcut.value();
    return isValidDayjsArray(sv);
  }
  function clearShortcutsTimer() {
    clearTimeout(shortcutEnterTimer.current);
    clearTimeout(shortcutLeaveTimer.current);
    shortcutEnterTimer.current = null;
    shortcutLeaveTimer.current = null;
  }
  function onMouseEnterShortcut(shortcut) {
    clearShortcutsTimer();
    shortcutEnterTimer.current = setTimeout(function() {
      if (isValidShortcut(shortcut)) {
        var nv = getDayjsValue(shortcut.value(), format, utcOffset, timezone);
        setShortcutsValue(nv);
        setFixedPageShowDates(nv);
      }
    }, 50);
  }
  function onMouseLeaveShortcut() {
    clearShortcutsTimer();
    shortcutLeaveTimer.current = setTimeout(function() {
      setShortcutsValue(void 0);
      setFixedPageShowDates(valueShow || mergedValue || [getNow(utcOffset, timezone), getNow(utcOffset, timezone)]);
    }, 50);
  }
  function onHandleSelectShortcut(shortcut) {
    onSelectShortcut && onSelectShortcut(shortcut);
    if (isValidShortcut(shortcut)) {
      var time = getDayjsValue(shortcut.value(), format, utcOffset, timezone);
      onConfirmValue(time);
    }
  }
  function changePageShowDates(type, unit, num) {
    if (num === void 0) {
      num = 1;
    }
    var index = type === "prev" ? 0 : 1;
    var newPageShowDates = __spreadArray([], __read(mergedPageShowDate), false);
    if (type === "prev") {
      newPageShowDates[index] = methods.subtract(mergedPageShowDate[index], num, unit);
    }
    if (type === "next") {
      newPageShowDates[index] = methods.add(mergedPageShowDate[index], num, unit);
    }
    newPageShowDates = getPageShowDatesByValue(newPageShowDates[index], mode, type);
    setFixedPageShowDates(newPageShowDates);
  }
  function getHeaderOperations(pickerMode) {
    if (pickerMode === void 0) {
      pickerMode = mode;
    }
    if (pickerMode === "date" || pickerMode === "week") {
      return {
        onPrev: function() {
          return changePageShowDates("prev", "month");
        },
        onNext: function() {
          return changePageShowDates("next", "month");
        },
        onSuperPrev: function() {
          return changePageShowDates("prev", "year");
        },
        onSuperNext: function() {
          return changePageShowDates("next", "year");
        }
      };
    }
    if (pickerMode === "month" || pickerMode === "quarter") {
      return {
        onSuperPrev: function() {
          return changePageShowDates("prev", "year");
        },
        onSuperNext: function() {
          return changePageShowDates("next", "year");
        }
      };
    }
    if (pickerMode === "year") {
      return {
        onSuperPrev: function() {
          return changePageShowDates("prev", "year", 10);
        },
        onSuperNext: function() {
          return changePageShowDates("next", "year", 10);
        }
      };
    }
  }
  function onClickSelectTimeBtn() {
    setIsTimePanel(!isTimePanel);
  }
  function renderPopup(panelOnly) {
    var _a2;
    var classNames = cs(prefixCls + "-container", (_a2 = {}, _a2[prefixCls + "-panel-only"] = panelOnly, _a2[prefixCls + "-container-shortcuts-placement-left"] = isArray(shortcuts) && shortcutsPlacementLeft, _a2[prefixCls + "-container-rtl"] = rtl, _a2), panelOnly ? className : "");
    var shortcutsProps = {
      prefixCls: getPrefixCls("picker"),
      showTime,
      shortcuts,
      onMouseEnterShortcut,
      onMouseLeaveShortcut,
      onSelectShortcut: onHandleSelectShortcut
    };
    var shouldShowFooter = showTime && panelModes[0] === "date" && panelModes[1] === "date" || extra || isArray(shortcuts) && shortcuts.length && !shortcutsPlacementLeft;
    var content = /* @__PURE__ */ jsxs(Fragment, {
      children: [/* @__PURE__ */ jsx(RangePicker, {
        ...__assign({}, props, getHeaderOperations(), {
          getHeaderOperations,
          setRangePageShowDates: setFixedPageShowDates,
          pageShowDates: mergedPageShowDate,
          value: panelValue,
          format,
          onSelectPanel,
          onMouseEnterCell,
          onMouseLeaveCell,
          disabledDate: function(current) {
            return isDisabledDate(current);
          },
          disabledTime,
          mode,
          localeName: locale.dayjsLocale,
          showTime,
          timeValues: shortcutsValue || timeValues,
          onTimePickerSelect,
          popupVisible: mergedPopupVisible,
          disabledTimePickerIndex,
          isTimePanel,
          valueShowHover,
          panelModes,
          setPanelModes
        })
      }), shouldShowFooter && /* @__PURE__ */ jsx(Footer, {
        ...__assign({}, shortcutsProps, {
          DATEPICKER_LOCALE: locale.DatePicker,
          disabled: !(isArray(panelValue) && panelValue[0] && panelValue[1]),
          onClickConfirmBtn,
          extra,
          shortcutsPlacementLeft,
          onClickSelectTimeBtn,
          isTimePanel
        })
      })]
    });
    var contentWithShortcuts = shortcutsPlacementLeft ? /* @__PURE__ */ jsxs(Fragment, {
      children: [/* @__PURE__ */ jsx(Shortcuts, {
        ...__assign({
          ref: refShortcuts
        }, shortcutsProps)
      }), /* @__PURE__ */ jsx("div", {
        ref: refPanel,
        className: prefixCls + "-panel-wrapper",
        children: content
      })]
    }) : content;
    var panelNode = typeof panelRender === "function" ? panelRender(contentWithShortcuts) : contentWithShortcuts;
    return /* @__PURE__ */ jsx("div", {
      className: classNames,
      onClick: function() {
        return focusInput();
      },
      style: panelOnly ? style : {},
      children: panelNode
    });
  }
  var size = props.size || ctxSize;
  var placeholders = isArray(placeholder) ? placeholder : locale.DatePicker.placeholders[mode];
  var suffixIcon = icons && icons.inputSuffix === null ? null : icons && icons.inputSuffix || (showTime ? /* @__PURE__ */ jsx(IconCalendarClock, {}) : /* @__PURE__ */ jsx(IconCalendar, {}));
  var baseInputProps = {
    style,
    className,
    popupVisible: mergedPopupVisible,
    format,
    disabled,
    error,
    size,
    onPressEnter,
    onPressTab,
    onClear,
    suffixIcon,
    editable,
    allowClear
  };
  var triggerDisabled = isArray(disabled) ? disabled[0] && disabled[1] : disabled;
  return /* @__PURE__ */ jsx(PickerContext.Provider, {
    value: {
      utcOffset,
      timezone,
      weekStart
    },
    children: triggerElement === null ? renderPopup(true) : /* @__PURE__ */ jsx(Trigger, {
      ...__assign({
        popup: renderPopup,
        trigger: "click",
        clickToClose: false,
        position,
        disabled: triggerDisabled,
        popupAlign: {
          bottom: 4
        },
        getPopupContainer,
        onVisibleChange: visibleChange,
        popupVisible: mergedPopupVisible,
        classNames: "slideDynamicOrigin",
        unmountOnExit
      }, triggerProps),
      children: triggerElement || /* @__PURE__ */ jsx(InputRange, {
        ...__assign({}, pickDataAttributes(props), baseInputProps, {
          ref: refInput,
          placeholder: placeholders,
          value: valueShow || mergedValue,
          onChange: onChangeInput,
          inputValue: hoverPlaceholderValue || inputValue,
          changeFocusedInputIndex,
          focusedInputIndex,
          isPlaceholder: !!hoverPlaceholderValue,
          separator
        })
      })
    })
  });
};
Picker.displayName = "RangePicker";
const PickerRange = Picker;
export {
  PickerRange as default
};
//# sourceMappingURL=picker-range.js.map
