import '../../globals.js';
// Copyright 2014-2024, University of Colorado Boulder
/**
 * Base class for Joist buttons such as the "home" button and "PhET" button that show custom highlighting on mouseover.
 *
 * @author Sam Reid (PhET Interactive Simulations)
 */
import Multilink from '../../axon/js/Multilink.js';
import { Shape } from '../../kite/js/imports.js';
import optionize from '../../phet-core/js/optionize.js';
import { Color, Node, SceneryConstants, Voicing } from '../../scenery/js/imports.js';
import ButtonInteractionState from '../../sun/js/buttons/ButtonInteractionState.js';
import PushButtonInteractionStateProperty from '../../sun/js/buttons/PushButtonInteractionStateProperty.js';
import PushButtonModel from '../../sun/js/buttons/PushButtonModel.js';
import HighlightNode from './HighlightNode.js';
import joist from './joist.js';
export default class JoistButton extends Voicing(Node) {
    /**
     * @param content - the scenery node to render as the content of the button
     * @param navigationBarFillProperty - the color of the navbar, as a string.
     * @param [providedOptions]
     */
    constructor(content, navigationBarFillProperty, providedOptions) {
        const options = optionize()({
            cursor: 'pointer', // {string}
            listener: null, // {function}
            // Customization for the highlight region, see overrides in HomeButton and PhetButton
            highlightExtensionWidth: 0,
            highlightExtensionHeight: 0,
            highlightCenterOffsetX: 0,
            highlightCenterOffsetY: 0,
            pointerAreaDilationX: 0,
            pointerAreaDilationY: 0,
            // JoistButtons by default do not have a featured enabledProperty
            enabledPropertyOptions: { phetioFeatured: false },
            disabledOpacity: SceneryConstants.DISABLED_OPACITY,
            // pdom
            tagName: 'button'
        }, providedOptions);
        // Creates the highlights for the button.
        const createHighlight = function (fill) {
            return new HighlightNode(content.width + options.highlightExtensionWidth, content.height + options.highlightExtensionHeight, {
                centerX: content.centerX + options.highlightCenterOffsetX,
                centerY: content.centerY + options.highlightCenterOffsetY,
                fill: fill,
                pickable: false
            });
        };
        // Highlight against the black background
        const brightenHighlight = createHighlight('white');
        // Highlight against the white background
        const darkenHighlight = createHighlight('black');
        options.children = [content, brightenHighlight, darkenHighlight];
        super(options);
        this.buttonModel = new PushButtonModel(options);
        // Button interactions
        const interactionStateProperty = new PushButtonInteractionStateProperty(this.buttonModel);
        this.interactionStateProperty = interactionStateProperty;
        // Update the highlights based on whether the button is highlighted and whether it is against a light or dark background.
        Multilink.multilink([interactionStateProperty, navigationBarFillProperty, this.buttonModel.enabledProperty], (interactionState, navigationBarFill, enabled) => {
            const useDarkenHighlight = !navigationBarFill.equals(Color.BLACK);
            brightenHighlight.visible = !useDarkenHighlight && enabled &&
                (interactionState === ButtonInteractionState.OVER ||
                    interactionState === ButtonInteractionState.PRESSED);
            darkenHighlight.visible = useDarkenHighlight && enabled &&
                (interactionState === ButtonInteractionState.OVER ||
                    interactionState === ButtonInteractionState.PRESSED);
        });
        // Keep the cursor in sync with if the button is enabled.
        // JoistButtons exist for the lifetime of the sim, and don't need to be disposed
        this.buttonModel.enabledProperty.link(enabled => {
            this.cursor = enabled ? options.cursor : null;
        });
        // Hook up the input listener
        this._pressListener = this.buttonModel.createPressListener({
            tandem: options.tandem.createTandem('pressListener')
        });
        this.addInputListener(this._pressListener);
        // eliminate interactivity gap between label and button
        this.mouseArea = this.touchArea = Shape.bounds(this.bounds.dilatedXY(options.pointerAreaDilationX, options.pointerAreaDilationY));
        // shift the focus highlight for the joist button so that the bottom is always on screen
        this.focusHighlight = Shape.bounds(this.bounds.shiftedY(-3));
    }
    /**
     * Is the button currently firing because of accessibility input coming from the PDOM?
     * (pdom)
     */
    isPDOMClicking() {
        return this._pressListener.pdomClickingProperty.get();
    }
}
joist.register('JoistButton', JoistButton);
//# sourceMappingURL=JoistButton.js.map