<?php

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

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

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

Output::line("ANAGRAM FINDER");

$args = ArgHandler::make($argv);
$anagram = $args->get(1) ?: readline("Enter the anagram: ");
$minLength = $args->get(2) ?: 3;
$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) . ")"));
