use std::{fs, path::Path};

use rand::{seq::SliceRandom, thread_rng};

pub fn load(path: impl AsRef<Path>, width: usize) -> Vec<String> {
	let content = fs::read_to_string(path).expect("Can read file.");
	lines_of(width, &content)
}

pub fn francais(width: usize) -> Vec<String> {
	lines_of(width, include_str!("../data/francais.txt"))
}
pub fn gutenberg(width: usize) -> Vec<String> {
	lines_of(width, include_str!("../data/gutenberg.txt"))
}

pub fn scrable(width: usize) -> Vec<String> {
	lines_of(width, include_str!("../data/scrable.txt"))
}

fn lines_of(width: usize, content: &str) -> Vec<String> {
	let mut res = content
		.lines()
		.filter(|w| w.len() == width)
		.map(|l| l.to_string())
		.collect::<Vec<_>>();
	res.shuffle(&mut thread_rng());
	res
}
