import { computed, unref } from 'vue';

const getColumnStyle = (column, fixedColumn) => {
  var _a;
  const style = {
    ...(_a = column.style) != null ? _a : {},
    width: column.width
  };
  if (!fixedColumn) {
    if (column.maxWidth)
      style.maxWidth = column.maxWidth;
    if (column.minWidth)
      style.maxWidth = column.minWidth;
  }
  return style;
};
function useColumns(columns, fixed) {
  let mappedColumnsCopy = [];
  const mappedColumns = computed(() => {
    const _columns = unref(columns);
    const ret = _columns.map((column) => {
      if (!column.resizable)
        return column;
      let { width } = column;
      if (column.resizable) {
        const idx = _columns.findIndex((predicated) => column.key === predicated.key);
        if (idx >= 0 && _columns[idx].width === column.width) {
          width = mappedColumnsCopy[idx].width;
        }
      }
      return {
        ...column,
        width
      };
    });
    mappedColumnsCopy = ret;
    return ret;
  });
  const visibleColumns = computed(() => {
    return unref(mappedColumns).filter((column) => !column.hidden);
  });
  const fixedColumnsOnLeft = computed(() => unref(visibleColumns).filter((column) => column.fixed === "left" || column.fixed === true));
  const fixedColumnOnRight = computed(() => unref(visibleColumns).filter((column) => column.fixed === "right"));
  const normalColumns = computed(() => unref(visibleColumns).filter((column) => !column.fixed));
  const mainColumns = computed(() => {
    const ret = [];
    unref(fixedColumnsOnLeft).forEach((column) => {
      ret.push({
        ...column,
        isPlaceholder: true
      });
    });
    unref(normalColumns).forEach((column) => {
      ret.push(column);
    });
    unref(fixedColumnOnRight).forEach((column) => {
      ret.push({
        ...column,
        isPlaceholder: true
      });
    });
    return ret;
  });
  const columnsStyle = computed(() => {
    const columns2 = unref(mappedColumns);
    return columns2.reduce((style, column) => {
      style[column.key] = getColumnStyle(column, unref(fixed));
      return style;
    }, {});
  });
  return {
    columns: mappedColumns,
    columnsStyle,
    fixedColumnsOnLeft,
    fixedColumnOnRight,
    mainColumns,
    normalColumns,
    visibleColumns
  };
}
function useTable() {
}

export { useColumns, useTable };
//# sourceMappingURL=useTable2.mjs.map
