from .utils_icons import getPreviewIcon
from .component_watcher import startFileWatcher, stopFileWatchers
from .utils import getWebProjectPath
from .blender_materials import createMaterialWithTexture
import bpy

class ExperimentalPanel(bpy.types.Panel):
    """Creates a Panel in the Object properties window"""
    bl_idname = "OBJECT_PT_NEEDLE_experimental"
    bl_label = "Needle Experimental"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "scene"
    # bl_category = "Name of your tab"

    material = bpy.props.PointerProperty(type=bpy.types.Material)

    @classmethod
    def poll(self, context):
        return False

    def draw_header(self, context):
        layout = self.layout
        icon = getPreviewIcon("logo_small_bw")
        layout.label(text="", icon_value=icon)

    def draw(self, context):
        layout = self.layout
        el = layout.column(align=True)
        el.label(text="These are experimental actions, don't use unless you were told to", icon="ERROR")
        el.operator("scene.set_environment", text="Set env", icon="ADD")
        el.operator("scene.needle_regenerate_component_panels", text="Regenerate component panels")
        el.operator("needle.print_web_project_path")
        el.operator("needle.start_file_watcher_op")
        el.operator("needle.stop_file_watcher_op")
        el.operator("needle.stop_server")
        el.operator("needle.open_log")
        el.operator("needle.link_meshes")
        # el.operator("scene.testprogressmodal")
        # el.operator("needle.bake_lightmaps")
        
        # material = bpy.data.materials[0]
        # settings =  material.my_settings
        # draw_op = getattr(settings, "draw", None)
        # if callable(draw_op):
        #     draw_op(context, layout)
        # else:
        #     layout.prop(material, "my_settings", text="Settings")
        

class printWebProjectPathOp(bpy.types.Operator):
    bl_idname = 'needle.print_web_project_path'
    bl_label = 'Print web project path'
    bl_options = {"REGISTER"}

    def execute(self, context):
        path = getWebProjectPath()
        print(path)
        if path is not None:
            self.report({'INFO'}, path)
        else:
            self.report({'ERROR'}, "Web project path not found")
        return {"FINISHED"} 


class startWatcherOp(bpy.types.Operator):
    bl_idname = 'needle.start_file_watcher_op'
    bl_label = 'Start File Watcher'
    bl_options = {"REGISTER"}

    def execute(self, context):
        startFileWatcher()
        return {"FINISHED"} 
    
class stopWatcherOp(bpy.types.Operator):
    bl_idname = 'needle.stop_file_watcher_op'
    bl_label = 'Stop File Watcher'
    bl_options = {"REGISTER"}

    def execute(self, context):
        stopFileWatchers()
        return {"FINISHED"} 

# class runCommandOp(bpy.types.Operator):
#     bl_idname = 'needle.test_make_progressive_op'
#     bl_label = 'Test Command'
#     bl_options = {"REGISTER"}

#     def execute(self, context):
#         makeProgressive(getWebProjectPath(), "scene.glb")
#         return {"FINISHED"} 

# def register():
#     bpy.utils.register_class(printWebProjectPathOp)

# def unregister():
#     bpy.utils.unregister_class(printWebProjectPathOp)



