"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const types = require("../../../../utils/types.js");
const shared_esmBundler = require("../../../../../../@vue/shared/dist/shared.esm-bundler.js");
const useGlobalConfig = require("../../../config-provider/src/hooks/use-global-config.js");
const util = require("../util.js");
const Vue = require("vue");
function getAllAliases(props, aliases) {
  return props.reduce((prev, cur) => {
    prev[cur] = cur;
    return prev;
  }, aliases);
}
function useWatcher(owner, props_) {
  const instance = Vue.getCurrentInstance();
  const registerComplexWatchers = () => {
    const props = ["fixed"];
    const aliases = {
      realWidth: "width",
      realMinWidth: "minWidth"
    };
    const allAliases = getAllAliases(props, aliases);
    Object.keys(allAliases).forEach((key) => {
      const columnKey = aliases[key];
      if (shared_esmBundler.hasOwn(props_, columnKey)) Vue.watch(() => props_[columnKey], (newVal) => {
        let value = newVal;
        if (columnKey === "width" && key === "realWidth") value = util.parseWidth(newVal);
        if (columnKey === "minWidth" && key === "realMinWidth") value = util.parseMinWidth(newVal);
        instance.columnConfig.value[columnKey] = value;
        instance.columnConfig.value[key] = value;
        const updateColumns = columnKey === "fixed";
        owner.value.store.scheduleLayout(updateColumns);
      });
    });
  };
  const registerNormalWatchers = () => {
    const props = [
      "label",
      "filters",
      "filterMultiple",
      "filteredValue",
      "sortable",
      "index",
      "formatter",
      "className",
      "labelClassName",
      "filterClassName",
      "showOverflowTooltip",
      "tooltipFormatter",
      "resizable"
    ];
    const parentProps = ["showOverflowTooltip"];
    const aliases = {
      property: "prop",
      align: "realAlign",
      headerAlign: "realHeaderAlign"
    };
    const allAliases = getAllAliases(props, aliases);
    Object.keys(allAliases).forEach((key) => {
      const columnKey = aliases[key];
      if (shared_esmBundler.hasOwn(props_, columnKey)) Vue.watch(() => props_[columnKey], (newVal) => {
        instance.columnConfig.value[key] = newVal;
        if (key === "filters" || key === "filterMethod") instance.columnConfig.value["filterable"] = !!(instance.columnConfig.value["filters"] || instance.columnConfig.value["filterMethod"]);
      });
    });
    parentProps.forEach((key) => {
      if (shared_esmBundler.hasOwn(owner.value.props, key)) Vue.watch(() => owner.value.props[key], (newVal) => {
        if (instance.columnConfig.value.type === "selection") return;
        if (!types.isUndefined(props_[key])) return;
        instance.columnConfig.value[key] = newVal;
      });
    });
    const globalConfig = useGlobalConfig.useGlobalConfig("table");
    if (globalConfig.value && shared_esmBundler.hasOwn(globalConfig.value, "showOverflowTooltip")) Vue.watch(() => {
      var _a;
      return (_a = globalConfig.value) == null ? void 0 : _a.showOverflowTooltip;
    }, (newVal) => {
      if (instance.columnConfig.value.type === "selection") return;
      if (!types.isUndefined(props_.showOverflowTooltip) || !types.isUndefined(owner.value.props.showOverflowTooltip)) return;
      instance.columnConfig.value.showOverflowTooltip = newVal;
    });
  };
  return {
    registerComplexWatchers,
    registerNormalWatchers
  };
}
exports.default = useWatcher;
