# Copyright (c) 2018-2020, NVIDIA CORPORATION.  All rights reserved.
#
# NVIDIA CORPORATION and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto.  Any use, reproduction, disclosure or
# distribution of this software and related documentation without an express
# license agreement from NVIDIA CORPORATION is strictly prohibited.
#
__all__ = ["Icons"]

from .singleton import Singleton
from pathlib import Path
from typing import Union

import omni.kit.app


EXTENSION_FOLDER_PATH = Path(
    omni.kit.app.get_app().get_extension_manager().get_extension_path_by_module(__name__)
)


@Singleton
class Icons:
    """A singleton that scans the icon folder and returns the icon depending on the type"""

    def __init__(self):
        # Read all the svg files in the directory
        self.__icons = {icon.stem: str(icon) for icon in EXTENSION_FOLDER_PATH.joinpath("icons").glob("*.svg")}

    def get(self, prim_type: str, default: Union[str, Path] = None) -> str:
        """Checks the icon cache and returns the icon if exists"""
        found = self.__icons.get(prim_type)
        if not found and default:
            found = self._icons.get(default)

        if found:
            return found

        return ""
