<?php

require __DIR__ . '/../autoload.php';

use Lvl0\AnagramFinder\Core\Matcher;
use Lvl0\AnagramFinder\TUI\ArgHandler;
use Lvl0\AnagramFinder\TUI\Output;

use function Laravel\Prompts\text;

const DICTIONARY = __DIR__ . '/../assets/words.txt';

Output::line("ANAGRAM FINDER");

$args = ArgHandler::make($argv);
$anagram = $args->get(1) ?: text("Enter the anagram", required: true);
$minLength = $args->get(2) ?: text(label: "Enter the minimum length of the results. (default=3)", placeholder: 3, default: 3, required: true);
$top10 = $args->hasOption('top');

Output::line();
Output::line("Results for your anagram: " . $anagram);

$matches = Matcher::findWords($anagram, $minLength);
if ($top10) {
    $matches = $matches->slice(0, 10);
}
$matches->each(fn(string $word) => Output::line($word . " (" . strlen($word) . ")"));
