import { f8 as R, Y as o, f9 as C, _ as L, cc as T, bL as S, a4 as h, bI as y, P as E, S as I, fa as $, O as r, ad as v, a3 as P, fb as M, ce as k, a6 as u, a7 as c, a8 as s, el as O, bJ as B, ca as q, dG as N, dH as W, dI as D, av as A, cP as H, d8 as U, cR as _, fc as z, fd as F, d9 as j, fe as G, ff as g } from "./603b75d9.js";
import { useState as J, useRef as x, useEffect as m } from "react";
import { formDataChildren as K } from "./f9847c56.js";
import "react-dom";
const p = [{
  label: "Text",
  value: "Text",
  extra: /.*/,
  help: ""
}, {
  label: "Email",
  value: "Email",
  extra: R,
  help: o("validationDesc.email")
}, {
  label: "URL",
  value: "URL",
  extra: C,
  help: o("validationDesc.url")
}, {
  label: "Regex",
  value: "Regex",
  extra: void 0,
  help: o("validationDesc.regex")
}], l = L.fromPairs(p.map((e) => [e.value, e])), b = (e) => {
  var i;
  if (e.customRule)
    return {
      validateStatus: "error",
      help: e.customRule
    };
  const t = e.value.value;
  if (e.required && t.length === 0)
    return {
      validateStatus: "error",
      help: o("prop.required")
    };
  if (e.maxLength > 0 && t.length > e.maxLength)
    return {
      validateStatus: "error",
      help: o("validationDesc.maxLength", {
        length: t.length,
        maxLength: e.maxLength
      })
    };
  if (e.minLength > 0 && t.length < e.minLength)
    return {
      validateStatus: "error",
      help: o("validationDesc.minLength", {
        length: t.length,
        minLength: e.minLength
      })
    };
  const a = e.validationType, n = ((i = l[a]) == null ? void 0 : i.extra) ?? e.regex;
  return t && !n.test(t) ? {
    validateStatus: "error",
    help: l[a].help
  } : {
    validateStatus: ""
  };
}, Y = T({
  name: "invalid",
  desc: o("export.invalidDesc"),
  depKeys: ["value", "required", "minLength", "maxLength", "validationType", "regex", "customRule"],
  func: (e) => b({
    ...e,
    value: {
      value: e.value
    }
  }).validateStatus !== ""
}), ae = [Y, ...S], ne = {
  defaultValue: h("defaultValue"),
  value: h("value"),
  disabled: y,
  label: E,
  placeholder: I,
  onEvent: $,
  readOnly: r,
  // validation
  required: r,
  showValidationWhenEmpty: r,
  minLength: v,
  maxLength: v,
  validationType: P(p, "Text"),
  regex: M,
  customRule: k,
  ...K
}, 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")
}), oe = (e) => {
  const [t, a] = J({}), n = x(!1), i = x(e);
  i.current = e;
  const d = {
    ...e.defaultValue
  }.value, f = {
    ...e.value
  }.value;
  m(() => {
    e.value.onChange(d);
  }, [d]), m(() => {
    n.current && (a(b({
      ...i.current,
      value: {
        value: f
      }
    })), i.current.onEvent("change"), n.current = !1);
  }, [f]);
  const V = (w) => {
    e.value.onChange(w.target.value), n.current = !0;
  };
  return [{
    ...Q(e),
    onChange: V
  }, t];
}, ie = (e) => /* @__PURE__ */ u(c, {
  name: s.basic,
  children: [e.defaultValue.propertyView({
    label: o("prop.defaultValue")
  }), O(e)]
}), re = (e) => /* @__PURE__ */ u(c, {
  name: s.interaction,
  children: [e.onEvent.getPropertyView(), B(e)]
}), le = (e) => {
  var t;
  return /* @__PURE__ */ u(c, {
    name: s.validation,
    children: [q(e), e.showValidationWhenEmpty.propertyView({
      label: o("prop.showEmptyValidation")
    }), e.validationType.propertyView({
      label: o("prop.textType")
    }), ((t = l[e.validationType.getView()]) == null ? void 0 : t.extra) === void 0 && N(e), W(e), D(e), e.customRule.propertyView({})]
  });
};
function ue(e, t) {
  return A`
    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};
      // line-height: ${e.lineHeight};

      &: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 ce = [...H([U, _, z, F]), {
  method: j,
  execute: (e, t) => {
    var a, n;
    return (n = (a = e.children.viewRef.viewRef) == null ? void 0 : a.input) == null ? void 0 : n.click();
  }
}, {
  method: G,
  execute: (e, t) => {
    var a, n, i;
    return (i = (n = (a = e.children.viewRef.viewRef) == null ? void 0 : a.input) == null ? void 0 : n.setRangeText) == null ? void 0 : i.call(n, ...t);
  }
}];
function se(e) {
  if (e === "")
    return {};
  for (const t in e)
    g(e[t], ["array"], t, (a) => (g(a, ["string"]), a));
  return e;
}
function de(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,
  ae as TextInputConfigs,
  re as TextInputInteractionSection,
  p as TextInputValidationOptions,
  le as TextInputValidationSection,
  se as checkMentionListData,
  de as fixOldInputCompData,
  ue as getStyle,
  ce as inputRefMethods,
  ne as textInputChildren,
  Q as textInputProps,
  b as textInputValidate,
  oe as useTextInputProps
};
