import O from "../../../@ant-design/icons/es/icons/EnterOutlined.mjs";
import j from "../../../classnames/index.mjs";
import p from "../../../rc-util/es/KeyCode.mjs";
import * as n from "react";
import { cloneElement as q } from "../_util/reactNode.mjs";
import F from "../input/TextArea.mjs";
import G from "./style/index.mjs";
const H = (d) => {
  const {
    prefixCls: o,
    "aria-label": y,
    className: E,
    style: S,
    direction: x,
    maxLength: K,
    autoSize: g = !0,
    value: s,
    onSave: h,
    onCancel: v,
    onEnd: l,
    component: c,
    enterIcon: i = /* @__PURE__ */ n.createElement(O, null)
  } = d, r = n.useRef(null), a = n.useRef(!1), u = n.useRef(), [m, f] = n.useState(s);
  n.useEffect(() => {
    f(s);
  }, [s]), n.useEffect(() => {
    if (r.current && r.current.resizableTextArea) {
      const {
        textArea: t
      } = r.current.resizableTextArea;
      t.focus();
      const {
        length: e
      } = t.value;
      t.setSelectionRange(e, e);
    }
  }, []);
  const b = (t) => {
    let {
      target: e
    } = t;
    f(e.value.replace(/[\n\r]/g, ""));
  }, N = () => {
    a.current = !0;
  }, R = () => {
    a.current = !1;
  }, $ = (t) => {
    let {
      keyCode: e
    } = t;
    a.current || (u.current = e);
  }, C = () => {
    h(m.trim());
  }, A = (t) => {
    let {
      keyCode: e,
      ctrlKey: D,
      altKey: I,
      metaKey: U,
      shiftKey: V
    } = t;
    u.current === e && !a.current && !D && !I && !U && !V && (e === p.ENTER ? (C(), l == null || l()) : e === p.ESC && v());
  }, w = () => {
    C();
  }, z = c ? `${o}-${c}` : "", [T, L, k] = G(o), B = j(o, `${o}-edit-content`, {
    [`${o}-rtl`]: x === "rtl"
  }, E, z, L, k);
  return T(/* @__PURE__ */ n.createElement("div", {
    className: B,
    style: S
  }, /* @__PURE__ */ n.createElement(F, {
    ref: r,
    maxLength: K,
    value: m,
    onChange: b,
    onKeyDown: $,
    onKeyUp: A,
    onCompositionStart: N,
    onCompositionEnd: R,
    onBlur: w,
    "aria-label": y,
    rows: 1,
    autoSize: g
  }), i !== null ? q(i, {
    className: `${o}-edit-content-confirm`
  }) : null));
}, Y = H;
export {
  Y as default
};
