import { defineComponent as S, computed as p, ref as T, watch as V, shallowRef as F, useSlots as B, openBlock as l, createElementBlock as f, normalizeClass as k, unref as a, createBlock as n, mergeProps as r, withCtx as s, createElementVNode as E, createVNode as P, createTextVNode as N, toDisplayString as h, resolveDynamicComponent as $, Fragment as g, renderList as A, normalizeProps as q, createCommentVNode as D, renderSlot as O } from "vue";
import { useNamespace as j, ElFormItem as z, ElTooltip as R, ElText as L, ElAutocomplete as G, ElCascader as H, ElColorPicker as J, ElSelect as K, ElOption as M, ElTimeSelect as Q, ElRate as W, ElInputNumber as X, ElTreeSelect as Y, ElDatePicker as Z, ElTimePicker as ee, ElSwitch as le, ElInput as oe } from "element-plus";
import ae from "../../../pro-table/src/components/enum.vue.mjs";
import te from "../../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/get.mjs";
import ne from "../../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/isPlainObject.mjs";
import C from "../../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/set.mjs";
import ue from "../../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/cloneDeep.mjs";
const re = /* @__PURE__ */ E("div", { style: { height: "100%", width: "100%" } }, null, -1), ie = { key: 1 }, ge = /* @__PURE__ */ S({
  __name: "columns-item",
  props: {
    row: {
      type: Object,
      required: !0
    },
    prop: {
      type: [String, Array]
    },
    index: Number,
    itemConfig: {
      type: Object,
      default() {
        return { dataIndex: "" };
      }
    },
    changeValue: {
      type: Function
    },
    emitControlChangeValue: {
      type: Function
    },
    readonly: Boolean,
    check: Boolean,
    controlled: Boolean,
    saveTag: Boolean
  },
  setup(x) {
    const y = j("editable-table-column"), e = x, m = p(() => e.itemConfig.valueType || ""), t = T(), v = p(() => te(e.row, e.itemConfig.dataIndex, void 0)), b = p(() => {
      const o = Array.isArray(e.prop) ? e.prop : e.prop ? [e.prop] : [], u = Array.isArray(e.itemConfig.dataIndex) ? e.itemConfig.dataIndex : e.itemConfig.dataIndex ? [e.itemConfig.dataIndex] : [];
      return [...o, `${e.index}`, ...u];
    }), _ = p(() => {
      var o;
      return (o = e.itemConfig) != null && o.valueEnum ? e.itemConfig.valueEnum.map((u) => ne(u) ? u : {
        label: u,
        value: u,
        disabled: !1
      }) : [];
    });
    V(v, (o) => {
      t.value = o;
    }, {
      immediate: !0,
      deep: !0
    });
    const c = F(!1), I = p(() => {
      var u, d;
      if (e.readonly || e.index === -1)
        return [];
      const o = [...((u = e.itemConfig.formItemProps) == null ? void 0 : u.rules) || []];
      return (e.itemConfig.required || (d = e.itemConfig.formItemProps) != null && d.required) && o.unshift({
        required: !0,
        message: `${e.itemConfig.label || e.itemConfig.title || "该字段"}是必填项`
      }), o;
    });
    V([() => e.readonly, () => e.saveTag], ([o, u]) => {
      o && u ? w() : o && (t.value = v.value);
    }, {
      immediate: !0
    });
    const i = (o) => {
      if (t.value = o, !e.controlled)
        C(e.row, e.itemConfig.dataIndex, o), e.changeValue && e.changeValue(o, e.index);
      else {
        c.value = !0;
        const u = ue(e.row);
        C(u, e.itemConfig.dataIndex, o), e.emitControlChangeValue && e.emitControlChangeValue(u, e.index);
      }
    }, w = () => {
      c.value && (C(e.row, e.itemConfig.dataIndex, t.value), e.changeValue && e.changeValue(e.row, e.index), c.value = !1);
    }, U = B();
    return (o, u) => (l(), f("div", {
      class: k(a(y).b())
    }, [
      e.readonly ? (l(), f(g, { key: 1 }, [
        a(U).default ? D("", !0) : (l(), f(g, { key: 0 }, [
          e.itemConfig.valueEnum ? (l(), n(ae, {
            key: 0,
            "value-enum": e.itemConfig.valueEnum,
            value: v.value
          }, null, 8, ["value-enum", "value"])) : (l(), f("span", ie, h(v.value), 1))
        ], 64)),
        O(o.$slots, "default")
      ], 64)) : (l(), n(a(z), r({ key: 0 }, e.itemConfig.formItemProps, {
        label: "",
        style: { position: "relative" },
        rules: I.value,
        prop: b.value
      }), {
        error: s(({ error: d }) => [
          E("div", {
            class: k(a(y).e("error"))
          }, [
            P(a(R), {
              visible: !!d,
              effect: "light",
              placement: "top-start"
            }, {
              content: s(() => [
                P(a(L), {
                  type: "danger",
                  size: "small"
                }, {
                  default: s(() => [
                    N(h(d), 1)
                  ]),
                  _: 2
                }, 1024)
              ]),
              default: s(() => [
                re
              ]),
              _: 2
            }, 1032, ["visible"])
          ], 2)
        ]),
        default: s(() => [
          e.itemConfig.renderFormField ? (l(), n($(e.itemConfig.renderFormField), r({ key: 0 }, e.itemConfig.fieldProps, {
            "model-value": t.value,
            "onUpdate:modelValue": i
          }), null, 16, ["model-value"])) : m.value === "autocomplete" ? (l(), n(a(G), r({ key: 1 }, e.itemConfig.fieldProps, {
            "model-value": t.value,
            "onUpdate:modelValue": i
          }), null, 16, ["model-value"])) : m.value === "cascader" ? (l(), n(a(H), r({ key: 2 }, e.itemConfig.fieldProps, {
            "model-value": t.value,
            "onUpdate:modelValue": i
          }), null, 16, ["model-value"])) : m.value === "color" ? (l(), n(a(J), r({ key: 3 }, e.itemConfig.fieldProps, {
            "model-value": t.value,
            "onUpdate:modelValue": i
          }), null, 16, ["model-value"])) : m.value === "select" ? (l(), n(a(K), r({ key: 4 }, e.itemConfig.fieldProps, {
            "model-value": t.value,
            "onUpdate:modelValue": i
          }), {
            default: s(() => [
              (l(!0), f(g, null, A(_.value, (d) => (l(), n(a(M), {
                label: d.label.toString(),
                value: d.value,
                key: d.value.toString()
              }, null, 8, ["label", "value"]))), 128))
            ]),
            _: 1
          }, 16, ["model-value"])) : m.value === "time-select" ? (l(), n(a(Q), r({ key: 5 }, e.itemConfig.fieldProps, {
            "model-value": t.value,
            "onUpdate:modelValue": i
          }), null, 16, ["model-value"])) : m.value === "rate" ? (l(), n(a(W), r({ key: 6 }, e.itemConfig.fieldProps, {
            "model-value": t.value,
            "onUpdate:modelValue": i
          }), null, 16, ["model-value"])) : m.value === "number" ? (l(), n(a(X), r({ key: 7 }, e.itemConfig.fieldProps, {
            "model-value": t.value,
            "onUpdate:modelValue": i
          }), null, 16, ["model-value"])) : m.value === "tree-select" ? (l(), n(a(Y), r({ key: 8 }, e.itemConfig.fieldProps, {
            "model-value": t.value,
            "onUpdate:modelValue": i
          }), null, 16, ["model-value"])) : m.value === "date" ? (l(), n(a(Z), r({ key: 9 }, e.itemConfig.fieldProps, {
            "model-value": t.value,
            "onUpdate:modelValue": i
          }), null, 16, ["model-value"])) : m.value === "time-picker" ? (l(), n(a(ee), q(r({ key: 10 }, e.itemConfig.fieldProps)), null, 16)) : m.value === "switch" ? (l(), n(a(le), r({ key: 11 }, e.itemConfig.fieldProps, {
            "model-value": t.value,
            "onUpdate:modelValue": i
          }), null, 16, ["model-value"])) : (l(), n(a(oe), r({ key: 12 }, e.itemConfig.fieldProps, {
            "model-value": t.value,
            "onUpdate:modelValue": i
          }), null, 16, ["model-value"]))
        ]),
        _: 1
      }, 16, ["rules", "prop"]))
    ], 2));
  }
});
export {
  ge as default
};
