from typing import Dict
from typing import List
from typing import Tuple


def map_intermediate_to_input(
    input_line_mapping: Dict[str, List], line_number: int
) -> Tuple[str, int]:
    """Map intermediate file lines to notebooke cell and line.

    Maps the line at `line_number` to the corresponding code cell
    (`input_cell_name`) and line number in the code cell
    (`input_cell_line_number`)

    Parameters
    ----------
    input_line_mapping : Dict[str, List]
        Dict containing lists of input cell names and their line in the
        intermediate file.
    line_number : int
        Line in the intermediate py file.

    Returns
    -------
    Tuple[str, int]
        Input cell name and corresponding line in that cell
        (input_cell_name, input_cell_line_number)

    See Also
    --------
    create_intermediate_py_file
    """
    line_filter = filter(
        lambda code_line: code_line < line_number, input_line_mapping["code_lines"]
    )
    entry_index = len(list(line_filter)) - 1
    input_cell_name = input_line_mapping["input_names"][entry_index]
    code_starting_line_number = input_line_mapping["code_lines"][entry_index] + 2
    input_cell_line_number = code_starting_line_number - line_number
    return input_cell_name, abs(input_cell_line_number)