import { defineComponent as S, computed as f, ref as h, useSlots as U, onMounted as V, unref as o, createVNode as s, Fragment as a, openBlock as u, createBlock as i, createElementBlock as N, resolveDynamicComponent as P, mergeProps as _, withCtx as q, renderSlot as z, normalizeProps as F, guardReactiveProps as R } from "vue";
import { Spin as T, Segmented as M } from "@aplus-frontend/antdv";
import { omit as O, isFunction as v, isUndefined as w, isString as A, isNumber as D } from "lodash-unified";
import "../../hooks/index.mjs";
import E from "../hooks/use-options.mjs";
import { useControllableValue as $ } from "../../hooks/useControllableValue.mjs";
const L = /* @__PURE__ */ S({
  name: "ApFieldSegmented",
  __name: "index",
  props: {
    mode: {
      default: "edit"
    },
    class: {},
    style: {},
    emptyText: {
      default: "--"
    },
    customReadMode: {},
    prefixCls: {},
    options: {},
    block: {
      type: Boolean,
      default: void 0
    },
    disabled: {
      type: Boolean,
      default: void 0
    },
    size: {},
    value: {},
    motionName: {},
    onChange: {},
    "onUpdate:value": {},
    vertical: {
      type: Boolean
    },
    shape: {},
    name: {},
    defaultValue: {},
    request: {}
  },
  emits: ["update:value"],
  setup(d, {
    emit: y
  }) {
    const e = d, g = f(() => O(e, ["onUpdate:value", "value", "defaultValue", "options"])), {
      options: p,
      updateOptions: b
    } = E(e), k = y, {
      value: m,
      updateValue: x
    } = $(e, k), r = h(!1), B = U();
    V(() => {
      v(e.request) && (r.value = !0, e.request().then((t) => b(t)).finally(() => {
        r.value = !1;
      }));
    });
    const C = f(() => {
      const t = o(m);
      if (w(t))
        return s(a, null, [e.emptyText]);
      const l = o(p)?.find((c) => c === t || c?.value === t);
      if (A(l) || D(l))
        return s(a, null, [l]);
      const n = l?.label || B.label;
      return v(n) ? s(a, null, [n?.({
        ...l
      })]) : s(a, null, [n || e.emptyText]);
    });
    return (t, l) => r.value ? (u(), i(o(T), {
      key: 0,
      size: "small"
    })) : (u(), N(a, {
      key: 1
    }, [d.mode === "read" ? (u(), i(P(C.value), {
      key: 0
    })) : (u(), i(o(M), _({
      key: 1
    }, g.value, {
      value: o(m),
      options: o(p),
      "onUpdate:value": o(x)
    }), {
      label: q((n) => [z(t.$slots, "label", F(R(n)))]),
      _: 3
    }, 16, ["value", "options", "onUpdate:value"]))], 64));
  }
});
export {
  L as default
};
