from typing import List
from typing import Tuple


def text_batch_splitter(strings: List[str], max_length: int) -> Tuple[List[str], List[Tuple[int, int]]]:
	"""
	Takes a list of strings and split the ones of them that are longer than a specified length, growing the list
	where splitting is needed. Split information can then be used to merge the output information back after use.
	Cuts happen at whitespaces.
	:param strings: list of input strings of any length
	:param max_length: maximum length after which a string must be split into smaller ones
	:return new list of strings of size <= max_length, with long strings splitted in consecutive indices
	:return split information: indices of split strings, with number of consecutive elements involved (pass to merger later)
	"""
	new_strings = []
	split_information = []

	for full_str in strings:
		if len(full_str) <= max_length:
			new_strings.append(full_str)
		else:
			# Splitting the text in sequences the model can accept
			words = full_str.split()
			n_seqs = len(full_str) // max_length + 1
			seqs = []
			wi = 0
			for i in range(n_seqs):
				current = ""
				while wi < len(words) and len(current) + len(words[wi]) < len(full_str) / n_seqs:
					current += words[wi] + " "
					wi += 1
				seqs.append(current[:-1])

			split_information.append((len(new_strings), len(seqs)))
			new_strings += seqs

	return new_strings, split_information