/**
 * HoverTriggerStrategy handles mouse enter and leave events on the target and appendable elements,
 * as well as global mouse down events to show or hide the appendable element.
 */
export class HoverTriggerStrategy {
  /**
   * 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 related to hover actions or global mouse down, otherwise false.
   */
  canEvaluate(type) {
    return [
      'target-mouseenter',
      'target-mouseleave',
      'element-mouseenter',
      'element-mouseleave',
    ].includes(type);
  }
  /**
   * 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 (['target-mouseenter', 'element-mouseenter'].includes(context.eventType)) {
      return !context.currentState.isVisible
        ? {
          nextAction: 'show',
        }
        : {};
    }
    if (['target-mouseleave', 'element-mouseleave'].includes(context.eventType)) {
      return {
        nextAction: 'hide',
      };
    }
    /* istanbul ignore next */
    return {};
  }
}
