/**
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *
 * @flow strict
 */

import type {ProviderAwareness} from '@lexical/yjs';
import type {Doc, RelativePosition} from 'yjs';

export interface Provider {
  connect(): void | Promise<void>;
  disconnect(): void;
  awareness: ProviderAwareness;
  on(type: 'sync', cb: (isSynced: boolean) => void): void;
  on(type: 'status', cb: ({status: string}) => void): void;
  // $FlowFixMe: temp
  on(type: 'update', cb: (any) => void): void;
  on(type: 'reload', cb: (doc: Doc) => void): void;
  off(type: 'sync', cb: (isSynced: boolean) => void): void;
  // $FlowFixMe: temp
  off(type: 'update', cb: (any) => void): void;
  off(type: 'status', cb: ({status: string}) => void): void;
  off(type: 'reload', cb: (doc: Doc) => void): void;
}

export type ProviderFactory = (
  id: string,
  yjsDocMap: Map<string, Doc>,
) => Provider;

declare export function CollaborationPlugin(arg0: {
  id: string,
  cursorsContainerRef?: {current: HTMLElement | null},
  providerFactory: ProviderFactory,
  shouldBootstrap: boolean,
  username?: string,
}): React$Node;
