import { isVNode as b, createVNode as o, mergeProps as C, createTextVNode as R, Fragment as I } from "vue";
import { QuestionCircleOutlined as h } from "@ant-design/icons-vue";
import { Typography as S, Tooltip as F } from "@aplus-frontend/antdv";
import { isFunction as c, isArray as N, isBoolean as x, omit as q, isString as w } from "lodash-unified";
import P from "scroll-into-view-if-needed";
import { getValueStr as V } from "../ap-field/number/helper.mjs";
import "../ap-form/index.mjs";
import { apTableFormItemMap as v, noRenderAsFormItemValueList as A, apTableRenderItemMap as j } from "../ap-table/constants.mjs";
import { objectToString as M, getTableRenderType as O } from "../ap-table/utils.mjs";
import "../utils/index.mjs";
import { isDef as W } from "../utils/is.mjs";
import g from "../ap-form/item/index.vue.mjs";
function y(e) {
  return typeof e == "function" || Object.prototype.toString.call(e) === "[object Object]" && !b(e);
}
function _(e) {
  return v[e];
}
function k(e) {
  if (e.markRequired)
    return !0;
  if (!e.fieldProps)
    return !1;
  const t = c(e.fieldProps) ? e.fieldProps({}) : e.fieldProps;
  return W(t.required) ? t.required : (N(t.rules) ? t.rules : t.rules ? [t.rules] : []).some((i) => i.required);
}
function D(e, t) {
  if (e.valueType === "text" || e.valueType === "textArea")
    return t || "--";
  if (e.valueType === "number") {
    const r = e.fieldProps ? c(e.fieldProps) ? e.fieldProps({}) : e.fieldProps : {};
    return V(t, r) || "--";
  }
  return M(t);
}
function ee(e, t = document.body, r = {}) {
  const i = t.querySelectorAll("tr.ant-table-row")[e];
  i && P(i, {
    scrollMode: "if-needed",
    block: "nearest",
    behavior: "smooth",
    ...r
  });
}
function E(e, t, r) {
  return A.includes(e.valueType) ? r : e.copyable || e.ellipsis ? o(S.Paragraph, {
    copyable: e.copyable ? {
      text: t,
      tooltip: !1
    } : !1,
    ellipsis: e.ellipsis ? x(e.ellipsis) ? {
      tooltip: t
    } : {
      ...e.ellipsis,
      tooltip: t
    } : !1,
    content: e.ellipsis ? D(e, t) : r
  }, null) : r;
}
function te(e, t, r, i, f, n) {
  if (t) {
    if (e.customRenderFormItem) {
      const p = e.customRenderFormItem(e, r.field, t, f);
      return o(g, q(r, ["field"]), y(p) ? p : {
        default: () => [p]
      });
    }
    const a = _(e.valueType);
    if (a)
      return o(a, r, null);
    const l = n?.[e.valueType]?.renderFormItem?.(r.field);
    return l ? o(g, r, y(l) ? l : {
      default: () => [l]
    }) : null;
  }
  let s;
  const u = O(e), d = j[u];
  return d ? s = o(d, C(r.field, {
    mode: "read"
  }), null) : s = n?.[u]?.render?.(i, f, r.field), s ? E(e, i, s) : null;
}
function re(e, t, r, i, f) {
  const n = i?.({
    title: e.title,
    column: e
  }), s = n?.filter((T) => T.type !== /* @__PURE__ */ Symbol.for("v-cmt")) || [];
  if (n && s.length > 0)
    return n;
  const d = k(e), m = w(e.title) ? {
    class: t,
    title: e.title
  } : {}, l = o("div", m, [d ? o("span", {
    class: r
  }, [R("*")]) : null, e.title]), p = e.tooltip ? c(e.tooltip) ? e.tooltip(e) : o(I, null, [e.tooltip]) : null;
  return p ? o("span", {
    style: {
      display: "inline-flex",
      alignItems: "center",
      maxWidth: "100%"
    }
  }, [l, o(F, {
    title: p,
    placement: "bottom"
  }, {
    default: () => [o(h, {
      style: {
        padding: "4px",
        color: f,
        verticalAlign: "middle"
      }
    }, null)]
  })]) : l;
}
export {
  k as getColumnIsRequired,
  _ as getEditableComponent,
  re as getEditableTableTitle,
  te as getFinalNode,
  D as getRawDisplayValue,
  ee as scrollToRowIndex
};
