import { flags } from "@oclif/command"
import BaseCommand from "../utils/BaseCommand"
 
import Console from "../utils/console"

import {
  extractParagraphs,
  splitIntoSyllables,
  extractWords,
  countSentences,
  fleschKincaidGrade,
} from "../utils/creatorUtilities"

const exampleMd = `# How to Install Node.js

Node.js lets you run JavaScript outside a web browser.

## Step 1: Download Node.js

Get the Node.js installer from the [official site](https://nodejs.org/en/download/).

## Step 2: Install Node.js

Open the installer and follow the steps to finish.

## Step 3: Verify the Installation

Open a terminal and type:

\`\`\`bash
node -v
\`\`\`
`

class BreakTokenCommand extends BaseCommand {
  static description = "Break the token"

  static flags = {
    ...BaseCommand.flags,
    grading: flags.help({ char: "h" }),
  }

  async run() {
    const { flags } = this.parse(BreakTokenCommand)

    // await SessionManager.breakToken()
    const paragraphs = extractParagraphs(exampleMd)
    for (const paragraph of paragraphs) {
      const syllables = splitIntoSyllables(paragraph)
      const words = extractWords(paragraph)
      const sentences = countSentences(paragraph)
      const fkgl = fleschKincaidGrade(paragraph)
      Console.info(paragraph)
      Console.info(`Number of syllables: ${syllables.length}`)
      Console.info(syllables)
      Console.info(`Number of words: ${words.length}`)
      Console.info(words)
      Console.info(`Number of sentences: ${sentences}`)
      Console.info(`FKGL: ${fkgl}`)
      Console.info("---")
    }

    process.exit(0)
  }
}

export default BreakTokenCommand
