import { f7 as C, a0 as r, f8 as w, c1 as T, bX as L, bp as S, bP as f, bd as y, bK as I, ba as $, f9 as E, bv as v, cn as h, bb as P, fa as M, c0 as k, P as l, bi as u, bj as c, em as B, bk as O, bV as q, ds as N, dt as D, du as A, co as U, cG as W, fb as g } from "./684d2f28.js";
import { useState as _, useRef as x, useEffect as m } from "react";
import { formDataChildren as j } from "./00dac55d.js";
import { focusWithOptions as z, blurMethod as F, selectMethod as K, setSelectionRangeMethod as G, clickMethod as H, setRangeTextMethod as X } from "./d6402597.js";
import "react-dom";
const p = [{
  label: "Text",
  value: "Text",
  extra: /.*/,
  help: ""
}, {
  label: "Email",
  value: "Email",
  extra: C,
  help: r("validationDesc.email")
}, {
  label: "URL",
  value: "URL",
  extra: w,
  help: r("validationDesc.url")
}, {
  label: "Regex",
  value: "Regex",
  extra: void 0,
  help: r("validationDesc.regex")
}], i = T.fromPairs(p.map((e) => [e.value, e])), b = (e) => {
  var o;
  if (e.customRule)
    return {
      validateStatus: "error",
      help: e.customRule
    };
  const t = e.value.value;
  if (e.required && t.length === 0)
    return {
      validateStatus: "error",
      help: r("prop.required")
    };
  if (e.maxLength > 0 && t.length > e.maxLength)
    return {
      validateStatus: "error",
      help: r("validationDesc.maxLength", {
        length: t.length,
        maxLength: e.maxLength
      })
    };
  if (e.minLength > 0 && t.length < e.minLength)
    return {
      validateStatus: "error",
      help: r("validationDesc.minLength", {
        length: t.length,
        minLength: e.minLength
      })
    };
  const a = e.validationType, n = ((o = i[a]) == null ? void 0 : o.extra) ?? e.regex;
  return t && !n.test(t) ? {
    validateStatus: "error",
    help: i[a].help
  } : {
    validateStatus: ""
  };
}, J = L({
  name: "invalid",
  desc: r("export.invalidDesc"),
  depKeys: ["value", "required", "minLength", "maxLength", "validationType", "regex", "customRule"],
  func: (e) => b({
    ...e,
    value: {
      value: e.value
    }
  }).validateStatus !== ""
}), ne = [J, ...S], oe = {
  defaultValue: f("defaultValue"),
  value: f("value"),
  disabled: y,
  label: I,
  placeholder: $,
  onEvent: E,
  readOnly: v,
  // validation
  required: v,
  minLength: h,
  maxLength: h,
  validationType: P(p, "Text"),
  regex: M,
  customRule: k,
  ...j
}, Q = (e) => ({
  disabled: e.disabled,
  readOnly: e.readOnly,
  placeholder: e.placeholder,
  defaultValue: e.defaultValue.value,
  value: e.value.value,
  onFocus: () => e.onEvent("focus"),
  onBlur: () => e.onEvent("blur"),
  onPressEnter: () => e.onEvent("submit")
}), re = (e) => {
  const [t, a] = _({}), n = x(!1), o = x(e);
  o.current = e;
  const s = {
    ...e.defaultValue
  }.value, d = {
    ...e.value
  }.value;
  m(() => {
    e.value.onChange(s);
  }, [s]), m(() => {
    n.current && (a(b({
      ...o.current,
      value: {
        value: d
      }
    })), o.current.onEvent("change"), n.current = !1);
  }, [d]);
  const V = (R) => {
    e.value.onChange(R.target.value), n.current = !0;
  };
  return [{
    ...Q(e),
    onChange: V
  }, t];
}, ie = (e) => /* @__PURE__ */ l(u, {
  name: c.basic,
  children: [e.defaultValue.propertyView({
    label: r("prop.defaultValue")
  }), B(e)]
}), le = (e) => /* @__PURE__ */ l(u, {
  name: c.interaction,
  children: [e.onEvent.getPropertyView(), O(e)]
}), ue = (e) => {
  var t;
  return /* @__PURE__ */ l(u, {
    name: c.validation,
    children: [q(e), e.validationType.propertyView({
      label: r("prop.textType")
    }), ((t = i[e.validationType.getView()]) == null ? void 0 : t.extra) === void 0 && N(e), D(e), A(e), e.customRule.propertyView({})]
  });
};
function ce(e, t) {
  return U`
    border-radius: ${e.radius};
    border-width: ${e.borderWidth};
    padding: ${e.padding};	
    // still use antd style when disabled
    &:not(.ant-input-disabled, .ant-input-affix-wrapper-disabled),
    input {
      color: ${e.text};
      font-size: ${e.textSize};
      font-weight: ${e.textWeight};
      font-family: ${e.fontFamily};
      font-style:${e.fontStyle};
      text-transform:${e.textTransform};
      text-decoration:${e.textDecoration};
      // background-color: ${e.background};
      border-color: ${e.border};

      &:focus,
      &.ant-input-affix-wrapper-focused {
        border-color: ${e.accent};
      }

      &:hover {
        border-color: ${e.accent};
      }

      &::-webkit-input-placeholder {
        color: ${e.text};
        opacity: 0.4;
      }

      .ant-input-show-count-suffix,
      .ant-input-prefix,
      .ant-input-suffix svg {
        opacity: 0.45;
        color: ${e.text};
      }

      .ant-input-clear-icon svg:hover {
        opacity: 0.65;
      }
    }
  `;
}
const se = [...W([z, F, K, G]), {
  method: H,
  execute: (e, t) => {
    var a, n;
    return (n = (a = e.children.viewRef.viewRef) == null ? void 0 : a.input) == null ? void 0 : n.click();
  }
}, {
  method: X,
  execute: (e, t) => {
    var a, n, o;
    return (o = (n = (a = e.children.viewRef.viewRef) == null ? void 0 : a.input) == null ? void 0 : n.setRangeText) == null ? void 0 : o.call(n, ...t);
  }
}];
function de(e) {
  if (e === "")
    return {};
  for (const t in e)
    g(e[t], ["array"], t, (a) => (g(a, ["string"]), a));
  return e;
}
function fe(e) {
  if (!e)
    return e;
  if (e.value && !e.defaultValue) {
    const t = e.value;
    return {
      ...e,
      defaultValue: t,
      value: ""
    };
  }
  return e;
}
export {
  ie as TextInputBasicSection,
  ne as TextInputConfigs,
  le as TextInputInteractionSection,
  p as TextInputValidationOptions,
  ue as TextInputValidationSection,
  de as checkMentionListData,
  fe as fixOldInputCompData,
  ce as getStyle,
  se as inputRefMethods,
  oe as textInputChildren,
  Q as textInputProps,
  b as textInputValidate,
  re as useTextInputProps
};
