from lnx.logicnode.lnx_nodes import *


class CallWASMNode(LnxLogicTreeNode):
    """Call WASM"""
    bl_idname = 'LNCallWASMNode'
    bl_label = 'Call WASM'
    bl_description = 'Call WASM'
    lnx_category = 'HTML'
    lnx_version = 1
    min_inputs = 3

    property1: HaxeBoolProperty(
        'property1',
        name="Secure",
        description="Assignment",
        default=False,
    )

    def __init__(self):
        super(CallWASMNode, self).__init__()
        array_nodes[str(id(self))] = self
        
    def lnx_init(self, context):
        self.add_input('LnxNodeSocketAction', 'In')
        self.add_input('LnxDynamicSocket', 'WASM')
        self.add_input('LnxStringSocket', 'Call')

        self.add_output('LnxNodeSocketAction', 'Out')
        self.add_output('LnxDynamicSocket', 'Result')

    def draw_buttons(self, context, layout):
        #layout.prop(self, 'property1')
        row = layout.row(align=True)
        op = row.operator('lnx.node_add_input', text='Add Arg', icon='PLUS', emboss=True)
        op.node_index = str(id(self))
        op.socket_type = 'LnxDynamicSocket'
        op.name_format = "Arg {0}"
        op.index_name_offset = -2
        column = row.column(align=True)
        op = column.operator('lnx.node_remove_input', text='', icon='X', emboss=True)
        op.node_index = str(id(self))
        if len(self.inputs) == self.min_inputs:
            column.enabled = False

    def get_replacement_node(self, node_tree: bpy.types.NodeTree):
        if self.lnx_version not in (0, 1):
            raise LookupError()
            
        return NodeReplacement.Identity(self)

def register():
    add_category('HTML', icon='SEQ_STRIP_META')
    CallWASMNode.on_register()