import { defineComponent as S, useSlots as P, computed as d, createVNode as V, shallowRef as k, openBlock as i, createBlock as c, unref as u, mergeProps as M, createSlots as T, renderList as _, withCtx as z, renderSlot as U, normalizeProps as F, guardReactiveProps as N } from "vue";
import { Input as $ } from "@aplus-frontend/antdv";
import { omit as A } from "lodash-unified";
import "../../render/index.mjs";
import "../../hooks/index.mjs";
import { useDefaultPlaceholder as E } from "../hooks/use-default-placeholder.mjs";
import { useControllableValue as K } from "../../hooks/useControllableValue.mjs";
import j from "../../render/render.mjs";
const W = /* @__PURE__ */ S({
  name: "ApFieldText",
  __name: "index",
  props: {
    mode: {
      default: "edit"
    },
    class: {},
    style: {},
    emptyText: {
      default: "--"
    },
    customReadMode: {},
    variant: {},
    size: {},
    value: {},
    name: {},
    type: {
      default: "text"
    },
    onCompositionend: {},
    onCompositionstart: {},
    onFocus: {},
    onBlur: {},
    onChange: {},
    onInput: {},
    onKeydown: {},
    onKeyup: {},
    onMousedown: {},
    focused: {
      type: Boolean
    },
    hidden: {
      type: Boolean
    },
    disabled: {
      type: Boolean,
      default: void 0
    },
    prefixCls: {},
    id: {},
    readonly: {
      type: Boolean
    },
    autofocus: {
      type: Boolean
    },
    autocomplete: {},
    placeholder: {},
    lazy: {
      type: Boolean,
      default: !0
    },
    maxlength: {},
    loading: {
      type: Boolean
    },
    bordered: {
      type: Boolean,
      default: !0
    },
    showCount: {
      type: [Boolean, Object]
    },
    htmlSize: {},
    onPressEnter: {},
    onMouseUp: {},
    onRawInput: {},
    "onUpdate:value": {},
    valueModifiers: {},
    status: {},
    defaultValue: {},
    inputElement: {},
    triggerFocus: {},
    handleReset: {},
    addonBefore: {},
    addonAfter: {},
    prefix: {},
    suffix: {},
    clearIcon: {},
    allowClear: {
      type: Boolean,
      default: !0
    },
    beforeInput: {}
  },
  emits: ["update:value"],
  setup(r, {
    expose: f,
    emit: m
  }) {
    const s = P(), o = r, y = m, {
      value: p,
      updateValue: v
    } = K(o, y), x = E("Text", o), h = d(() => A(o, ["mode", "emptyText", "value", "onUpdate:value", "beforeInput"])), B = () => {
      const e = p.value || o.emptyText, t = V("span", null, [o.prefix || s.prefix?.(), e, o.suffix || s.suffix?.()]);
      return o.customReadMode?.(e, t) ?? t;
    }, n = k(), g = (e) => {
      n.value?.focus(e);
    }, I = () => {
      n.value?.blur();
    }, R = (e, t, l) => {
      n.value?.setSelectionRange(e, t, l);
    }, b = () => {
      n.value?.select();
    };
    function C(e) {
      const t = e.target.value || "", l = o.beforeInput ? o.beforeInput?.(t) : t, a = n.value?.$el?.querySelector("input");
      a && (a.value = l), v(l);
    }
    return f({
      focus: g,
      blur: I,
      setSelectionRange: R,
      select: b,
      input: d(() => n.value?.input)
    }), (e, t) => r.mode === "edit" ? (i(), c(u($), M({
      key: 0
    }, h.value, {
      ref_key: "inputRef",
      ref: n,
      placeholder: u(x),
      value: u(p),
      onInput: C
    }), T({
      _: 2
    }, [_(e.$slots, (l, a) => ({
      name: a,
      fn: z((w) => [U(e.$slots, a, F(N(w || {})))])
    }))]), 1040, ["placeholder", "value"])) : (i(), c(u(j), {
      key: 1,
      node: B()
    }, null, 8, ["node"]));
  }
});
export {
  W as default
};
