import { assertExists, noop } from '@blockeditor/global/utils';
import { CanvasElementType, } from '../../../../surface-block/index.js';
import { EdgelessToolController } from './index.js';
export class ConnectorToolController extends EdgelessToolController {
    constructor() {
        super(...arguments);
        this.tool = {
            type: 'connector',
        };
        this._connector = null;
        this._source = null;
        this._startPoint = null;
    }
    onContainerClick() {
        noop();
    }
    onContainerContextMenu() {
        noop();
    }
    onContainerDblClick() {
        noop();
    }
    onContainerTripleClick() {
        noop();
    }
    onContainerPointerDown(e) {
        this._startPoint = this._surface.viewport.toModelCoord(e.x, e.y);
        this._source = this._surface.connector.searchConnection(this._startPoint);
    }
    onContainerDragStart() {
        assertExists(this._source);
        assertExists(this._startPoint);
        this._page.captureSync();
        const { mode } = this.tool;
        const { _surface } = this;
        const id = _surface.addElement(CanvasElementType.CONNECTOR, {
            mode,
            controllers: [],
            source: this._source,
            target: { position: this._startPoint },
        });
        this._connector = _surface.pickById(id);
    }
    onContainerDragMove(e) {
        assertExists(this._connector);
        const { connector, viewport } = this._surface;
        const point = viewport.toModelCoord(e.x, e.y);
        const target = connector.searchConnection(point, this._connector.source.id ? [this._connector.source.id] : []);
        this._surface.updateElement(this._connector.id, { target });
    }
    onContainerDragEnd() {
        assertExists(this._connector);
        this._surface.connector.clear();
        this._page.captureSync();
        this._edgeless.tools.switchToDefaultMode({
            elements: [this._connector.id],
            editing: false,
        });
        this._connector = null;
    }
    onContainerMouseMove(e) {
        const { connector, viewport } = this._surface;
        const point = viewport.toModelCoord(e.x, e.y);
        connector.searchConnection(point);
    }
    onContainerMouseOut() {
        noop();
    }
    onPressShiftKey(_) {
        noop();
    }
    beforeModeSwitch() {
        noop();
    }
    afterModeSwitch() {
        this._surface.connector.clear();
    }
}
//# sourceMappingURL=connector-tool.js.map