import bpy


# check collections
def __isCollectionHidden(name, collection, parentIsHidden: bool = False):
    isHidden = collection.hide_viewport or parentIsHidden
    if collection.name == name:
        if isHidden:
            return True
    for child in collection.children:
        if __isCollectionHidden(name, child, isHidden):
            return True
    return False

def objectIsVisibleInViewport(blender_object):
    # if we dont have an object
    if not blender_object:
        return False
    
    # check object visible state
    visible = blender_object.hide_get() == False and blender_object.hide_viewport == False
    if not visible: 
        return False
    
    # viewport display
    display = blender_object.display_type
    if display == "BOUNDS":
        return False
    
    # check collections
    for col in blender_object.users_collection:
        if col.hide_viewport:
            return False
        layerCol = bpy.context.layer_collection
        if layerCol:
            if __isCollectionHidden(col.name, layerCol):
                return False

    return True