"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const types = require("../../../../utils/types.js");
const useGlobalConfig = require("../../../config-provider/src/hooks/use-global-config.js");
const index = require("../../../checkbox/index.js");
const util = require("../util.js");
const config = require("../config.js");
const watcherHelper = require("./watcher-helper.js");
const renderHelper = require("./render-helper.js");
const defaults = require("./defaults.js");
const Vue = require("vue");
const shared_esmBundler = require("../../../../../../@vue/shared/dist/shared.esm-bundler.js");
let columnIdSeed = 1;
var table_column_default = Vue.defineComponent({
  name: "ElTableColumn",
  components: { ElCheckbox: index.ElCheckbox },
  props: defaults.default,
  setup(props, { slots }) {
    const instance = Vue.getCurrentInstance();
    const globalConfig = useGlobalConfig.useGlobalConfig("table");
    const columnConfig = Vue.ref({});
    const owner = Vue.computed(() => {
      let parent2 = instance.parent;
      while (parent2 && !parent2.tableId) parent2 = parent2.parent;
      return parent2;
    });
    const { registerNormalWatchers, registerComplexWatchers } = watcherHelper.default(owner, props);
    const { columnId, isSubColumn, realHeaderAlign, columnOrTableParent, setColumnWidth, setColumnForcedProps, setColumnRenders, getPropsData, getColumnElIndex, realAlign, updateColumnOrder } = renderHelper.default(props, slots, owner);
    const parent = columnOrTableParent.value;
    columnId.value = `${"tableId" in parent && parent.tableId || "columnId" in parent && parent.columnId}_column_${columnIdSeed++}`;
    Vue.onBeforeMount(() => {
      var _a, _b;
      isSubColumn.value = owner.value !== parent;
      const type = props.type || "default";
      const sortable = props.sortable === "" ? true : props.sortable;
      const showOverflowTooltip = type === "selection" ? false : types.isUndefined(props.showOverflowTooltip) ? parent.props.showOverflowTooltip ?? ((_a = globalConfig.value) == null ? void 0 : _a.showOverflowTooltip) : props.showOverflowTooltip;
      const tooltipFormatter = types.isUndefined(props.tooltipFormatter) ? parent.props.tooltipFormatter ?? ((_b = globalConfig.value) == null ? void 0 : _b.tooltipFormatter) : props.tooltipFormatter;
      const defaults2 = {
        ...config.cellStarts[type],
        id: columnId.value,
        type,
        property: props.prop || props.property,
        align: realAlign,
        headerAlign: realHeaderAlign,
        showOverflowTooltip,
        tooltipFormatter,
        filterable: props.filters || props.filterMethod,
        filteredValue: [],
        filterPlacement: "",
        filterClassName: "",
        isColumnGroup: false,
        isSubColumn: false,
        filterOpened: false,
        sortable,
        index: props.index,
        rawColumnKey: instance.vnode.key
      };
      let column = getPropsData([
        "columnKey",
        "label",
        "className",
        "labelClassName",
        "type",
        "renderHeader",
        "formatter",
        "fixed",
        "resizable"
      ], [
        "sortMethod",
        "sortBy",
        "sortOrders"
      ], ["selectable", "reserveSelection"], [
        "filterMethod",
        "filters",
        "filterMultiple",
        "filterOpened",
        "filteredValue",
        "filterPlacement",
        "filterClassName"
      ]);
      column = util.mergeOptions(defaults2, column);
      column = util.compose(setColumnRenders, setColumnWidth, setColumnForcedProps)(column);
      columnConfig.value = column;
      registerNormalWatchers();
      registerComplexWatchers();
    });
    Vue.onMounted(() => {
      var _a, _b;
      const parent2 = columnOrTableParent.value;
      const children = isSubColumn.value ? (_a = parent2.vnode.el) == null ? void 0 : _a.children : (_b = parent2.refs.hiddenColumns) == null ? void 0 : _b.children;
      const getColumnIndex = () => getColumnElIndex(children || [], instance.vnode.el);
      columnConfig.value.getColumnIndex = getColumnIndex;
      getColumnIndex() > -1 && owner.value.store.commit("insertColumn", columnConfig.value, isSubColumn.value ? "columnConfig" in parent2 && parent2.columnConfig.value : null, updateColumnOrder);
    });
    Vue.onBeforeUnmount(() => {
      const getColumnIndex = columnConfig.value.getColumnIndex;
      (getColumnIndex ? getColumnIndex() : -1) > -1 && owner.value.store.commit("removeColumn", columnConfig.value, isSubColumn.value ? "columnConfig" in parent && parent.columnConfig.value : null, updateColumnOrder);
    });
    instance.columnId = columnId.value;
    instance.columnConfig = columnConfig;
  },
  render() {
    var _a, _b, _c;
    try {
      const renderDefault = (_b = (_a = this.$slots).default) == null ? void 0 : _b.call(_a, {
        row: {},
        column: {},
        $index: -1
      });
      const children = [];
      if (shared_esmBundler.isArray(renderDefault)) {
        for (const childNode of renderDefault) if (((_c = childNode.type) == null ? void 0 : _c.name) === "ElTableColumn" || childNode.shapeFlag & 2) children.push(childNode);
        else if (childNode.type === Vue.Fragment && shared_esmBundler.isArray(childNode.children)) childNode.children.forEach((vnode) => {
          if ((vnode == null ? void 0 : vnode.patchFlag) !== 1024 && !shared_esmBundler.isString(vnode == null ? void 0 : vnode.children)) children.push(vnode);
        });
      }
      return Vue.h("div", children);
    } catch {
      return Vue.h("div", []);
    }
  }
});
exports.default = table_column_default;
