import { jsxs as N, jsx as e } from "react/jsx-runtime";
import { useState as r, useRef as f } from "react";
import { noop as l } from "es-toolkit/function";
import h from "../../utils/classNames.js";
import X from "../button/Button.js";
import Z from "../datepicker/DatePicker.js";
import $ from "../../hooks/useIsFocusWithin.js";
import ee from "../../hooks/useEsc.js";
const se = "primary", pe = (k) => {
  const {
    placeholder: P,
    value: s = "",
    isValid: t = !0,
    errorMessage: m,
    hideErrorIcon: g = !1,
    onValueChanged: R = l,
    onInputChange: c,
    // for controlled usage
    onEnterEdit: V = l,
    onExitEdit: b = l,
    onCancel: S = l,
    buttonStyle: B = se,
    inputClassName: T,
    inputProps: D,
    invalidExitBehavior: C = "stay-open",
    datePickerProps: F = {},
    disabled: w = !1,
    className: O,
    ...W
  } = k, y = c !== void 0, [a, p] = r(s), [n, u] = r(!1), [j, E] = r(!1), [A, i] = r(!1), I = f(null), L = f(null), o = f(a);
  $({
    ref: I,
    onFocusWithin: () => {
      E(!0);
    },
    onBlurWithin: () => {
      E(!1);
    }
  }), ee(() => {
    j && n && v();
  });
  const [U, _] = r(s);
  U !== s && (p(s), _(s), n || (o.current = s));
  const z = () => {
    n ? M() : (u(!0), o.current = a, i(!0), V());
  }, M = () => {
    t ? (u(!1), R(a, o.current), b(!0), i(!1)) : C === "reset-and-close" && v();
  }, v = () => {
    u(!1), y ? c(o.current, !0) : p(o.current), i(!1), S(), b(!1);
  }, Y = (x, Q) => {
    y ? c(x, Q) : p(x);
  }, q = () => i(!1), G = h("form-group", !t && "has-feedback has-error", O), H = h("rioglyph", n ? "rioglyph-ok" : "rioglyph-pencil"), J = h("margin-0 width-100pct", T), K = w || n && !t && C === "stay-open";
  let d = {
    borderTopRightRadius: 0,
    borderBottomRightRadius: 0
  };
  return !t && g && (d = { ...d, paddingRight: "10px" }), /* @__PURE__ */ N("div", { ref: I, ...W, className: G, children: [
    /* @__PURE__ */ N("div", { className: "input-group", children: [
      /* @__PURE__ */ e(
        Z,
        {
          ...F,
          open: A,
          className: J,
          inputProps: {
            ...D,
            placeholder: P,
            disabled: !n,
            style: d
          },
          value: a,
          onChange: Y,
          onClose: q
        }
      ),
      !t && !g && /* @__PURE__ */ e("span", { className: "right-25 margin-right-10 form-control-feedback rioglyph rioglyph-error-sign" }),
      /* @__PURE__ */ e("div", { className: "input-group-btn", children: /* @__PURE__ */ e(
        X,
        {
          ref: L,
          bsStyle: B,
          iconOnly: !0,
          onClick: z,
          disabled: K,
          children: /* @__PURE__ */ e("span", { className: H })
        }
      ) })
    ] }),
    !t && m && /* @__PURE__ */ e("span", { className: "help-block z-index-max", children: /* @__PURE__ */ e("span", { children: m }) })
  ] });
};
export {
  pe as default
};
//# sourceMappingURL=SaveableDateInput.js.map
