import { Doc } from "yjs";
import { DocAdapter } from "../webrtc/client/doc-adapter.js";
import { Awareness } from "y-protocols/awareness";
import { ObservableYMap } from "./observable-y-map.js";
import { Observable } from "cellx-decorators";
import { IndexeddbPersistence } from "y-indexeddb";
export class SyncStore {
    constructor(name) {
        this.name = name;
        this.doc = new Doc();
        this.adapter = new DocAdapter(this.doc, new Awareness(this.doc));
        this.items = this.doc.getMap('items');
        this.Items = new ObservableYMap(this.items);
        this.IsSynced = false;
    }
    useIndexedDB() {
        const indexeddbProvider = new IndexeddbPersistence(this.name, this.doc);
        indexeddbProvider.whenSynced.then(() => {
            this.Items.subscribe();
            this.IsSynced = true;
        });
    }
}
__decorate([
    Observable,
    __metadata("design:type", Object)
], SyncStore.prototype, "Items", void 0);
__decorate([
    Observable,
    __metadata("design:type", Object)
], SyncStore.prototype, "IsSynced", void 0);
//# sourceMappingURL=sync.store.js.map