import * as React from "react";
import { IMapView, IExternalBaseLayer, Dictionary, ReduxDispatch, Bounds, GenericEvent, ActiveMapTool, DigitizerCallback, Size2, RefreshMode, ILayerManager, Coordinate2D, IMapViewer, IMapGuideViewerSupport, ILayerInfo, ClientKind, IMapImageExportOptions } from '../../api/common';
import { MouseTrackingTooltip } from '../tooltips/mouse';
import Map from "ol/Map";
import OverviewMap from 'ol/control/OverviewMap';
import DragBox from 'ol/interaction/DragBox';
import Select from 'ol/interaction/Select';
import Draw from 'ol/interaction/Draw';
import { SelectedFeaturesTooltip, ISelectionPopupContentOverrideProvider, SelectionPopupContentRenderer } from '../tooltips/selected-features';
import Feature from 'ol/Feature';
import Polygon from 'ol/geom/Polygon';
import Geometry from 'ol/geom/Geometry';
import View from 'ol/View';
import Point from 'ol/geom/Point';
import LineString from 'ol/geom/LineString';
import Circle from 'ol/geom/Circle';
import type Interaction from 'ol/interaction/Interaction';
import type Overlay from 'ol/Overlay';
import { ProjectionLike } from 'ol/proj';
import { LayerManager } from '../../api/layer-manager';
import type Collection from 'ol/Collection';
import type MapBrowserEvent from 'ol/MapBrowserEvent';
import type { LayerSetGroupBase } from '../../api/layer-set-group-base';
import { Toaster } from '@blueprintjs/core';
import { IOLFactory, OLFactory } from '../../api/ol-factory';
import type { ISubscriberProps } from '../../containers/subscriber';
import type { IInitialExternalLayer } from '../../actions/defs';
import { MapGuideMockMode } from '../mapguide-debug-context';
import LayerBase from 'ol/layer/Base';
import type { LoadFunction as TileLoadFunction } from 'ol/Tile';
import type { LoadFunction as ImageLoadFunction } from 'ol/Image';
import { IBasicPointCircleStyle, IPointIconStyle, IBasicVectorLineStyle, IBasicVectorPolygonStyle } from '../../api/ol-style-contracts';
import { QueryMapFeaturesResponse } from '../../api/contracts/query';
import type { OLFeature, OLLayer } from "../../api/ol-types";
export declare function inflateBoundsByMeters(thisProj: ProjectionLike, extent: Bounds, meters: number): Bounds;
export declare function recursiveFindLayer(layers: Collection<LayerBase>, predicate: (layer: LayerBase) => boolean): LayerBase | undefined;
export declare function isMiddleMouseDownEvent(e: MouseEvent): boolean;
export declare function useViewerSideEffects(context: IMapProviderContext, appSettings: Dictionary<string>, isReady: boolean, mapName: string | undefined, layers: ILayerInfo[] | undefined, initialExternalLayers: IInitialExternalLayer[] | undefined, agentUri?: string | undefined, agentKind?: ClientKind | undefined, selection?: QueryMapFeaturesResponse | null): void;
export interface IViewerComponent {
    /**
     * @since 0.14.8
     */
    isShiftKeyDown: () => boolean;
    isContextMenuOpen: () => boolean;
    setDigitizingType: (digitizingType: string | undefined) => void;
    onDispatch: ReduxDispatch;
    onHideContextMenu: () => void;
    addImageLoading(): void;
    addImageLoaded(): void;
    addSubscribers(props: ISubscriberProps[]): string[];
    removeSubscribers(names: string[]): boolean;
    getSubscribers(): string[];
    selectCanDragPan(): boolean;
}
export interface IMapProviderState {
    activeTool: ActiveMapTool;
    view: IMapView | undefined;
    viewRotation: number;
    viewRotationEnabled: boolean;
    mapName: string | undefined;
    busyWorkers: number;
    locale: string;
    externalBaseLayers: IExternalBaseLayer[] | undefined;
    cancelDigitizationKey: number;
    undoLastPointKey: number;
    overviewMapElementSelector?: () => Element | null;
    initialExternalLayers: IInitialExternalLayer[];
}
export interface IMapProviderStateExtras {
    isReady: boolean;
    bgColor?: string;
    layers: ILayerInfo[] | undefined;
}
/**
 * Defines a mapping provider
 *
 * @since 0.14
 */
