'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var vue = require('vue');

var TableColumnVNodeRenderer = /* @__PURE__ */ vue.defineComponent({
  functional: true,
  props: {
    // 当前原始vnode vue模板中的attribute
    vnode: {
      type: [Object, Array],
      required: true
    },
    // 真实渲染的propsList
    propsList: {
      type: Array,
      default: () => []
    },
    defaultPropsList: {
      type: Array,
      default: () => []
    }
  },
  setup(props) {
    const mergePropsList = vue.computed(() => {
      return props.defaultPropsList.map((it) => {
        const findProp = props.propsList.find((item) => item.prop === it.prop);
        if (findProp) {
          return findProp;
        }
        return it;
      });
    });
    const processVNode = (vnode) => {
      if (!vnode) return null;
      if (vnode.type?.name === "GmTableColumnPro") {
        if (vnode.props?.type === "edit") {
          return null;
        }
        const propsConfig = mergePropsList.value.find((it) => it.prop === vnode.props?.prop);
        if (propsConfig && !propsConfig.isShow) {
          return null;
        }
        if (propsConfig) {
          const newProps = {
            ...vnode.props,
            width: propsConfig.width,
            label: propsConfig.label,
            fixed: propsConfig.fixed
          };
          return vue.cloneVNode(vnode, newProps);
        }
        return vnode;
      }
      if (vnode.children) {
        let newChildren = vnode.children;
        if (typeof vnode.children === "object" && vnode.children.default) {
          const originalDefault = vnode.children.default;
          newChildren = {
            ...vnode.children,
            default: (slotProps) => {
              const childVnodes = originalDefault(slotProps);
              if (Array.isArray(childVnodes)) {
                return childVnodes.map(processVNode).filter(Boolean);
              }
              return processVNode(childVnodes);
            }
          };
        } else if (Array.isArray(vnode.children)) {
          newChildren = vnode.children.map(processVNode).filter(Boolean);
        }
        return vue.cloneVNode(vnode, vnode.props, newChildren);
      }
      return vnode;
    };
    const render = vue.computed(() => {
      const vnodeArray = Array.isArray(props.vnode) ? props.vnode : [props.vnode];
      return vnodeArray.map((vnode) => {
        const processed = processVNode(vnode);
        return processed ? vue.h(processed) : null;
      }).filter(Boolean);
    });
    return () => render.value;
  }
});

exports.default = TableColumnVNodeRenderer;
//# sourceMappingURL=TableColumnVNodeRenderer.js.map
