import omni.ui as ui
from omni.kit.window.preferences import PreferenceBuilder, SettingType
from .. import _resourceMonitor


class ResourceMonitorPreferences(PreferenceBuilder):
    def __init__(self):
        super().__init__("Resource Monitor")

    def build(self):
        """ Resource Monitor """
        with ui.VStack(height=0):
            with self.add_frame("Resource Monitor"):
                with ui.VStack():
                    self.create_setting_widget(
                        "Time Between Queries",
                        _resourceMonitor.timeBetweenQueriesSettingName,
                        SettingType.FLOAT,
                    )
                    self.create_setting_widget(
                        "Send Device Memory Warnings",
                        _resourceMonitor.sendDeviceMemoryWarningSettingName,
                        SettingType.BOOL,
                    )
                    self.create_setting_widget(
                        "Device Memory Warning Threshold (MB)",
                        _resourceMonitor.deviceMemoryWarnMBSettingName,
                        SettingType.INT,
                    )
                    self.create_setting_widget(
                        "Device Memory Warning Threshold (Fraction)",
                        _resourceMonitor.deviceMemoryWarnFractionSettingName,
                        SettingType.FLOAT,
                        range_from=0.,
                        range_to=1.,
                    )
                    self.create_setting_widget(
                        "Send Host Memory Warnings",
                        _resourceMonitor.sendHostMemoryWarningSettingName,
                        SettingType.BOOL
                    )
                    self.create_setting_widget(
                        "Host Memory Warning Threshold (MB)",
                        _resourceMonitor.hostMemoryWarnMBSettingName,
                        SettingType.INT,
                    )
                    self.create_setting_widget(
                        "Host Memory Warning Threshold (Fraction)",
                        _resourceMonitor.hostMemoryWarnFractionSettingName,
                        SettingType.FLOAT,
                        range_from=0.,
                        range_to=1.,
                    )