export interface IMapProviderContext extends IMapViewer, ISelectionPopupContentOverrideProvider {
    isReady(): boolean;
    getProviderName(): string;
    isDigitizing(): boolean;
    getActiveTool(): ActiveMapTool;
    isMouseOverTooltip(): boolean;
    incrementBusyWorker(): void;
    decrementBusyWorker(): void;
    attachToComponent(el: HTMLElement, comp: IViewerComponent): void;
    detachFromComponent(): void;
    setToasterRef(ref: React.RefObject<Toaster>): void;
    setProviderState(nextState: IMapProviderState): void;
    onKeyDown(e: GenericEvent): void;
    hideAllPopups(): void;
    getHookFunction(): () => IMapProviderState & IMapProviderStateExtras;
    addCustomSelectionPopupRenderer(mapName: string | undefined, layerName: string | undefined, renderer: SelectionPopupContentRenderer): void;
}
export declare type WmsQueryAugmentation = (getFeatureInfoUrl: string) => string;
export declare abstract class BaseMapProviderContext<TState extends IMapProviderState, TLayerSetGroup extends LayerSetGroupBase> implements IMapProviderContext {
    private olFactory;
    private _toasterRef;
    private _baseTileSourceLoaders;
    private _tileSourceLoaders;
    private _imageSourceLoaders;
    private _wmsQueryAugmentations;
    private _globalCustomSelectionPopupRenderer;
    private _customSelectionPopupRenderers;
    protected _state: TState;
    /**
     * Indicates if touch events are supported.
     */
    protected _supportsTouch: boolean;
    /**
     * The internal OpenLayers map instance
     *
     * @private
     * @type {Map}
     */
    protected _map: Map | undefined;
    protected _ovMap: OverviewMap | undefined;
    protected _layerSetGroups: Dictionary<TLayerSetGroup>;
    protected _mouseTooltip: MouseTrackingTooltip | undefined;
    protected _selectTooltip: SelectedFeaturesTooltip | undefined;
    protected _comp: IViewerComponent | undefined;
    protected _zoomSelectBox: DragBox | undefined;
    protected _busyWorkers: number;
    protected _triggerZoomRequestOnMoveEnd: boolean;
    protected _select: Select | undefined;
    protected _activeDrawInteraction: Draw | null;
    constructor(olFactory?: OLFactory);
    /**
     * Exports an image of the current map view
     *
     * @param {IMapImageExportOptions} options
     * @memberof IMapViewer
     * @since 0.14
     */
    exportImage(options: IMapImageExportOptions): void;
    /**
     * Adds a custom tile load function for a given base image tile layer.
     *
     * NOTE: Unlike other load function registrations this must be done before the viewer is mounted. New load functions added at runtime will not be recognized
     * @param mapName
     * @param layerName The base layer this function should apply for
     * @param func The custom tile load function
     * @since 0.14
     */
    addBaseTileLoadFunction(mapName: string, layerName: string, func: TileLoadFunction): void;
    /**
     * Adds a custom tile load function for a given overlay image tile layer
     * @param mapName
     * @param layerName The layer this function should apply for
     * @param func The custom tile load function
     * @since 0.14
     */
    addTileLoadFunction(mapName: string, layerName: string, func: TileLoadFunction): void;
    /**
     * Adds a custom image load function for a given overlay image layer
     * @param mapName
     * @param layerName The layer this function should apply for
     * @param func The custom tile load function
     * @since 0.14
     */
    addImageLoadFunction(mapName: string, layerName: string, func: ImageLoadFunction): void;
    /**
     * Adds a WMS query augmentation for the given WMS overlay layer
     * @param mapName
     * @param layerName The layer this function should apply for
     * @param func The WMS query augmentation
     * @since 0.14
     */
    addWmsQueryAugmentation(mapName: string, layerName: string, func: WmsQueryAugmentation): void;
    addCustomSelectionPopupRenderer(mapName: string | undefined, layerName: string | undefined, renderer: SelectionPopupContentRenderer): void;
    getSelectionPopupRenderer(layerName: string): SelectionPopupContentRenderer | undefined;
    /**
     * @virtual
     */
    hideAllPopups(): void;
    isReady(): boolean;
    /**
     * @virtual
     * @returns {(IMapGuideViewerSupport | undefined)}
     * @memberof BaseMapProviderContext
     */
    mapguideSupport(): IMapGuideViewerSupport | undefined;
    setActiveTool(tool: ActiveMapTool): void;
    getOLFactory(): IOLFactory;
    getMapName(): string;
    setViewRotation(rotation: number): void;
    getViewRotation(): number;
    isViewRotationEnabled(): boolean;
    setViewRotationEnabled(enabled: boolean): void;
    toastSuccess(iconName: string, message: string | JSX.Element): string | undefined;
    toastWarning(iconName: string, message: string | JSX.Element): string | undefined;
    toastError(iconName: string, message: string | JSX.Element): string | undefined;
    toastPrimary(iconName: string, message: string | JSX.Element): string | undefined;
    dismissToast(key: string): void;
    addImageLoading(): void;
    addImageLoaded(): void;
    addSubscribers(props: ISubscriberProps[]): string[];
    removeSubscribers(names: string[]): boolean;
    getSubscribers(): string[];
    dispatch(action: any): void;
    getDefaultPointCircleStyle(): IBasicPointCircleStyle;
    getDefaultPointIconStyle(): IPointIconStyle;
    getDefaultLineStyle(): IBasicVectorLineStyle;
    getDefaultPolygonStyle(): IBasicVectorPolygonStyle;
    abstract getHookFunction(): () => IMapProviderState & IMapProviderStateExtras;
    protected getBaseTileSourceLoaders(mapName: string): Dictionary<TileLoadFunction>;
    protected getTileSourceLoaders(mapName: string): Dictionary<TileLoadFunction>;
    protected getImageSourceLoaders(mapName: string): Dictionary<ImageLoadFunction>;
    protected abstract getInitialProviderState(): Omit<TState, keyof IMapProviderState>;
    protected getMockMode(): MapGuideMockMode | undefined;
    protected addFeatureToHighlight(feat: OLFeature | undefined, bAppend: boolean): void;
    protected getScaleForExtent(bounds: Bounds): number;
    getViewForExtent(extent: Bounds): IMapView;
    protected onZoomSelectBox(e: GenericEvent): void;
    /**
     * @virtual
     * @protected
     * @param {GenericEvent} e
     * @returns
     * @memberof BaseMapProviderContext
     */
    protected onMouseMove(e: GenericEvent): void;
    incrementBusyWorker(): void;
    decrementBusyWorker(): void;
    protected applyView(layerSet: LayerSetGroupBase, vw: IMapView): void;
    protected removeActiveDrawInteraction(): void;
    getActiveTool(): ActiveMapTool;
    cancelDigitization(): void;
    private onBeginDigitization;
    protected pushDrawInteraction<T extends Geometry>(digitizingType: string, draw: Draw, handler: DigitizerCallback<T>, prompt?: string): void;
    /**
     * @virtual
     * @protected
     * @param {Polygon} geom
     * @memberof BaseMapProviderContext
     */
    protected selectFeaturesByExtent(geom: Polygon): void;
    protected zoomByDelta(delta: number): void;
    protected ensureAndGetLayerSetGroup(nextState: TState): TLayerSetGroup;
    getLayerSetGroup(name: string | undefined): TLayerSetGroup | undefined;
    /**
     * @virtual
     * @readonly
     * @memberof BaseMapProviderContext
     */
    isMouseOverTooltip(): boolean;
    protected clearMouseTooltip(): void;
    protected setMouseTooltip(text: string): void;
    protected handleMouseTooltipMouseMove(e: GenericEvent): void;
    private _highlightedFeature;
    private isLayerHoverable;
    protected handleHighlightHover(e: GenericEvent): void;
    protected hideSelectedVectorFeaturesTooltip(): void;
    protected showSelectedVectorFeatures(features: Collection<OLFeature>, pixel: [number, number], featureToLayerMap: [OLFeature, OLLayer][], locale?: string): void;
    protected queryWmsFeatures(mapName: string | undefined, coord: Coordinate2D, bAppendMode: boolean): Promise<boolean>;
    /**
     * @virtual
     * @protected
     * @param {GenericEvent} e
     * @memberof BaseMapProviderContext
     */
    protected onImageError(e: GenericEvent): void;
    private addClientSelectedFeature;
    private clearClientSelectedFeatures;
    protected onMapClick(e: MapBrowserEvent<any>): void;
    protected abstract onProviderMapClick(px: [number, number]): void;
    protected abstract initLayerSet(nextState: TState): TLayerSetGroup;
    abstract getProviderName(): string;
    protected initContext(layerSet: TLayerSetGroup, locale?: string, overviewMapElementSelector?: () => (Element | null)): void;
    /**
     * @virtual
     * @protected
     * @param {TLayerSetGroup} layerSetGroup
     * @memberof BaseMapProviderContext
     */
    protected onBeforeAttachingLayerSetGroup(layerSetGroup: TLayerSetGroup): void;
    setToasterRef(ref: React.RefObject<Toaster>): void;
    abstract setProviderState(nextState: TState): void;
    onKeyDown(e: GenericEvent): void;
    isDigitizing(): boolean;
    detachFromComponent(): void;
    private onMoveEnd;
    private _boundZoomSelectBox;
    private _boundMouseMove;
    private _boundResize;
    private _boundClick;
    private _boundMoveEnd;
    /**
     * @virtual
     * @param {HTMLElement} el
     * @param {IViewerComponent} comp
     * @memberof BaseMapProviderContext
     */
    attachToComponent(el: HTMLElement, comp: IViewerComponent): void;
    private onResize;
    scaleToResolution(scale: number): number;
    resolutionToScale(resolution: number): number;
    getCurrentView(): IMapView;
    getCurrentExtent(): Bounds;
    getSize(): Size2;
    getOLView(): View;
    zoomToView(x: number, y: number, scale: number): void;
    /**
     * @virtual
     * @param {RefreshMode} [mode=RefreshMode.LayersOnly | RefreshMode.SelectionOnly]
     * @memberof BaseMapProviderContext
     */
    refreshMap(mode?: RefreshMode): void;
    getMetersPerUnit(): number;
    initialView(): void;
    zoomDelta(delta: number): void;
    zoomToExtent(extent: Bounds): void;
    digitizePoint(handler: DigitizerCallback<Point>, prompt?: string): void;
    digitizeLine(handler: DigitizerCallback<LineString>, prompt?: string): void;
    digitizeLineString(handler: DigitizerCallback<LineString>, prompt?: string): void;
    digitizeCircle(handler: DigitizerCallback<Circle>, prompt?: string): void;
    digitizeRectangle(handler: DigitizerCallback<Polygon>, prompt?: string): void;
    digitizePolygon(handler: DigitizerCallback<Polygon>, prompt?: string): void;
    addInteraction<T extends Interaction>(interaction: T): T;
    removeInteraction<T extends Interaction>(interaction: T): void;
    addOverlay(overlay: Overlay): void;
    removeOverlay(overlay: Overlay): void;
    getProjection(): ProjectionLike;
    addHandler(eventName: string, handler: Function): void;
    removeHandler(eventName: string, handler: Function): void;
    updateSize(): void;
    protected getLayerManagerForLayerSet(layerSet: TLayerSetGroup): LayerManager;
    getLayerManager(mapName?: string): ILayerManager;
    screenToMapUnits(x: number, y: number): [number, number];
    getSelectedFeatures(): Collection<Feature<Geometry>> | undefined;
    getPointSelectionBox(point: Coordinate2D, ptBuffer: number): Bounds;
    getResolution(): number | undefined;
    updateOverviewMapElement(overviewMapElementSelector: () => (Element | null)): void;
}
