'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var vue = require('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 = vue.computed(() => {
    const _columns = vue.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 = vue.computed(() => {
    return vue.unref(mappedColumns).filter((column) => !column.hidden);
  });
  const fixedColumnsOnLeft = vue.computed(() => vue.unref(visibleColumns).filter((column) => column.fixed === "left" || column.fixed === true));
  const fixedColumnOnRight = vue.computed(() => vue.unref(visibleColumns).filter((column) => column.fixed === "right"));
  const normalColumns = vue.computed(() => vue.unref(visibleColumns).filter((column) => !column.fixed));
  const mainColumns = vue.computed(() => {
    const ret = [];
    vue.unref(fixedColumnsOnLeft).forEach((column) => {
      ret.push({
        ...column,
        isPlaceholder: true
      });
    });
    vue.unref(normalColumns).forEach((column) => {
      ret.push(column);
    });
    vue.unref(fixedColumnOnRight).forEach((column) => {
      ret.push({
        ...column,
        isPlaceholder: true
      });
    });
    return ret;
  });
  const columnsStyle = vue.computed(() => {
    const columns2 = vue.unref(mappedColumns);
    return columns2.reduce((style, column) => {
      style[column.key] = getColumnStyle(column, vue.unref(fixed));
      return style;
    }, {});
  });
  return {
    columns: mappedColumns,
    columnsStyle,
    fixedColumnsOnLeft,
    fixedColumnOnRight,
    mainColumns,
    normalColumns,
    visibleColumns
  };
}
function useTable() {
}

exports.useColumns = useColumns;
exports.useTable = useTable;
//# sourceMappingURL=useTable2.js.map
