/**
 * ClickTriggerStrategy handles 'targetClick' and 'globalMouseDown' events to toggle or hide the appendable element.
 */
export class ClickTriggerStrategy {
  /**
   * 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 'targetClick' or 'globalMouseDown', otherwise false.
   */
  canEvaluate(type) {
    return type === 'target-click' || type === 'click-outside';
  }
  /**
   * Evaluates the trigger context and determines whether to show, hide, or toggle the appendable element.
   *
   * @param {VegaEATriggerContext} context - The context of the trigger event.
   * @returns {VegaEATriggerResult} An object indicating whether to show, hide, or toggle the appendable element.
   */
  evaluate(context) {
    if (context.eventType === 'target-click') {
      return {
        nextAction: context.currentState.isVisible ? 'hide' : 'show',
      };
    }
    if (context.eventType === 'click-outside' && context.currentState.isVisible) {
      return {
        nextAction: 'hide',
      };
    }
    return {};
  }
}
