# Path: aisikl/exceptions.py
# class AISParseError(AisiklError):
#     '''We couldn't parse or properly process the response from AIS.
# 
#     This isn't just for syntax errors, but also for unknown or unsupported
#     attribute values, method names and such. The error can either mean:
# 
#     - AIS does something we doesn't support yet, or
#     - AIS changes their formats and our parser needs to be updated, or
#     - the AIS server returned an error with status 200 (should never happen).
#     '''


from aisikl.exceptions import AISParseError

def is_true(value):
    return value == 'true' or value == True


# TODO: Document Component and all subclasses.

class Component:
    def __init__(self, dialog, id, type, parent_id, properties, element):
        self.dialog = dialog
        self.id = id
        self.component_type = type
        self.used_listeners_mask = properties.get('ulm', 0)
        self.enabled = properties.get('e', True)
        self.enabled_in_ui = properties.get('enabledInUI', True)
        self.visible = properties.get('v', True)
        self.visible_in_ui = properties.get('visibleInUI', True)
        self.title = properties.get('title')
        self.popup_menu = properties.get('pm')

        if properties.get('state', 1) == 2:
            raise AISParseError('STATE_DT is not supported')

    def log(self, *args, **kwargs):
        self.dialog.app.ctx.log(*args, **kwargs)

    def is_really_enabled(self):
        return self.enabled and self.enabled_in_ui

    def _ais_setState(self, value):

# Path: aisikl/exceptions.py
# class AISParseError(AisiklError):
#     '''We couldn't parse or properly process the response from AIS.
# 
#     This isn't just for syntax errors, but also for unknown or unsupported
#     attribute values, method names and such. The error can either mean:
# 
#     - AIS does something we doesn't support yet, or
#     - AIS changes their formats and our parser needs to be updated, or
#     - the AIS server returned an error with status 200 (should never happen).
#     '''


# Path: aisikl/components/component.py
from aisikl.exceptions import AISParseError


def is_true(value):
    return value == 'true' or value == True


# TODO: Document Component and all subclasses.

class Component:
    def __init__(self, dialog, id, type, parent_id, properties, element):
        self.dialog = dialog
        self.id = id
        self.component_type = type
        self.used_listeners_mask = properties.get('ulm', 0)
        self.enabled = properties.get('e', True)
        self.enabled_in_ui = properties.get('enabledInUI', True)
        self.visible = properties.get('v', True)
        self.visible_in_ui = properties.get('visibleInUI', True)
        self.title = properties.get('title')
        self.popup_menu = properties.get('pm')

        if properties.get('state', 1) == 2:
            raise AISParseError('STATE_DT is not supported')

    def log(self, *args, **kwargs):
        self.dialog.app.ctx.log(*args, **kwargs)

    def is_really_enabled(self):
        return self.enabled and self.enabled_in_ui

    def _ais_setState(self, value):

        if int(value) == 2: raise AISParseError('STATE_DT is not supported')