export class CueStateMachine {
    published = new Map();
    pending = new Map();
    active;
    apply(cue) {
        if (this.published.has(cue.cueId))
            return undefined;
        if (cue.state === "ACTIVE_PARTIAL") {
            this.active = cue;
            return cue;
        }
        if (cue.state === "STABLE_SOURCE") {
            if (this.pending.has(cue.cueId))
                return undefined;
            this.active = undefined;
            this.pending.set(cue.cueId, cue);
            return cue;
        }
        if (!cue.translationText)
            return undefined;
        const source = this.pending.get(cue.cueId);
        if (source && cue.revision <= source.revision)
            return undefined;
        this.active = undefined;
        this.pending.delete(cue.cueId);
        this.published.set(cue.cueId, cue);
        return cue;
    }
    stable() { return [...this.published.values()]; }
    pendingCue(cueId) { return this.pending.get(cueId); }
    clearMutable() { this.active = undefined; this.pending.clear(); }
}
