import { Task as t } from "./Task.js";
import { shuffle as s } from "../DatasetBuilder.js";
class a extends t {
  rawConvo;
  shuffledIndices = null;
  index = 0;
  get length() {
    return this.rawConvo.length;
  }
  constructor(n) {
    super(), this.rawConvo = n;
  }
  hasMoreConversations() {
    return this.index < this.rawConvo.length;
  }
  nextConversation() {
    if (this.index >= this.rawConvo.length)
      return null;
    const n = this.rawConvo[this.shuffledIndices ? this.shuffledIndices[this.index] : this.index];
    return this.index++, n;
  }
  nextTokens(n) {
    const e = this.nextConversation();
    return e ? n.encodeConversation(e) : null;
  }
  shuffle() {
    if (!this.shuffledIndices) {
      this.shuffledIndices = new Uint32Array(this.rawConvo.length);
      for (let n = 0; n < this.rawConvo.length; n++)
        this.shuffledIndices[n] = n;
    }
    s(this.shuffledIndices), this.index = 0;
  }
  async estimateTokens(n) {
    return (await n.encodeConversation(this.rawConvo[0])).length * this.length;
  }
}
export {
  a as default
};
