'use strict';

/**
 * A trigger strategy that hides the appendable element when a global mouse down event occurs outside the element.
 */
class ClickOutsideOnlyToDismissStrategy {
  /**
   * Determines if the strategy can evaluate the given event type.
   *
   * @param {VegaEAEventType} type - The type of the event.
   * @returns {boolean} True if the event type is 'globalMouseDown', otherwise false.
   */
  canEvaluate(type) {
    return type === 'click-outside';
  }
  /**
   * Evaluates the trigger context and determines whether to hide the appendable element.
   *
   * @param {VegaEATriggerContext} context - The context of the trigger event.
   * @returns {VegaEATriggerResult} An object indicating whether to hide the appendable element.
   */
  evaluate(context) {
    if (context.eventType === 'click-outside' && context.currentState.isVisible) {
      return {
        nextAction: 'hide',
      };
    }
    return {};
  }
}

exports.ClickOutsideOnlyToDismissStrategy = ClickOutsideOnlyToDismissStrategy;
