import { defineComponent, computed, cloneVNode, h } from 'vue';

var TableColumnVNodeRenderer = /* @__PURE__ */ 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 = computed(() => {
      const matchedItems = props.propsList.filter((propsItem) => {
        return props.defaultPropsList.some((defaultItem) => defaultItem.prop === propsItem.prop);
      });
      const additionalItems = props.defaultPropsList.filter((defaultItem) => {
        return !props.propsList.some((propsItem) => propsItem.prop === defaultItem.prop);
      });
      return [...matchedItems, ...additionalItems];
    });
    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 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 cloneVNode(vnode, vnode.props, newChildren);
      }
      return vnode;
    };
    const render = computed(() => {
      const vnodeArray = Array.isArray(props.vnode) ? props.vnode : [props.vnode];
      const processedVnodes = vnodeArray.map((vnode) => processVNode(vnode)).filter(Boolean);
      const topLevelColumns = [];
      const multiLevelHeaders = [];
      processedVnodes.forEach((vnode) => {
        if (vnode?.type?.name === "GmTableColumnPro") {
          topLevelColumns.push(vnode);
        } else {
          multiLevelHeaders.push(vnode);
        }
      });
      const orderedColumns = [];
      const processedProps = /* @__PURE__ */ new Set();
      mergePropsList.value.forEach((propsConfig) => {
        if (!propsConfig.isShow || propsConfig.type === "edit") {
          return;
        }
        const matchedColumn = topLevelColumns.find((col) => col?.props?.prop === propsConfig.prop);
        if (matchedColumn) {
          orderedColumns.push(matchedColumn);
          processedProps.add(propsConfig.prop);
        }
      });
      return [...multiLevelHeaders, ...orderedColumns].map((vnode) => vnode ? h(vnode) : null).filter(Boolean);
    });
    return () => render.value;
  }
});

export { TableColumnVNodeRenderer as default };
//# sourceMappingURL=TableColumnVNodeRenderer.mjs.map
