import _ from 'lodash';
import '../../../../assert/js/assert.js';
import '../../../../globals.js';
import { LayoutCell, LayoutConstraint, Node, scenery } from '../../imports.js';
export default class RelaxedManualConstraint extends LayoutConstraint {
    constructor(ancestorNode, nodes, layoutCallback) {
        assert && assert(Array.isArray(nodes) && _.every(nodes, node => node instanceof Node));
        super(ancestorNode);
        // Don't churn updates during construction
        this.lock();
        this.nodes = nodes;
        // Having cells will give us proxy Properties and listening for when it's added for free
        this.cells = nodes.map(node => new LayoutCell(this, node, null));
        this.layoutCallback = layoutCallback;
        // Hook up to listen to these nodes (will be handled by LayoutConstraint disposal)
        this.nodes.forEach(node => this.addNode(node, false));
        // Run the layout manually at the start
        this.unlock();
        this.updateLayout();
    }
    /**
     * (scenery-internal)
     */
    layout() {
        super.layout();
        assert && assert(_.every(this.nodes, node => !node.isDisposed));
        // If a cell is disconnected, pass in null
        const proxies = this.cells.map(cell => cell.isConnected() ? cell.proxy : null);
        this.layoutCallback.apply(null, proxies);
        this.finishedLayoutEmitter.emit();
    }
    /**
     * Releases references
     */
    dispose() {
        this.cells.forEach(cell => cell.dispose());
        super.dispose();
    }
    static create(ancestorNode, nodes, layoutCallback) {
        return new RelaxedManualConstraint(ancestorNode, nodes, layoutCallback);
    }
}
scenery.register('RelaxedManualConstraint', RelaxedManualConstraint);
//# sourceMappingURL=RelaxedManualConstraint.js.map