// Copyright 2020, University of Colorado Boulder

/**
 * Property to control the enabled of something. In general this should never be called by clients, but instead is factored
 * out for consistency in PhET libraries. This serves as the default Property to control enabled with PhET-iO instrumentation
 *
 * @author Michael Kauzmann(PhET Interactive Simulations)
 */

import merge from '../../phet-core/js/merge.js';
import axon from './axon.js';
import BooleanProperty from './BooleanProperty.js';

const TANDEM_NAME = 'enabledProperty';

class EnabledProperty extends BooleanProperty {

  /**
   * @param {boolean} initialEnabled
   * @param {Object} [options]
   */
  constructor( initialEnabled, options ) {
    if ( assert && options && options.tandem ) {
      assert && assert( options.tandem.name === TANDEM_NAME, `EnabledProperty tandems should be named ${TANDEM_NAME}` );
    }

    super( initialEnabled, merge( {
      phetioDocumentation: 'Determines whether the element is enabled (true) or disabled (false).',
      phetioFeatured: true
    }, options ) );
  }

  /**
   * @public
   * @returns {string}
   */
  static get TANDEM_NAME() { return TANDEM_NAME; }
}

axon.register( 'EnabledProperty', EnabledProperty );
export default EnabledProperty;
@@ -704,24 +704,616 @@
 options ) %7B%0A
+%0A    options = merge( %7B%0A      phetioDocumentation: 'Determines whether the element is enabled (true) or disabled (false).',%0A      phetioFeatured: true,%0A%0A      // by default, the tandem name must match. In rare occurrences (such as when one model must have 2 separate%0A      // EnabledProperties, like this.mass1EnabledProperty = ..., this.mass2EnabledProperty = ...%0A      // you can opt out of the name check. This should be used sparingly. For instance, for the example above, it may%0A      // be better to do this.mass1.enabledProperty anyways.%0A      checkTandemName: true%0A    %7D, options );%0A%0A
     if ( ass
@@ -1345,16 +1345,43 @@
 .tandem 
+&& options.checkTandemName 
 ) %7B%0A    
@@ -1534,159 +1534,16 @@
 led,
- merge( %7B%0A      phetioDocumentation: 'Determines whether the element is enabled (true) or disabled (false).',%0A      phetioFeatured: true%0A    %7D,
  options
  ) )
@@ -1538,18 +1538,16 @@
  options
- )
  );%0A  %7D%0A

Allow EnabledProperty to opt out of name check, see https://github.com/phetsims/axon/issues/340