import { defineComponent as L, computed as b, useSlots as $, ref as j, shallowRef as E, unref as t, cloneVNode as O, openBlock as q, createBlock as D, mergeProps as K, createSlots as M, withCtx as s, createVNode as d, renderSlot as y, createElementVNode as Q, normalizeClass as U, normalizeStyle as Y, renderList as G, normalizeProps as H, guardReactiveProps as J } from "vue";
import { QuestionCircleOutlined as W } from "@ant-design/icons-vue";
import { Form as X, Tooltip as Z, TypographyText as _ } from "@aplus-frontend/antdv";
import { useToken as ee } from "@aplus-frontend/antdv/es/theme/internal";
import { omit as v, isArray as oe, isFunction as te } from "lodash-unified";
import "../../render/index.mjs";
import "../../config-provider/index.mjs";
import { getValidVNodeList as re } from "../../utils/slot.mjs";
import { apFormItemColPropKeys as le } from "../constant.mjs";
import { useInjectForm as ae } from "../context.mjs";
import ne from "../hooks/use-regist-form.mjs";
import se from "../style/item.mjs";
import { useNamespace as ie } from "../../config-provider/hooks/use-namespace.mjs";
import ue from "../../render/render.mjs";
const ke = /* @__PURE__ */ L({
  name: "ApFormItem",
  __name: "index",
  props: {
    htmlFor: {},
    prefixCls: {},
    label: {},
    help: {},
    extra: {},
    labelCol: {},
    wrapperCol: {},
    hasFeedback: { type: Boolean, default: !1 },
    colon: { type: Boolean, default: void 0 },
    labelAlign: {},
    prop: {},
    name: {},
    rules: {},
    autoLink: { type: Boolean, default: !0 },
    required: { type: Boolean, default: void 0 },
    validateFirst: { type: Boolean, default: void 0 },
    validateStatus: {},
    validateTrigger: {},
    messageVariables: {},
    hidden: { type: Boolean },
    noStyle: { type: Boolean },
    tooltip: {},
    span: {},
    order: {},
    offset: {},
    push: {},
    pull: {},
    xs: {},
    sm: {},
    md: {},
    lg: {},
    xl: {},
    xxl: {},
    flex: {},
    bordered: { type: Boolean, default: !1 },
    valuePropName: { default: "value" },
    initialValue: {},
    _signal: {},
    transform: {},
    description: {},
    customFilled: {},
    disabled: { type: Boolean },
    autoFocus: { type: Boolean, default: void 0 }
  },
  setup(l, { expose: F }) {
    const e = l, h = b(
      () => v(e, [
        ...le,
        "tooltip",
        "label",
        "description",
        "autoFocus"
      ])
    ), g = $(), { model: c, updateModel: x } = ae(), { m: f, b: B } = ie("ap-form-item"), V = se("ap-form-item"), m = j(!1), i = E(), [, k] = ee();
    ne(e);
    const p = b(() => e.name ? oe(e.name) ? e.name.reduce((r, o) => r?.[o], t(c)) : c?.value[e.name] : null);
    function C(r, o) {
      const a = Object.keys(o), n = { ...o };
      return a.forEach((u) => {
        u in r || delete n[u];
      }), n;
    }
    function P(r) {
      if (!e.name)
        return r[0];
      const o = re(r)[0];
      if (!o)
        return null;
      const a = o?.type?.props ?? {}, n = {
        autofocus: e.autoFocus ?? o?.props?.autofocus,
        variant: e.bordered ? "borderless" : o?.props?.variant,
        bordered: e.bordered ? !1 : o?.props?.bordered,
        onFocus: S,
        onBlur: I
      };
      return O(o, {
        ...C(a, n),
        [e.valuePropName]: t(p),
        [`onUpdate:${e.valuePropName}`]: N
      });
    }
    function N(r) {
      x?.(e.name, r);
    }
    function S() {
      m.value = !0;
    }
    function I() {
      m.value = !1;
    }
    function R() {
      i.value?.onFieldBlur();
    }
    function T() {
      i.value?.onFieldChange();
    }
    function w() {
      i.value?.clearValidate();
    }
    function z() {
      i.value?.resetField();
    }
    function A(r = !1) {
      const o = t(p);
      if (!r || !e.transform)
        return o;
      const a = te(e.transform) ? e.transform : e.transform.transformer;
      return e.transform ? a(o) : o;
    }
    return F({
      onFieldBlur: R,
      onFieldChange: T,
      clearValidate: w,
      resetField: z,
      getFieldValue: A
    }), (r, o) => (q(), D(t(X).Item, K({
      ref_key: "formItemRef",
      ref: i
    }, h.value, {
      class: {
        [t(f)("bordered")]: l.bordered,
        [t(f)("focused")]: l.bordered && m.value,
        [t(f)("disabled")]: l.bordered && l.disabled,
        [t(B)()]: !0,
        [t(V)]: !0
      },
      colon: l.bordered ? !1 : e.colon
    }), M({
      default: s(() => [
        d(t(ue), { renderer: P }, {
          default: s(() => [
            y(r.$slots, "default")
          ]),
          _: 3
        })
      ]),
      _: 2
    }, [
      e.tooltip ? {
        name: "tooltip",
        fn: s(({ class: a }) => [
          Q("span", {
            class: U(a)
          }, [
            d(t(Z), {
              title: e.tooltip
            }, {
              default: s(() => [
                d(t(W), {
                  style: Y({
                    color: t(k).colorTextTertiary,
                    fontSize: "14px",
                    transform: "translateY(1px)"
                  })
                }, null, 8, ["style"])
              ]),
              _: 1
            }, 8, ["title"])
          ], 2)
        ]),
        key: "0"
      } : void 0,
      l.label ? {
        name: "label",
        fn: s(() => [
          d(t(_), {
            content: l.label,
            ellipsis: { tooltip: l.label },
            style: { "min-width": "0px", flex: "1" }
          }, null, 8, ["content", "ellipsis"])
        ]),
        key: "1"
      } : void 0,
      G(t(v)(g, "default"), (a, n) => ({
        name: n,
        fn: s((u) => [
          y(r.$slots, n, H(J(u || {})))
        ])
      }))
    ]), 1040, ["class", "colon"]));
  }
});
export {
  ke as default
};
