import { PluginFunction, PluginObject } from 'vue';
import VueRouter from 'vue-router';
import { Route } from 'vue-router/types';
import HistoryStack from './classes/HistoryStack';
import { ErrorHandler, RawLocation } from 'vue-router/types/router';

export interface RouterHistoryPluginOptions {
  router: VueRouterWithHistory;
  limit?: number;
}

export interface RouterHistoryPlugin<T> extends PluginObject<T> {
  /**
   * Стек роутов
   */
  history: HistoryStack;
  /**
   * Интеграция в роутер
   */
  install: PluginFunction<T>;
  /**
   * Действие при изменении роута
   */
  onRouteChange(route: Route): void;
}

export interface VueRouterWithHistory extends VueRouter {
  $history: HistoryStack;
}

export type FunctionVoid = (...args: unknown[]) => void;
export type FunctionGo = (n: number) => void;

export interface RouterReplaceFunc {
  (location: RawLocation): Promise<Route>;
  // eslint-disable-next-line @typescript-eslint/ban-types
  (location: RawLocation, onComplete?: Function, onAbort?: ErrorHandler): void;
}
