export class PeerUiState {
    connectionState = "idle";
    connectionMessage;
    draft = "";
    isCancelling = false;
    isCrdtResyncing = false;
    listeners = new Set();
    subscribe(listener) {
        this.listeners.add(listener);
        return () => {
            this.listeners.delete(listener);
        };
    }
    setConnectionState(connectionState) {
        this.connectionState = connectionState;
        this.connectionMessage = undefined;
        this.emit();
    }
    setConnectionStatus(status) {
        this.connectionState = status.state;
        this.connectionMessage = status.message;
        this.emit();
    }
    setDraft(draft) {
        this.draft = draft;
    }
    setCancelling(isCancelling) {
        if (this.isCancelling === isCancelling) {
            return;
        }
        this.isCancelling = isCancelling;
        this.emit();
    }
    setCrdtResyncing(isCrdtResyncing) {
        if (this.isCrdtResyncing === isCrdtResyncing) {
            return;
        }
        this.isCrdtResyncing = isCrdtResyncing;
        this.emit();
    }
    getSnapshot() {
        return {
            connectionState: this.connectionState,
            connectionMessage: this.connectionMessage,
            draft: this.draft,
            isCancelling: this.isCancelling,
            isCrdtResyncing: this.isCrdtResyncing,
        };
    }
    emit() {
        const snapshot = this.getSnapshot();
        for (const listener of this.listeners) {
            listener(snapshot);
        }
    }
}
//# sourceMappingURL=peer-ui-state.js.map