import { EventEmitter } from "events";
class AnalyticsPanel extends EventEmitter {
  line;
  // contrib.line type
  currentMetric = "tokens";
  data = null;
  constructor(line) {
    super();
    this.line = line;
    this.initializeUI();
  }
  initializeUI() {
    this.line.screen.key(["m"], () => {
      this.cycleMetric();
    });
    this.showTokenUsage();
  }
  cycleMetric() {
    const metrics = [
      "tokens",
      "velocity",
      "quality",
      "performance"
    ];
    const currentIndex = metrics.indexOf(this.currentMetric);
    this.currentMetric = metrics[(currentIndex + 1) % metrics.length];
    switch (this.currentMetric) {
      case "tokens":
        this.showTokenUsage();
        break;
      case "velocity":
        this.showVelocity();
        break;
      case "quality":
        this.showQuality();
        break;
      case "performance":
        this.showPerformance();
        break;
    }
  }
  showTokenUsage() {
    if (!this.data) return;
    const data = [
      {
        title: "Token Usage",
        x: this.data.tokens.labels.map((_, i) => i.toString()),
        y: this.data.tokens.values,
        style: { line: "yellow" }
      }
    ];
    this.line.setData(data);
    if (typeof this.line.setLabel === "function") {
      this.line.setLabel(" \u{1F4C8} Analytics - Token Usage [m] cycle ");
    }
    this.line.screen.render();
  }
  showVelocity() {
    if (!this.data) return;
    const data = [
      {
        title: "Task Velocity",
        x: this.data.tasks.velocity.map((_, i) => `Sprint ${i + 1}`),
        y: this.data.tasks.velocity,
        style: { line: "green" }
      }
    ];
    this.line.setData(data);
    if (typeof this.line.setLabel === "function") {
      this.line.setLabel(" \u{1F4C8} Analytics - Task Velocity [m] cycle ");
    }
    this.line.screen.render();
  }
  showQuality() {
    if (!this.data) return;
    const data = [
      {
        title: "Tests Passed",
        x: ["1", "2", "3", "4", "5"],
        y: [
          this.data.quality.testsPassed,
          this.data.quality.testsPassed,
          this.data.quality.testsPassed,
          this.data.quality.testsPassed,
          this.data.quality.testsPassed
        ],
        style: { line: "green" }
      },
      {
        title: "Coverage %",
        x: ["1", "2", "3", "4", "5"],
        y: [
          this.data.quality.coverage,
          this.data.quality.coverage,
          this.data.quality.coverage,
          this.data.quality.coverage,
          this.data.quality.coverage
        ],
        style: { line: "blue" }
      }
    ];
    this.line.setData(data);
    if (typeof this.line.setLabel === "function") {
      this.line.setLabel(" \u{1F4C8} Analytics - Code Quality [m] cycle ");
    }
    this.line.screen.render();
  }
  showPerformance() {
    if (!this.data) return;
    const data = [
      {
        title: "Response Time (ms)",
        x: this.data.performance.avgResponseTime.map((_, i) => i.toString()),
        y: this.data.performance.avgResponseTime,
        style: { line: "cyan" }
      },
      {
        title: "Error Rate (%)",
        x: this.data.performance.errorRate.map((_, i) => i.toString()),
        y: this.data.performance.errorRate.map((r) => r * 100),
        style: { line: "red" }
      }
    ];
    this.line.setData(data);
    if (typeof this.line.setLabel === "function") {
      this.line.setLabel(" \u{1F4C8} Analytics - Performance [m] cycle ");
    }
    this.line.screen.render();
  }
  update(data) {
    this.data = data;
    switch (this.currentMetric) {
      case "tokens":
        this.showTokenUsage();
        break;
      case "velocity":
        this.showVelocity();
        break;
      case "quality":
        this.showQuality();
        break;
      case "performance":
        this.showPerformance();
        break;
    }
  }
  focus() {
    this.emit("focused");
  }
  hasFocus() {
    return false;
  }
}
export {
  AnalyticsPanel
};
//# sourceMappingURL=analytics-panel.js.map
