import { ref as d, computed as h, unref as n } from "vue";
import "../../utils/index.mjs";
import { isDef as w } from "../../utils/is.mjs";
function r(s, e) {
  s.forEach((l) => {
    e(l), l.children?.length && r(l.children, e);
  });
}
const A = (s) => {
  const e = d(s), l = h(() => n(e).every((t) => t.show));
  function f() {
    const t = n(e);
    r(t, (o) => {
      !o.disabled && (o.show = !0);
    });
  }
  function i() {
    const t = n(e);
    r(t, (o) => {
      !o.disabled && (o.show = !1);
    });
  }
  function u() {
    n(l) ? i() : f();
  }
  function a(t, o) {
    r(n(e), (c) => {
      c.key === t && (c.show = w(o) ? o : !c.show);
    });
  }
  function S(t) {
    e.value = t;
  }
  return {
    columnState: e,
    selectAll: f,
    unSelectAll: i,
    toggleSelect: a,
    setColumnState: S,
    isAllSelected: l,
    toggleSelectAll: u
  };
};
export {
  A as useTableColumnState
};
