import '../../../../assert/js/assert.js';
import '../../../../globals.js';
// Copyright 2022-2024, University of Colorado Boulder
/**
 * A configurable cell containing a Node used for more permanent layouts
 *
 * @author Jonathan Olson <jonathan.olson@colorado.edu>
 */
import Orientation from '../../../../phet-core/js/Orientation.js';
import { LayoutProxyProperty, scenery } from '../../imports.js';
// NOTE: This would be an abstract class, but that is incompatible with how mixin constraints work in TypeScript
export default class LayoutCell {
    /**
     * NOTE: Consider this scenery-internal AND protected. It's effectively a protected constructor for an abstract type,
     * but cannot be due to how mixins constrain things (TypeScript doesn't work with private/protected things like this)
     *
     * NOTE: Methods can be marked as protected, however!
     *
     * (scenery-internal)
     *
     * @param constraint
     * @param node
     * @param proxy - If not provided, LayoutProxies will be computed and updated based on the ancestorNode of the
     *                constraint. This includes more work, and ideally should be avoided for things like FlowBox/GridBox
     *                (but will be needed by ManualConstraint or other direct LayoutConstraint usage)
     */
    constructor(constraint, node, proxy) {
        if (proxy) {
            this.layoutProxyProperty = null;
            this._proxy = proxy;
        }
        else {
            this._proxy = null;
            // If a LayoutProxy is not provided, we'll listen to (a) all the trails between our ancestor and this node,
            // (b) construct layout proxies for it (and assign here), and (c) listen to ancestor transforms to refresh
            // the layout when needed.
            this.layoutProxyProperty = new LayoutProxyProperty(constraint.ancestorNode, node, {
                onTransformChange: () => constraint.updateLayoutAutomatically()
            });
            this.layoutProxyProperty.link(proxy => {
                this._proxy = proxy;
                constraint.updateLayoutAutomatically();
            });
        }
        this._constraint = constraint;
        this._node = node;
        this.layoutOptionsListener = this.onLayoutOptionsChange.bind(this);
        this.node.layoutOptionsChangedEmitter.addListener(this.layoutOptionsListener);
    }
    // Can't be abstract, we're using mixins :(
    onLayoutOptionsChange() {
        // Lint rule not needed here
    }
    /**
     * (scenery-internal)
     */
    get node() {
        return this._node;
    }
    /**
     * (scenery-internal)
     */
    isConnected() {
        return this._proxy !== null;
    }
    /**
     * (scenery-internal)
     */
    get proxy() {
        assert && assert(this._proxy);
        return this._proxy;
    }
    /**
     * (scenery-internal)
     */
    isSizable(orientation) {
        return orientation === Orientation.HORIZONTAL ? this.proxy.widthSizable : this.proxy.heightSizable;
    }
    /**
     * Releases references
     */
    dispose() {
        this.layoutProxyProperty && this.layoutProxyProperty.dispose();
        this.node.layoutOptionsChangedEmitter.removeListener(this.layoutOptionsListener);
    }
}
scenery.register('LayoutCell', LayoutCell);
//# sourceMappingURL=LayoutCell.js.map