import { createRemoveOldRemoteDrivesConfig } from "@powerhousedao/connect";
import { BrowserStorage, EventQueueManager, InMemoryCache, ReactorBuilder, } from "document-drive";
const DEFAULT_DRIVES_URL = import.meta.env.PH_CONNECT_DEFAULT_DRIVES_URL ||
    undefined;
const defaultDrivesUrl = DEFAULT_DRIVES_URL
    ? DEFAULT_DRIVES_URL.split(",")
    : [];
export const getReactorDefaultDrivesConfig = () => {
    const remoteDrives = defaultDrivesUrl.map((driveUrl) => ({
        url: driveUrl,
        options: {
            sharingType: "PUBLIC",
            availableOffline: true,
            listeners: [
                {
                    block: true,
                    callInfo: {
                        data: driveUrl,
                        name: "switchboard-push",
                        transmitterType: "SwitchboardPush",
                    },
                    filter: {
                        branch: ["main"],
                        documentId: ["*"],
                        documentType: ["*"],
                        scope: ["global"],
                    },
                    label: "Switchboard Sync",
                    listenerId: "1",
                    system: true,
                },
            ],
            triggers: [],
        },
    }));
    return {
        defaultDrives: {
            remoteDrives,
            removeOldRemoteDrives: createRemoveOldRemoteDrivesConfig(defaultDrivesUrl),
        },
    };
};
export function createBrowserStorage(routerBasename) {
    return new BrowserStorage(routerBasename);
}
export function createBrowserDocumentDriveServer(documentModels, storage, options) {
    return new ReactorBuilder(documentModels)
        .withStorage(storage)
        .withCache(new InMemoryCache())
        .withQueueManager(new EventQueueManager())
        .withOptions({
        ...options,
        ...getReactorDefaultDrivesConfig(),
    })
        .build();
}
//# sourceMappingURL=reactor.js.map