"use strict";
const React = require("react");
const index$1 = require("../../../icon/react-icon/IconClose/index.js");
const iconHover = require("../icon-hover.js");
const classNames = require("../../_util/classNames.js");
const keycode = require("../../_util/keycode.js");
const omit = require("../../_util/omit.js");
const index = require("../../ConfigProvider/index.js");
const is = require("../../_util/is.js");
const emotionReactJsxRuntime_browser_esm = require("../../../../../../../@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 __rest = globalThis && globalThis.__rest || function(s, e) {
  var t = {};
  for (var p in s)
    if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
      t[p] = s[p];
  if (s != null && typeof Object.getOwnPropertySymbols === "function")
    for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
      if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
        t[p[i]] = s[p[i]];
    }
  return t;
};
function DateInput(_a, ref) {
  var _b;
  var allowClear = _a.allowClear, error = _a.error, style = _a.style, className = _a.className, disabled = _a.disabled, _c = _a.placeholder, placeholder = _c === void 0 ? [] : _c, _d = _a.value, value = _d === void 0 ? [] : _d, popupVisible = _a.popupVisible, format = _a.format, propSize = _a.size, onClear = _a.onClear, editable = _a.editable, inputValue = _a.inputValue, onPressEnter = _a.onPressEnter, onPressTab = _a.onPressTab, onChange = _a.onChange, separator = _a.separator, suffixIcon = _a.suffixIcon, changeFocusedInputIndex = _a.changeFocusedInputIndex, focusedInputIndex = _a.focusedInputIndex, isPlaceholder = _a.isPlaceholder, rest = __rest(_a, ["allowClear", "error", "style", "className", "disabled", "placeholder", "value", "popupVisible", "format", "size", "onClear", "editable", "inputValue", "onPressEnter", "onPressTab", "onChange", "separator", "suffixIcon", "changeFocusedInputIndex", "focusedInputIndex", "isPlaceholder"]);
  var _e = React.useContext(index.ConfigContext), getPrefixCls = _e.getPrefixCls, ctxSize = _e.size, locale = _e.locale, rtl = _e.rtl;
  var input0 = React.useRef(null);
  var input1 = React.useRef(null);
  var disabled1 = is.isArray(disabled) ? disabled[0] : disabled;
  var disabled2 = is.isArray(disabled) ? disabled[1] : disabled;
  React.useImperativeHandle(ref, function() {
    return {
      focus: function(index2) {
        var focusedIndex = typeof index2 === "number" ? index2 : focusedInputIndex;
        var focusElement = focusedIndex === 0 ? input0 : input1;
        if (focusedInputIndex === 0 && !disabled1 || focusedInputIndex === 1 && !disabled2) {
          focusElement.current && focusElement.current.focus && focusElement.current.focus();
        }
      },
      blur: function() {
        if (focusedInputIndex === 0) {
          input0.current && input0.current.blur && input0.current.blur();
        }
        if (focusedInputIndex === 1) {
          input1.current && input1.current.blur && input1.current.blur();
        }
      }
    };
  });
  function changeFocusedInput(index2) {
    if (focusedInputIndex !== index2) {
      changeFocusedInputIndex(index2);
    }
  }
  function onKeyDown(e) {
    var keyCode = e.keyCode || e.which;
    if (keyCode === keycode.Enter.code) {
      onPressEnter && onPressEnter();
    }
    if (keyCode === keycode.Tab.code) {
      onPressTab && onPressTab(e);
    }
  }
  function onChangeInput(e) {
    e.stopPropagation();
    onChange && onChange(e);
  }
  var prefixCls = getPrefixCls("picker");
  var size = propSize || ctxSize;
  var inputClassNames = classNames(prefixCls, prefixCls + "-range", prefixCls + "-size-" + size, (_b = {}, _b[prefixCls + "-focused"] = !!popupVisible, _b[prefixCls + "-disabled"] = disabled1 && disabled2, _b[prefixCls + "-error"] = error, _b[prefixCls + "-rtl"] = rtl, _b), className);
  var getInputValue = function(index2) {
    var valueText = value[index2] ? value[index2].locale(locale.dayjsLocale).format(format) : "";
    if (inputValue) {
      return index2 === focusedInputIndex ? inputValue : valueText;
    }
    return valueText;
  };
  var readOnlyProps = editable ? {} : {
    readOnly: true
  };
  function getFocusInputClassName(index2) {
    var _a2;
    return classNames(prefixCls + "-input", (_a2 = {}, _a2[prefixCls + "-input-active"] = focusedInputIndex === index2, _a2[prefixCls + "-input-placeholder"] = isPlaceholder && focusedInputIndex === index2, _a2));
  }
  return /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsxs("div", {
    ...__assign({
      style,
      className: inputClassNames
    }, omit(rest, ["onChange", "onPressEnter"])),
    children: [/* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("div", {
      className: getFocusInputClassName(0),
      children: /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("input", {
        ...__assign({
          ref: input0,
          disabled: disabled1,
          placeholder: placeholder[0],
          value: getInputValue(0),
          onChange: onChangeInput,
          onKeyDown,
          onClick: function() {
            return changeFocusedInput(0);
          }
        }, readOnlyProps)
      })
    }), /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("span", {
      className: prefixCls + "-separator",
      children: separator || "-"
    }), /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("div", {
      className: getFocusInputClassName(1),
      children: /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("input", {
        ...__assign({
          ref: input1,
          disabled: disabled2,
          placeholder: placeholder[1],
          value: getInputValue(1),
          onChange: onChangeInput,
          onKeyDown,
          onClick: function() {
            return changeFocusedInput(1);
          }
        }, readOnlyProps)
      })
    }), /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsxs("div", {
      className: prefixCls + "-suffix",
      children: [allowClear && value.length === 2 && /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(iconHover, {
        prefix: prefixCls,
        onClick: onClear,
        className: prefixCls + "-clear-icon",
        children: /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(index$1, {})
      }), /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("span", {
        className: prefixCls + "-suffix-icon",
        children: suffixIcon
      })]
    })]
  });
}
const InputRange = React.forwardRef(DateInput);
module.exports = InputRange;
//# sourceMappingURL=input-range.js.map
