import { isVNode as T, createVNode as s, mergeProps as a, cloneVNode as h, createTextVNode as C } from "vue";
import { QuestionCircleOutlined as x } from "@ant-design/icons-vue";
import { Tooltip as E } from "@aplus-frontend/antdv";
import { isObject as f, isArray as u, isUndefined as j, isFunction as g, omit as v, isBoolean as O, isString as F, isEqual as N, sortBy as m, isPlainObject as y, every as R, isEmpty as P } from "lodash-unified";
import "../ap-form/index.mjs";
import { apTableRenderItemMap as S, apTableFormItemMap as I } from "./constants.mjs";
import A from "../ap-form/item/index.vue.mjs";
function V(e) {
  return typeof e == "function" || Object.prototype.toString.call(e) === "[object Object]" && !T(e);
}
const w = (e, t, n) => {
  let o = {};
  return f(e) ? Object.keys(e).forEach((r) => {
    f(e[r]) ? o[r] = w(e[r], t[r], n) : o[r] = n(e[r], t);
  }) : o = n(e, t), o;
}, K = (e, t) => {
  switch (e) {
    case "dayjs":
      return t.valueOf();
    case "dayjsRange":
      return t.map((n) => n.valueOf());
    case "dayjsDayRange": {
      const [n, o] = t;
      return [n.startOf("day").valueOf(), o.endOf("day").valueOf()];
    }
    case "multiple":
    case "multipleNumber":
      return u(t) ? t : [t];
    case "boolean":
      return t;
    case "object":
      return t;
    default:
      return t;
  }
};
function L(e) {
  return u(e) ? e.join(".") : e;
}
function M(e) {
  const t = Object.prototype.toString.call(e).match(/^\[object (.*)\]$/)[1].toLowerCase();
  return t === "string" && typeof e == "object" ? "object" : e === null ? "null" : e === void 0 ? "undefined" : t;
}
const _ = (e) => {
  if (M(e) === "map")
    return e;
  const t = /* @__PURE__ */ new Map();
  for (const [n, o] of Object.entries(e || {})) {
    let r = n;
    n === "true" ? r = !0 : n === "false" && (r = !1), t.set(r, o);
  }
  return t;
}, b = (e) => {
  const t = [], n = _(e);
  return n.forEach((o, r) => {
    const i = n.get(r) || n.get(`${r}`);
    if (i) {
      if (typeof i == "object" && i?.text) {
        t.push({
          text: i?.text,
          value: r,
          label: i?.text,
          disabled: i.disabled
        });
        return;
      }
      t.push({
        text: i,
        label: i,
        value: r
      });
    }
  }), t;
}, Q = (e) => j(e) || e < 0 ? 0 : e;
function q(e, t) {
  return !e || !g(e) ? e : e(t);
}
function z(e) {
  let t = e.valueType || "text";
  return e.valueEnum && (t = "status"), t;
}
function G(e, t, n, o) {
  const r = S[e];
  return r ? s(r, a(t, {
    mode: "read"
  }), null) : o?.[e]?.render?.(t.value, n, t) || t.value;
}
function X(e, t) {
  if (e.customRenderFormItem)
    return () => {
      const r = e.customRenderFormItem(e);
      return h(r, {
        ...e.fieldProps,
        span: e.span,
        ...r.props || {}
      });
    };
  const n = I[e.valueType];
  if (n)
    return () => s(n, a(e.fieldProps, {
      span: e.span
    }), null);
  const o = t?.[e.valueType];
  return () => {
    const r = o?.renderFormItem?.(e.fieldProps.field);
    return r ? s(A, a(e.fieldProps, {
      span: e.span
    }), V(r) ? r : {
      default: () => [r]
    }) : null;
  };
}
function Y(e, t) {
  const n = q(e.fieldProps, t), o = n?.field || n || {}, r = e.valueType === "switch", i = e.valueType === "index", c = r ? {
    checked: t.value
  } : {
    value: i ? t.index + 1 : t.value
  };
  return e.valueEnum && (o.valueEnum = e.valueEnum), {
    ...v(o, ["request"]),
    ...c
  };
}
function Z(e) {
  const t = {
    ...e
  };
  return O(e.filters) && e.filters && e.valueEnum && (t.filters = b(e.valueEnum)), t;
}
function ee(e, t) {
  const n = t || {};
  return e.valueEnum && !n.field?.options && (n.field = {
    ...n.field,
    options: b(e.valueEnum)
  }), n;
}
function te(e) {
  if (!f(e))
    return e;
  try {
    return JSON.stringify(e);
  } catch {
    return e;
  }
}
function ne(e, t, n, o) {
  const r = n?.({
    title: e.title,
    column: e
  }), i = r?.filter((l) => l.type !== /* @__PURE__ */ Symbol.for("v-cmt")) || [];
  if (r && i.length > 0)
    return r;
  const p = F(e.title) ? s("span", {
    class: t,
    style: {
      textAlign: e.align || "left"
    },
    title: e.title
  }, [e._requireMark ? s("span", {
    style: {
      color: "#FF4D4F",
      paddingRight: "2px"
    }
  }, [C("*")]) : null, e.title]) : e.title, d = e.tooltip ? g(e.tooltip) ? e.tooltip(e) : e.tooltip : null;
  return d ? s("span", {
    style: {
      display: "inline-flex",
      alignItems: "center",
      maxWidth: "100%"
    }
  }, [p, s(E, {
    title: d,
    placement: "bottom",
    getPopupContainer: (l) => l.closest(".ant-table") || l.closest(".ant-modal") || l.closest(".vxe-table") || document.body
  }, {
    default: () => [s(x, {
      style: {
        paddingInline: "4px",
        color: o,
        verticalAlign: "middle"
      }
    }, null)]
  })]) : p;
}
function re(e, t) {
  const n = [];
  function o(r) {
    for (const i of r)
      i.children?.length ? o(i.children) : n.push(t(i));
  }
  return o(e), n;
}
function oe(e, t) {
  if (u(e) && u(t))
    return N(m(e), m(t));
  if (y(e) && y(t)) {
    const n = (o) => R(o, (r) => r == null) || P(o);
    if (n(e) && n(t))
      return !0;
  }
}
function ie(e) {
  if (e !== !1)
    return e;
}
export {
  Z as apColumnToColumn,
  L as dataIndexToStr,
  ie as falseToUndefined,
  w as formatParamsValueType,
  Q as getColumnOrder,
  q as getFieldProps,
  X as getSearchFormItemRenderNode,
  G as getTableCellRenderNode,
  Y as getTableRenderProps,
  z as getTableRenderType,
  ne as getTableTitle,
  oe as isEqualCustom,
  _ as objectToMap,
  te as objectToString,
  K as parseFieldValue,
  re as recursionApColumns,
  ee as updateFormProps,
  b as valueEnumToArray
};
