from pathlib import Path
import re


def nearest_img_files(files, fmt='png'):
    """Get a list of file paths to closest images (type as specified) in dataset """
    def file_png2svg(x):
        p = Path(x)
        n = p.name
        n = re.sub(r"\.png", ".svg", n)
        p = p.parent.parent
        p = p / 'transformed_svgs' / n
        return str(p)

    def file_png2gif(x):
        p = Path(x)
        n = p.name
        n = re.sub(r"-\d+\.png", ".gif", n)
        p = p.parent.parent
        p = p / 'icons' / 'icon_gif' / n
        return str(p)

    if fmt == 'png':
        pass
    elif fmt == 'svg':
        files = list(map(lambda x: file_png2svg(x), files))
    elif fmt == 'gif':
        files = list(map(lambda x: file_png2gif(x), files))

    return files