import { computed } from 'vue';
import '../../_util/type';
export default function usePositions(itemHeights, columnCount, verticalGutter) {
  return computed(() => {
    var _a;
    const columnHeights = new Array(columnCount.value).fill(0);
    const itemPositions = new Map();
    for (let i = 0; i < ((_a = itemHeights.value) === null || _a === void 0 ? void 0 : _a.length); i += 1) {
      const [itemKey, itemHeight, itemColumn] = itemHeights.value[i];
      let targetColumnIndex = itemColumn !== null && itemColumn !== void 0 ? itemColumn : columnHeights.indexOf(Math.min(...columnHeights));
      targetColumnIndex = Math.min(targetColumnIndex, columnCount.value - 1);
      const top = columnHeights[targetColumnIndex];
      itemPositions.set(itemKey, {
        column: targetColumnIndex,
        top
      });
      columnHeights[targetColumnIndex] += itemHeight + verticalGutter.value;
    }
    return [itemPositions, Math.max(0, Math.max(...columnHeights) - verticalGutter.value)];
  });
}