// Copyright 2026 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import { AnnotationHostDef } from './annotation_types.js';
export function glicBrowserHostAnnotationMixin(base) {
    return class extends base {
        annotationSender;
        annotationReceiver;
        mainClientRemote;
        initializeAnnotation(initialState, router, clientRemote) {
            if (!initialState.enableScrollTo) {
                this.scrollTo = undefined;
                this.dropScrollToHighlight = undefined;
                return;
            }
            const { remote, receiver } = router.newPipeWithRemote(AnnotationHostDef);
            this.annotationSender = remote;
            this.annotationReceiver = receiver;
            this.mainClientRemote = clientRemote;
        }
        async scrollTo(params) {
            this.ensureAnnotationHandlerCreated();
            return this.annotationSender.requestWithResponse('scrollTo', { params });
        }
        dropScrollToHighlight() {
            this.ensureAnnotationHandlerCreated();
            this.annotationSender.requestNoResponse('dropScrollToHighlight', undefined);
        }
        ensureAnnotationHandlerCreated() {
            if (this.annotationReceiver === undefined) {
                return;
            }
            this.mainClientRemote.requestNoResponse('createAnnotationHandler', {
                annotationReceiver: this.annotationReceiver,
            });
            this.annotationReceiver = undefined;
        }
    };
}
