import React, { createElement } from "react";
import { Command } from "@oclif/core";
import { render } from "ink";
import { sharedFlags } from "../command-helpers.mjs";
import { WatchApp } from "../tui/watch-app.mjs";

export default class WatchCommand extends Command {
  static summary = "Open an interactive viewer for the latest run artifact";

  static flags = sharedFlags;

  async run() {
    const { flags } = await this.parse(WatchCommand);
    const productDir = flags.dir || process.cwd();
    const app = render(
      createElement(WatchApp, {
        productDir,
        serviceFilter: flags.service || null,
      })
    );
    await app.waitUntilExit();
  }
}
