import '../../assert/js/assert.js';
import '../../globals.js';
import optionize from '../../phet-core/js/optionize.js';
import { Node, Rectangle } from '../../scenery/js/imports.js';
import joist from './joist.js';
import Screen from './Screen.js';
export default class ScreenIcon extends Node {
    constructor(iconNode, providedOptions) {
        const options = optionize()({
            // SelfOptions
            size: Screen.MINIMUM_HOME_SCREEN_ICON_SIZE,
            maxIconWidthProportion: 0.85,
            maxIconHeightProportion: 0.85,
            fill: 'white',
            stroke: null
        }, providedOptions);
        assert && assert(options.maxIconWidthProportion > 0 && options.maxIconWidthProportion <= 1);
        assert && assert(options.maxIconHeightProportion > 0 && options.maxIconHeightProportion <= 1);
        const background = new Rectangle(0, 0, options.size.width, options.size.height, {
            fill: options.fill,
            stroke: options.stroke
        });
        iconNode.pickable = false;
        // iconNode may have a dynamic size - for example, if it involves a string Property.
        // So if it's size changes, adjust its scale and re-center.
        const localBoundsListener = () => {
            iconNode.setScaleMagnitude(1);
            iconNode.setScaleMagnitude(Math.min(options.maxIconWidthProportion * background.width / iconNode.width, options.maxIconHeightProportion * background.height / iconNode.height));
            iconNode.center = background.center;
        };
        iconNode.localBoundsProperty.link(localBoundsListener);
        options.children = [background, iconNode];
        super(options);
        this.disposeScreenIcon = () => {
            if (iconNode.localBoundsProperty.hasListener(localBoundsListener)) {
                iconNode.localBoundsProperty.unlink(localBoundsListener);
            }
        };
    }
    dispose() {
        this.disposeScreenIcon();
        super.dispose();
    }
}
joist.register('ScreenIcon', ScreenIcon);
//# sourceMappingURL=ScreenIcon.js.map