import '../../globals.js';
// Copyright 2022-2024, University of Colorado Boulder
/**
 * Ticks for a slider.
 *
 * @author Jonathan Olson (PhET Interactive Simulations)
 *
 */
import DerivedProperty from '../../axon/js/DerivedProperty.js';
import { Shape } from '../../kite/js/imports.js';
import Orientation from '../../phet-core/js/Orientation.js';
import { ManualConstraint, Node, Path } from '../../scenery/js/imports.js';
import sun from './sun.js';
import SunConstants from './SunConstants.js';
export default class SliderTick {
    // NOTE: This could be cleaned up, so we could remove ticks or do other nice things
    constructor(parent, value, label, length, stroke, lineWidth, tickOptions, orientation, track) {
        this.parent = parent;
        this.value = value;
        this.label = label;
        this.labelXProperty = new DerivedProperty([track.valueToPositionProperty], valueToPosition => valueToPosition.evaluate(value));
        // ticks
        this.tickNode = new Node();
        parent.addChild(this.tickNode);
        const tickInitialPoint = tickOptions.setTickInitialPoint(track.bounds, length);
        const tickPath = new Path(new Shape()
            .moveTo(tickInitialPoint.x, tickInitialPoint.y)
            .lineTo(0, tickInitialPoint.y - length), { stroke: stroke, lineWidth: lineWidth });
        this.labelXProperty.link(x => {
            tickPath.x = x;
        });
        this.tickNode.addChild(tickPath);
        // label
        if (label) {
            this.labelContainer = new Node({
                pickable: false
            });
            this.tickNode.addChild(this.labelContainer);
            this.labelContainer.addChild(label);
            // For a vertical slider, rotate labels opposite the rotation of the slider, so that they appear as expected.
            if (orientation === Orientation.VERTICAL) {
                this.labelContainer.rotation = -SunConstants.SLIDER_VERTICAL_ROTATION;
            }
            this.labelManualConstraint = ManualConstraint.create(this.tickNode, [tickPath, this.labelContainer], (tickProxy, labelProxy) => {
                tickOptions.positionLabel(labelProxy, tickProxy.bounds);
            });
        }
    }
    dispose() {
        this.parent.removeChild(this.tickNode);
        this.labelContainer && this.labelContainer.dispose();
        this.labelXProperty.dispose();
        this.labelManualConstraint && this.labelManualConstraint.dispose();
    }
}
sun.register('SliderTick', SliderTick);
//# sourceMappingURL=SliderTick.js.map