function _check_private_redeclaration(obj, privateCollection) {
    if (privateCollection.has(obj)) {
        throw new TypeError("Cannot initialize the same private elements twice on an object");
    }
}
function _class_apply_descriptor_get(receiver, descriptor) {
    if (descriptor.get) {
        return descriptor.get.call(receiver);
    }
    return descriptor.value;
}
function _class_apply_descriptor_set(receiver, descriptor, value) {
    if (descriptor.set) {
        descriptor.set.call(receiver, value);
    } else {
        if (!descriptor.writable) {
            throw new TypeError("attempted to set read only private field");
        }
        descriptor.value = value;
    }
}
function _class_extract_field_descriptor(receiver, privateMap, action) {
    if (!privateMap.has(receiver)) {
        throw new TypeError("attempted to " + action + " private field on non-instance");
    }
    return privateMap.get(receiver);
}
function _class_private_field_get(receiver, privateMap) {
    var descriptor = _class_extract_field_descriptor(receiver, privateMap, "get");
    return _class_apply_descriptor_get(receiver, descriptor);
}
function _class_private_field_init(obj, privateMap, value) {
    _check_private_redeclaration(obj, privateMap);
    privateMap.set(obj, value);
}
function _class_private_field_set(receiver, privateMap, value) {
    var descriptor = _class_extract_field_descriptor(receiver, privateMap, "set");
    _class_apply_descriptor_set(receiver, descriptor, value);
    return value;
}
import { StretchStrategy } from './_base.mjs';
var /**
   * The width of the last calculated column.
   *
   * @type {number}
   */ _lastColumnWidth = /*#__PURE__*/ new WeakMap(), /**
   * The index of the last calculated column.
   *
   * @type {number}
   */ _lastColumnIndex = /*#__PURE__*/ new WeakMap();
/**
 * @typedef StretchStrategyCalcArgs
 * @property {number} viewportWidth The width of the viewport.
 */ /**
 * The strategy calculates only the last column widths to fill the viewport.
 *
 * @private
 * @class StretchLastStrategy
 */ export class StretchLastStrategy extends StretchStrategy {
    /**
   * Prepares the strategy for the calculation.
   *
   * @param {StretchStrategyCalcArgs} calcArgs The calculation arguments.
   */ prepare(calcArgs) {
        super.prepare(calcArgs);
        _class_private_field_set(this, _lastColumnWidth, 0);
        _class_private_field_set(this, _lastColumnIndex, -1);
    }
    /**
   * Sets the base widths of the columns with which the strategy will work with.
   *
   * @param {number} columnVisualIndex The visual index of the column.
   * @param {number} columnWidth The width of the column.
   */ setColumnBaseWidth(columnVisualIndex, columnWidth) {
        super.setColumnBaseWidth(columnVisualIndex, columnWidth);
        _class_private_field_set(this, _lastColumnIndex, columnVisualIndex);
        _class_private_field_set(this, _lastColumnWidth, columnWidth);
    }
    /**
   * Calculates the columns widths.
   */ calculate() {
        if (_class_private_field_get(this, _lastColumnIndex) === -1) {
            return;
        }
        const allColumnsWidth = Array.from(this.baseWidths).reduce((sum, [, width])=>sum + width, 0);
        const lastColumnWidth = this.viewportWidth - allColumnsWidth + _class_private_field_get(this, _lastColumnWidth);
        // If the calculated width would shrink the last column below its base width,
        // don't apply stretching at all (similar to StretchAllStrategy behavior)
        if (lastColumnWidth < _class_private_field_get(this, _lastColumnWidth)) {
            this.stretchedWidths.clear();
            return;
        }
        this.stretchedWidths.set(_class_private_field_get(this, _lastColumnIndex), lastColumnWidth);
    }
    constructor(...args){
        super(...args), _class_private_field_init(this, _lastColumnWidth, {
            writable: true,
            value: void 0
        }), _class_private_field_init(this, _lastColumnIndex, {
            writable: true,
            value: void 0
        }), _class_private_field_set(this, _lastColumnWidth, 0), _class_private_field_set(this, _lastColumnIndex, -1);
    }
}
