import { forwardRef, useContext, useRef, useImperativeHandle } from "react";
import omit from "../../_util/omit.js";
import { Enter } from "../../_util/keycode.js";
import { ConfigContext } from "../../ConfigProvider/index.js";
import IconClose from "../../../icon/react-icon/IconClose/index.js";
import IconHover from "../icon-hover.js";
import cs from "../../_util/classNames.js";
import { isArray } from "../../_util/is.js";
import { jsxs, jsx } 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 __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, _c;
  var style = _a.style, className = _a.className, propPrefixCls = _a.prefixCls, allowClear = _a.allowClear, error = _a.error, disabled = _a.disabled, placeholder = _a.placeholder, format = _a.format, propSize = _a.size, onClear = _a.onClear, editable = _a.editable, value = _a.value, inputValue = _a.inputValue, onPressEnter = _a.onPressEnter, suffixIcon = _a.suffixIcon, onChange = _a.onChange, popupVisible = _a.popupVisible, isPlaceholder = _a.isPlaceholder, rest = __rest(_a, ["style", "className", "prefixCls", "allowClear", "error", "disabled", "placeholder", "format", "size", "onClear", "editable", "value", "inputValue", "onPressEnter", "suffixIcon", "onChange", "popupVisible", "isPlaceholder"]);
  var _d = useContext(ConfigContext), getPrefixCls = _d.getPrefixCls, ctxSize = _d.size, locale = _d.locale, rtl = _d.rtl;
  var input = useRef(null);
  var size = propSize || ctxSize;
  useImperativeHandle(ref, function() {
    return {
      focus: function() {
        input.current && input.current.focus && input.current.focus();
      },
      blur: function() {
        input.current && input.current.blur && input.current.blur();
      }
    };
  });
  function onKeyDown(e) {
    var keyCode = e.keyCode || e.which;
    if (keyCode === Enter.code) {
      onPressEnter && onPressEnter();
    }
  }
  var showValue = "";
  if (inputValue !== void 0) {
    showValue = inputValue;
  } else if (value && !isArray(value)) {
    showValue = typeof format === "function" ? format(value) : value.locale(locale.dayjsLocale).format(format);
  }
  var readOnlyProps = editable ? {} : {
    readOnly: true
  };
  var prefixCls = propPrefixCls || getPrefixCls("picker");
  var classNames = cs(prefixCls, prefixCls + "-size-" + size, (_b = {}, _b[prefixCls + "-focused"] = !!popupVisible, _b[prefixCls + "-disabled"] = disabled, _b[prefixCls + "-error"] = error, _b[prefixCls + "-rtl"] = rtl, _b), className);
  return /* @__PURE__ */ jsxs("div", {
    ...__assign({
      style,
      className: classNames
    }, omit(rest, ["onChange", "onPressEnter"])),
    children: [/* @__PURE__ */ jsx("div", {
      className: cs(prefixCls + "-input", (_c = {}, _c[prefixCls + "-input-placeholder"] = isPlaceholder, _c)),
      children: /* @__PURE__ */ jsx("input", {
        ...__assign({
          ref: input,
          disabled,
          placeholder,
          className: prefixCls + "-start-time",
          value: showValue,
          onKeyDown,
          onChange
        }, readOnlyProps)
      })
    }), /* @__PURE__ */ jsxs("div", {
      className: prefixCls + "-suffix",
      children: [allowClear && showValue && /* @__PURE__ */ jsx(IconHover, {
        prefix: prefixCls,
        onClick: onClear,
        className: prefixCls + "-clear-icon",
        children: /* @__PURE__ */ jsx(IconClose, {})
      }), /* @__PURE__ */ jsx("span", {
        className: prefixCls + "-suffix-icon",
        children: suffixIcon
      })]
    })]
  });
}
const Input = forwardRef(DateInput);
export {
  Input as default
};
//# sourceMappingURL=input.js.map
