import '../../../../assert/js/assert.js';
import '../../../../globals.js';
// Copyright 2021-2024, University of Colorado Boulder
/**
 * A configurable cell containing a Node used for FlowConstraint layout
 *
 * @author Jonathan Olson <jonathan.olson@colorado.edu>
 */
import { FLOW_CONFIGURABLE_OPTION_KEYS, FlowConfigurable, MarginLayoutCell, scenery } from '../../imports.js';
import optionize from '../../../../phet-core/js/optionize.js';
const FLOW_CELL_KEYS = [
    ...FLOW_CONFIGURABLE_OPTION_KEYS,
    'isSeparator'
];
export default class FlowCell extends FlowConfigurable(MarginLayoutCell) {
    constructor(constraint, node, proxy) {
        super(constraint, node, proxy);
        // (scenery-internal) Set during FlowConstraint layout
        this.size = 0;
        // (scenery-internal)
        this._isSeparator = false;
        this.flowConstraint = constraint;
        this.orientation = constraint.orientation;
        this.onLayoutOptionsChange(true);
    }
    // The used value, with this cell's value taking precedence over the constraint's default
    get effectiveAlign() {
        return this._align !== null ? this._align : this.flowConstraint._align;
    }
    // The used value, with this cell's value taking precedence over the constraint's default
    get effectiveCellAlign() {
        return this._cellAlign !== null ? this._cellAlign : this.flowConstraint._cellAlign;
    }
    // The used value, with this cell's value taking precedence over the constraint's default
    get effectiveStretch() {
        return this._stretch !== null ? this._stretch : this.flowConstraint._stretch;
    }
    // The used value, with this cell's value taking precedence over the constraint's default
    get effectiveGrow() {
        return this._grow !== null ? this._grow : this.flowConstraint._grow;
    }
    onLayoutOptionsChange(isInitial = false) {
        if (this.node.layoutOptions) {
            this.setOptions(this.node.layoutOptions);
        }
        super.onLayoutOptionsChange();
        if (!isInitial) {
            this.flowConstraint.updateLayoutAutomatically();
        }
    }
    setOptions(providedOptions) {
        const options = optionize()({
            isSeparator: false
        }, providedOptions);
        assert && Object.keys(options).forEach(key => {
            assert && assert(FLOW_CELL_KEYS.includes(key), `Cannot provide key ${key} to a FlowCell's layoutOptions. Perhaps this is a Grid-style layout option?`);
        });
        this._isSeparator = options.isSeparator;
        // Clear options that are not provided in the mutate options (but if they are present, do NOT clear, so we avoid
        // more potential for infinite loops)
        this.setConfigToInherit(options);
        this.mutateConfigurable(options);
    }
}
scenery.register('FlowCell', FlowCell);
//# sourceMappingURL=FlowCell.js.map