/**
 * Copyright 2023 Impulse Innovations Limited
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
import { EventEmitter } from 'eventemitter3';
import type { DefaultTheme } from '@darajs/styled-components';
import type { NotificationPayload } from '@darajs/ui-notifications';
import type { GraphLayout } from '../graph-layout';
import type { DragMode } from '../use-drag-mode';
import type { EdgeConstraint, SimulationEdge, SimulationGraph, ZoomThresholds } from '../../types';
import { EditorMode } from '../../types';
import type { PixiEdgeStyle } from './edge';
export interface EngineEvents {
    backgroundClick: () => void;
    createEdge: (event: PIXI.FederatedMouseEvent, source: string, target: string) => void;
    dragEnd: () => void;
    dragStart: () => void;
    edgeClick: (event: PIXI.FederatedMouseEvent, source: string, target: string) => void;
    edgeMouseout: (event: PIXI.FederatedMouseEvent, edgeKey: string) => void;
    edgeMouseover: (event: PIXI.FederatedMouseEvent, edgeKey: string) => void;
    nodeClick: (event: PIXI.FederatedMouseEvent, nodeKey: string) => void;
    nodeMouseout: (event: PIXI.FederatedMouseEvent, nodeKey: string) => void;
    nodeMouseover: (event: PIXI.FederatedMouseEvent, nodeKey: string) => void;
    groupMouseout: (event: PIXI.FederatedMouseEvent, groupKey: string) => void;
    groupMouseover: (event: PIXI.FederatedMouseEvent, groupKey: string) => void;
    layoutComputationStart: () => void;
    layoutComputationEnd: () => void;
}
export declare const ENGINE_EVENTS: Array<keyof EngineEvents>;
export declare class Engine extends EventEmitter<EngineEvents> {
    /** App instance */
    private app;
    /** Background object */
    private background;
    /** Available edge constraints */
    private constraints;
    /** Parent container where canvas is rendered in */
    private container;
    /** Running layout worker instance */
    private layoutWorker;
    /** Debounced version of `this.updateLayout` in case multiple changes come in at the same time */
    debouncedUpdateLayout: import("lodash").DebouncedFunc<(retry?: boolean) => Promise<void>>;
    /** Current drag mode */
    private dragMode;
    /** Container storing edge graphics */
    private edgeLayer;
    /** Edge ID -> EdgeObject cache */
    private edgeMap;
    /** Container storing edge symbol graphics */
    private edgeSymbolsLayer;
    /** Whether the graph is editable */
    private editable;
    /** Current editor mode */
    private editorMode;
    /** Graph state */
    private graph;
    /** Whether engine has been started */
    initialized: boolean;
    /** Whether there is an edge being created */
    private isCreatingEdge;
    /** Whether a node is being moved */
    private isMovingNode;
    /** Graph layout instance */
    private layout?;
    /** Which edge the user is holding down mouse button on */
    private mousedownEdgeKey;
    /** Which node the user is holding down mouse button on */
    private mousedownNodeKey;
    /** Container storing node label graphics */
    private nodeLabelLayer;
    /** Container storing node graphics */
    private nodeLayer;
    /** Node ID -> NodeObject cache */
    private nodeMap;
    /** Center position of the node user pressed mousedown on, stored while user is holding down mouse1 */
    private nodeMousedownCenterPosition;
    /** Last mousedown event position stored while user is holding down mouse1 */
    private nodeMousedownPosition;
    /** Callback executed when a node is added */
    private onAddNode?;
    /** Callback executed when an edge is added */
    private onAddEdge?;
    /** Callback executed when engine is being destroyed */
    private onCleanup?;
    /** Container storing group container graphics */
    private groupContainerLayer;
    /** Group ID -> GroupContainerObject cache */
    private groupContainerMap;
    /** Group ID -> simulation edge array */
    private collapsedEdgesMap;
    private onGraphAttributesUpdatedBound;
    private onGraphNodeAddedBound;
    private onGraphEdgeAddedBound;
    private onGraphEdgeDroppedBound;
    private onGraphNodeDroppedBound;
    private onGraphEdgeAttributesUpdatedBound;
    private onGraphNodeAttributesUpdatedBound;
    private onDocumentMouseMoveBound;
    private onDocumentMouseUpBound;
    private onLayoutComputationStartedBound;
    private onLayoutComputationDoneBound;
    /** Callback executed when a drag motion is done */
    private onEndDrag?;
    /** Callback executed when a node is being moved */
    private onMove?;
    /** Callback executed when a drag motion is started */
    private onStartDrag?;
    /** Callback for raising error from a layout build into the Graph component */
    private errorHandler?;
    /** Callback executed when an edge needs style change */
    private processEdgeStyle?;
    /** Last render request ID - used to skip extra render calls */
    private renderRequestId;
    /** Whether the styles are dirty and need to be updated in the animation frame */
    private isStyleDirty;
    /** ResizeObserver instance watching window resizes */
    private resizeObserver;
    /** Current node search results */
    private searchResults;
    /** Currently selected edge. We keep track of it here so we can unselect it when need be */
    private selectedEdge;
    /** Currently selected node. We keep track of it here so we can unselect it when need be */
    private selectedNode;
    /** Current range of edge strength values provided in meta attributes */
    private strengthRange;
    /** Texture cache instance */
    private textureCache;
    /** Current theme */
    private theme;
    /** Graph UID */
    private uid;
    /** Viewport instance */
    private viewport;
    /** Optional user-provided zoom thresholds */
    private zoomThresholds?;
    /** whether zoom on scroll should be enabled only when the graph is focused */
    private requireFocusToZoom;
    /** Whether the graph is currently focused */
    private isFocused;
    constructor(graph: SimulationGraph, layout: GraphLayout, editable: boolean, editorMode: EditorMode, theme: DefaultTheme, constraints?: EdgeConstraint[], zoomThresholds?: ZoomThresholds, errorHandler?: (error: NotificationPayload) => void, processEdgeStyle?: (edge: PixiEdgeStyle, attributes: SimulationEdge) => PixiEdgeStyle, requireFocusToZoom?: boolean);
    /**
     * Get the center position of the rendered viewport
     */
    getCenterPosition(): PIXI.PointData;
    /**
     * Cleanup the app appropriately
     */
    destroy(): void;
    /**
     * Mark styles to update them in the next animation frame
     */
    markStylesDirty(): void;
    /**
     * Request the graph to be re-rendered
     */
    requestRender(): void;
    /**
     * Reset the viewport to fit the graph centered on screen
     */
    resetViewport(): void;
    /**
     * Collapse all groups present in the graph
     */
    collapseAllGroups(): void;
    /**
     * Expand all groups present in the graph
     */
    expandAllGroups(): void;
    /**
     * Update matched status based on new search result
     *
     * @param ids ids found in search result
     */
    searchNodes(ids: string[]): void;
    /**
     * Select an edge with given id
     *
     * @param id id of the edge
     */
    selectEdge(path: [string, string]): void;
    /**
     * Select a node with given id
     *
     * @param id id of the node
     */
    selectNode(id: string): void;
    /**
     * Update drag mode
     *
     * @param dragMode drag mode to set
     */
    setDragMode(dragMode: DragMode): void;
    /**
     * Update theme used
     *
     * @param theme theme used
     */
    setTheme(theme: DefaultTheme): void;
    /**
     * Start the rendering engine
     *
     * @param container container to start in - canvas will be injected into it
     */
    start(container: HTMLElement): Promise<void>;
    /**
     * Notify the engine about focus change on the graph canvas
     *
     * This is used to enable/disable behaviour depending on focus state, e.g. zoom on wheel
     *
     * @param isFocused - focus state
     */
    setFocus(isFocused: boolean): void;
    /**
     * Toggle zoom-on-wheel behaviour
     *
     * @param isEnabled - whether to enable or disable wheel zoom
     */
    toggleWheelZoom(isEnabled: boolean): void;
    /**
     * Wheel listener which disables the default browser scrolling behaviour
     *
     * @param event - mouse wheel event
     */
    private static wheelListener;
    /**
     * Extract current visible canvas state to an image
     */
    extractImage(): Promise<string>;
    /**
     * Update the set of constraints
     *
     * @param constraints new constraints
     */
    updateConstraints(constraints: EdgeConstraint[]): void;
    /**
     * Create an edge
     *
     * @param id edge id
     * @param attributes  edge attributes
     * @param source source node id
     * @param target target node i
     * @param sourceAttributes source node attributes
     * @param targetAttributes target node attributes
     */
    private createEdge;
    /**
     * Create the graph.
     *
     * Creates edges and nodes based on current graph state.
     */
    private createGraph;
    /**
     * Create a node
     *
     * @param id node id
     * @param attributes node attributes
     */
    private createNode;
    /**
     * Create a group container
     *
     * @param id node id
     * @param nodes a list of simulation nodes that are part of the group
     */
    private createGroupContainer;
    /**
     * Creates all group containers
     */
    private createGroupContainers;
    /**
     * Drop the edge graphics from the renderer
     *
     * @param id edge id
     */
    private dropEdge;
    /**
     * Drop the node graphics from the renderer
     *
     * @param id node id
     */
    private dropNode;
    /**
     * Drop the group container graphics from the renderer
     *
     * @param id node id
     */
    private dropGroupContainer;
    /**
     * Enables drag behaviour
     *
     * Pauses viewport dragging and installs listeners for mouse movement
     */
    private enableDragBehaviour;
    /**
     * Get constraint for given edge
     *
     * @param source edge source
     * @param target edge target
     */
    private getConstraint;
    /**
     * Get style object to determine edge behaviour
     *
     * @param edge edge object to get styles for
     * @param attributes edge attributes
     * @param constraint optional attached constraint, used in edge encoder mode
     */
    private getEdgeStyle;
    /**
     * Get style object to determine node behaviour
     *
     * @param node node object to get styles for
     * @param attributes node attributes
     */
    private getNodeStyle;
    /**
     * Enable hover state for given edge
     *
     * @param id id of edge to hover
     */
    private hoverEdge;
    /**
     * Enable hover state for given node
     *
     * @param id id of node to hover
     */
    private hoverNode;
    /**
     * Move given node to target position
     *
     * @param nodeKey id of node to move
     * @param point target position
     */
    private moveNode;
    /**
     * Callback invoked when layout worker has finished computing layout
     */
    private onLayoutComputationDone;
    /**
     * Callback invoked when a request is sent to the layout worker
     */
    private onLayoutComputationStart;
    /**
     * Move handler - drag behaviour
     *
     * @param event mouse event
     */
    private onDocumentMouseMove;
    /**
     * On mouse up, stop drag - reset stored mousedown keys and remove moving listener
     */
    private onDocumentMouseUp;
    private onGraphAttributesUpdated;
    private onGraphNodeAdded;
    private onGraphEdgeAdded;
    private onGraphEdgeDropped;
    private onGraphNodeDropped;
    private onGraphEdgeAttributesUpdated;
    private onGraphNodeAttributesUpdated;
    /**
     * Apply a given layout to the graph
     *
     * @param layout layout to apply
     */
    private setLayout;
    /**
     * Get relative strength definition based on all edge thickness provided
     *
     * @param attributes edge attributes
     */
    private getRelativeStrength;
    /**
     * Disable hover state for given edge
     *
     * @param id id of edge to unhover
     */
    private unhoverEdge;
    /**
     * Disable hover state for given node
     *
     * @param id id of node to unhover
     */
    private unhoverNode;
    /**
     * Update edge style
     *
     * @param id id of edge to update
     * @param attributes edge attributes
     * @param source source node ID
     * @param target target node ID
     * @param sourceNodeAttributes source node attributes
     * @param targetNodeAttributes target node attributes
     */
    private updateEdgeStyle;
    /**
     * Update style for given edge
     *
     * @param edgeKey id of edge to update
     */
    private updateEdgeStyleByKey;
    /**
     * Update visibility of graph parts.
     *
     * Applies culling to hide off-screen graphics, updates LOD based on zoom level
     */
    private updateGraphVisibility;
    /**
     * Recompute the layout and apply it
     */
    private updateLayout;
    /**
     * Update style of given node
     *
     * @param id id of node to update
     * @param attributes node attributes
     */
    private updateNodeStyle;
    /**
     * Update style of given group container
     *
     * @param id id of group to update
     * @param nodes array of nodes that are part of the group
     */
    private updateGroupContainerStyle;
    /**
     * Update style for given node
     *
     * @param nodeKey id of node to update
     */
    private updateNodeStyleByKey;
    /**
     * Recalculate current strength range based on thickness properties
     */
    private updateStrengthRange;
    /**
     * Update the visuals of each node, edge and group containers
     */
    private updateStyles;
}
//# sourceMappingURL=engine.d.ts.map