class MakeGridCommandInputChangedHandler(adsk.core.InputChangedEventHandler):
    def __init__(self):
        super().__init__()

    def notify(self, args):
        eventArgs = adsk.core.InputChangedEventArgs.cast(args)
        changedInput = eventArgs.input
        inputs = eventArgs.inputs

        partitionedId = changedInput.id.partition("_")
        if partitionedId[-1] == "AddButton":
            partitionedId = changedInput.id.partition("_")
            parentId = partitionedId[0]
            table = inputs.itemById(parentId)
            newRowIndex = table.rowCount
            if parentId == "rowsTable":
                row_number = inputs.addIntegerSpinnerCommandInput(
                    f"row_number_{newRowIndex}", f"Row Number", 1, maxCount, 1, 1
                )
                row_height = inputs.addDistanceValueCommandInput(
                    f"row_height_{newRowIndex}",
                    f"Row {newRowIndex} Height",
                    defultRectSize,
                )
                table.addCommandInput(
                    row_number,
                    newRowIndex,
                    0,
                )
                table.addCommandInput(row_height, newRowIndex, 1)
            elif parentId == "columnsTable":
                column_number = inputs.addIntegerSpinnerCommandInput(
                    f"column_number_{newRowIndex}", f"Column Number", 1, maxCount, 1, 1
                )
                column_width = inputs.addDistanceValueCommandInput(
                    f"column_width_{newRowIndex}",
                    f"Column {newRowIndex} Width",
                    defultRectSize,
                )
                table.addCommandInput(
                    column_number,
                    newRowIndex,
                    0,
                )
                table.addCommandInput(column_width, newRowIndex, 1)
            elif parentId == "rectanglesTable":
                for i in range(4):
                    cord_input = inputs.addIntegerSpinnerCommandInput(
                        f"cord_{i}_{newRowIndex}", f"Cord {i}", 1, maxCount, 1, 1
                    )
                    table.addCommandInput(cord_input, newRowIndex, i)

                pocketOrFill = inputs.addDropDownCommandInput(
                    f"dropList_{newRowIndex}",
                    "filled or pocket",
                    adsk.core.DropDownStyles.LabeledIconDropDownStyle,
                )
                pocketOrFill.listItems.add("pocket", True, "Resources/Icons/pocket")
                pocketOrFill.listItems.add("filled", False, "Resources/Icons/filled")
                table.addCommandInput(pocketOrFill, newRowIndex, 5)

        if changedInput.id == "customSizes":
            customSizes = inputs.itemById("customSizes").value
            rowsTable = inputs.itemById("rowsTable")
            columnsTable = inputs.itemById("columnsTable")
            rowsTable.isVisible = customSizes
            columnsTable.isVisible = customSizes
        elif changedInput.id == "customGrid":
            customGrid = inputs.itemById("customGrid").value
            table = inputs.itemById("rectanglesTable")
            instrucitons = inputs.itemById("Rect_instruct")
            table.isVisible = customGrid
            instrucitons.isVisible = customGrid