-----------------------------------------------------------
-- PATHS PANEL
-----------------------------------------------------------
function editor.definePathsPanel()
	pathsPanel = 
	{ 
		name 			= "Paths",
	 	height 			= 100,
	 	hide 			= true,
	 	open 			= false,
	 	docked  		= true,

	 	mode 			= "paths",
	 	modes 			= pathModes,
	 	loadedObjects 	= false,
	 	slidingSpeed 	= 0,
	 	slidingPos 		= 0,
	 	slidingSmooth 	= 0,
	 	smoothCutoff 	= 0.2,
	 	pointSize 		= 5,
	 	gridFade 			= 0,
	 	row 			= sidebar.row,
	 	y 				= 0,
	 	object 			= {},
	 	paths 			= {},
	 	changed 		= {},
	 	loopTypes 		= {"loop" ,"repeat" ,"reverse"},
	 	loopTypesK 		= {"輪" ,"再" ,"逆"},
	 	wallTypes 		= {"closed" ,"gaps" ,"open"},
	 	wallTypesK 		= {"閉" ,"壁" ,"緩"},
	 	
	 	update 			= function(x) editor.pathsPanelUpdate(x) end
	}
end

function cycleTable(t,n)
	local i,v = lume.find(t,n)
	i = i or 1
	return t[i==#t and 1 or i+1]
end

function editor.openPathsPanel(entity,path,mode)
	if not pathsPanel.open then
		--editor.activateSidebar 	()
	end
	scene.computePath(entity)
	pathsPanel.mode  		= mode or "paths"
	pathsPanel.open 		= true
	pathsPanel.entity  		= entity
	entity[pathsPanel.mode] = entity[pathsPanel.mode] or {}
	pathsPanel.paths  		= entity[pathsPanel.mode]
	pathsPanel.id 				= (entity.uid or entity.key)
	pathsPanel.current 		= path or editor.getDefaultPath(pathsPanel.paths)
	pathsPanel.path 			= pathsPanel.paths[pathsPanel.current]
	pathsPanel.lineHovered  = 0
	game.enterRoom()
	editor.preparePathPoints()
end

function editor.openFloorPanel(entity,path)
	editor.openPathsPanel(entity,path,"floors")
end

function editor.openRampsPanel(entity,path)
	editor.openPathsPanel(entity,path,"ramps")
end

function editor.closePathsPanel()
	editor.deactivateSidebar ()
	editor.clearPathPoints 	 ()
	lume.clear 				 (selectedEntities) 
	pathsPanel.open 		 = false 
	pathsPanel.currentPath 	 = nil
	pathsPanel.id 			 = ""
	pathsPanel.hoveredPath 	 = ""
end

function editor.getDefaultPath(paths)
	local first = ""
	for p,path in pairs(lume.sort(paths,"index")) do
		first = first=="" and path.key or first
		paths[path.key].index=p
	end 
	return first
end

function editor.clearPathPoints()
	for p,point in ipairs(pathsPanel.points or {}) do 
		scene.deleteEntity(point)
	end
	pathsPanel.points 	= lume.clear(pathsPanel.points or {})
end

function editor.preparePathPoints(newPoint)
 	editor.clearPathPoints()
	lume.clear(selectedEntities)	
	local rpoint
	if lume.count(pathsPanel.paths)>0 and pathsPanel.path then
		local index= newPoint and newPoint.i or #pathsPanel.path.points
		for p,point in ipairs(pathsPanel.path.points) do 
			local newPoint = editor.newPathPointEntity(point, pathsPanel.entity, p,pathsPanel.current)
			newPoint.color = pathsPanel.path.color
			table.insert(pathsPanel.points,newPoint)
			scene.updateEntityRenderInfo(newPoint)
			if p == index then 
				rpoint= newPoint
			end
		end
	end
	return rpoint
end

function editor.newPathPointEntity(point,entity,num,path)
	
    local pointEntity       = scene.newEntity({x=entity.x-point.x,y=entity.y-point.y,z=entity.z-point.z,simple=true})

    pointEntity.mode 				= pathsPanel.mode
    pointEntity.uid 				= (entity.uid or entity.key)..num
    pointEntity.pointIndex 	= point.i
    pointEntity.pathID 			= path
    pointEntity.fresh 						= true
    
    if pathsPanel.mode=="ramps" then pointEntity.snapPoint  	= point.snapPoint end

    --table.insert(selectedEntities,pointEntity)	
    return pointEntity
end


function editor.restorePathPanel()
	if pathsPanel.open then 
		--editor.openPathsPanel(scene.getEntityByID(pathsPanel.id),pathsPanel.current)
	end
end

function editor.deletePath(target,path)
	if target[pathsPanel.mode] then 
		target[pathsPanel.mode][path] = nil
	end
	if path == pathsPanel.current then
		editor.setCurrentPath(editor.getDefaultPath(pathsPanel.paths))
	end
end


function editor.deletePathWarning(target,path)
	namer:warning("This path has over 10 points, are you sure you want to delete it",function() 
		editor.deletePath(target,path)
	end)
end

function editor.pathModeSelect(panel)
	for m,mode in ipairs(panel.modes) do
		local check = {
			x 		= panel.x+panel.width-48*#panel.modes+(m-1)*47-panel.row,
			y 		= panel.y,
			width 	= 45,
			height 	= panel.row,
			state 	= panel.mode==mode and "on" or "off",
			text	= mode,
			func 	= function() 
				editor.openPathsPanel( room, nil, mode )
			end
		}
		check.col 		= {r=0,g=0,b=0,a=(mode==panel.mode and 0.5 or 0.05)*(check.hovered and 2 or 1)}
		check.tcol 		= {a=(mode==panel.mode and 1 or 0.5)}

		editor.drawButton(check)
	end
	panel.name=capFirst(panel.mode)
end

function editor.pathsPanelUpdate(panel)
	if keypressed("escape") then
		editor.closePathsPanel()
	end
	
	panel.changed=nil

	if panel.wallCutting then 
		editState = "Cutting"
		trace("")

		panel.cutMouse,panel.cutMouse3D = getPlaneCoords(panel.cutPlane.position,panel.cutPlane.normal,panel.cutPlane.tri)
		mouse.set(function()
			editor.pushUndoState("Start Cut")
			panel.startCut = panel.cutMouse
			table.insert(panel.cutPath.cuts,{})
			panel.cutNum = #panel.cutPath.cuts
			panel.cutting = true 
		end)
		mouse.pushRelease(function() 
			panel.cutting=false 
			panel.changed = {panel.cutTarget[1],panel.cutTarget[2]}
		end)
		if panel.cutting then 
			panel.changed = {panel.cutTarget[1],panel.cutTarget[2]}
			panel.cutPath.cuts[panel.cutNum].index  = panel.cutPoint

			if panel.cutStyle == "rect" then 
				panel.cutPath.cuts[panel.cutNum].style  = "rect"
				panel.cutPath.cuts[panel.cutNum].bounds = {math.min(panel.cutMouse.x,panel.startCut.x),math.max(panel.cutMouse.x,panel.startCut.x)}
				panel.cutPath.cuts[panel.cutNum].shape  = {	
					math.min(panel.cutMouse.x,panel.startCut.x), math.min(panel.cutMouse.y,panel.startCut.y),
					math.max(panel.cutMouse.x,panel.startCut.x), math.min(panel.cutMouse.y,panel.startCut.y),
					math.max(panel.cutMouse.x,panel.startCut.x), math.max(panel.cutMouse.y,panel.startCut.y),
					math.min(panel.cutMouse.x,panel.startCut.x), math.max(panel.cutMouse.y,panel.startCut.y)
				}
			elseif panel.cutStyle=="circ" then 
				panel.cutPath.cuts[panel.cutNum].style  = "circ"
				local dist = math.dist(panel.startCut.x,panel.startCut.y,panel.cutMouse.x,panel.cutMouse.y)
				local segs = 16--mc(8,mf(0.02*pi*dist^2),64)

				panel.cutPath.cuts[panel.cutNum].bounds = {panel.startCut.x-dist,panel.startCut.x+dist}
				panel.cutPath.cuts[panel.cutNum].shape  = {}
				for i=1,segs,1 do 
					table.insert(panel.cutPath.cuts[panel.cutNum].shape, panel.startCut.x + math.sin((i/segs)*pi*2) * dist )
					table.insert(panel.cutPath.cuts[panel.cutNum].shape, panel.startCut.y + math.cos((i/segs)*pi*2) * dist )
				end 
			end
			trace("cutRect",inspect(panel.cutPath.cuts[panel.cutNum].shape))
		end
		if panel.startCut then trace("panel.startCut",panel.startCut) end
		trace("panel.cutMouse",panel.cutMouse )
		trace("panel.cutMouse3D",panel.cutMouse3D )
		trace("")
		panel.gridFade = easeTo(panel.gridFade,0.5,8,4)
	else 
		panel.gridFade = easeTo(panel.gridFade,0,8,4)
	end

	panel.hide=not panel.open
	editor.togglePanel(panel,true,editor.closePathsPanel)

	panel.height 	= sidebar.titleH+2

	panel.preview 	= false
	if panel.mode then 
		panel.modeName  = capFirst(panel.mode):sub(1,-2)
	else 
		return 
	end

	if not ( 
		panel.open 
	 	and panel.entity 
	 	and panel.entity[panel.mode][panel.current] 
	 	and pathsPanel.points) then  
	 	return  
	end

	panel.preview 	= true
	editor.pathModeSelect(panel)

	if lume.count(panel.entity[panel.mode][panel.current].points)~=lume.count(pathsPanel.points) then 
		editor.openPathsPanel(room,pathsPanel.current,pathsPanel.mode)
	end

	--if mouse.click() then panel.snapPoint = nil end
		

	if lume.count(panel.entity[panel.mode])>0 then
		panel.path = panel.paths[panel.current]

		if #panel.points == 0 or #panel.path.points==0 then 
			panel.paths[panel.current]=nil
			editor.closePathsPanel()
			return
		end

		for i=#panel.points,1,-1 do 
			if not panel.points[i].x then
				print("rEMOVE poinTEYTY") 
				table.remove(panel.points,i)
			end
		end

		if #panel.points~= #panel.path.points then 
			for i,point in ipairs(panel.points) do
				local cPoint = point.position
				panel.path.points[i].x = -cPoint.x 
				panel.path.points[i].y = -cPoint.y 
				panel.path.points[i].z = -cPoint.z 
			end
			while(#panel.path.points>#panel.points) do 
				table.remove(panel.path.points,#panel.path.points)
				print("rEMOVE pathPoint") 
			end
		end

		for i,point in lume.ripairs(panel.points) do 
			local prev = lume.clone(panel.path.points[i])
			local cPoint = point.selected and not vec3.is_zero(point.nextPosition) and point.nextPosition or point

			panel.path.points[i].x = -cPoint.x 
			panel.path.points[i].y = -cPoint.y 
			panel.path.points[i].z = -cPoint.z 
			panel.path.points[i].id = panel.path.points[i].id or uuid()


			if panel.mode=="ramps" then 
				if point.fresh then
					if point.snapPoint then--and panel.mode=="ramps" then 
						--point.x = -point.snapPoint.x
						--point.y = -point.snapPoint.y
						--point.z = -point.snapPoint.z 
					end
				elseif point.selected then
					if selectedEntities[1]==point and #selectedEntities==1 then 

						local usedSnap = false 
						if     i == 1  and panel.snapPoint==panel.points[#panel.points].snapPoint then 
							usedSnap = true 
						elseif   panel.snapPoint==panel.points[1].snapPoint then 
							usedSnap = true 
						end

						if multiTool.dragging and mouse.moved   then 
							point.snapPoint = panel.snapPoint 
							panel.path.points[i].snapPoint = panel.snapPoint 
							trace("ZNAPPP")
						end

						panel.snapPoint = nil

						if  mouse.release() then 
							if point.snapPoint then 
								point.x = point.snapPoint.x
								point.y = point.snapPoint.y
								point.z = point.snapPoint.z
							end
						end

					end
				elseif point.snapPoint  then 
					--trace("HOIII2",vec3.dist(point,panel.path.points[i].snapPoint))
					--trace(vec3(point),-vec3(point.snapPoint))
					--trace("HOIII3",vec3.dist(point,-vec3(point.snapPoint)))
					--if vec3.dist(point,-vec3(point.snapPoint))>0 then 
						--point.snapPoint = nil
					--end
					
					--panel.path.points[i].snapPoint = nil
				end
				
			else 
				panel.snapPoint =nil
				point.snapPoint=nil
				panel.path.points[i].snapPoint=nil
			end
			panel.path.points[i].snapPoint = point.snapPoint or nil
			point.fresh=false

			local changedPoint = panel.path.points[i]

			panel.path.points[i].moved = (point.selected and multiTool.dragging and mouse.moved)

			if   ((not prev.snapPoint and (prev.x~=changedPoint.x or prev.y~=changedPoint.y or prev.z~=changedPoint.z))  or  prev.snapPoint~=changedPoint.snapPoint) then
				panel.changed={panel.mode,panel.current}
			end

			point.pointIndex 		= i
			local nextPoint = panel.points[i+1] and i+1 or 1

			if panel.points[nextPoint] and panel.lineHovered==i and hoveredEntity==nil and not editor.editingCode and not keyDown("space") then 
				mouse.set(function()
					editor.updateEntityTransform(
						editor.startDrag(
							editor.newPathPoint(
								lume.merge( 
									panel.newPointPosition,
									{id==uuid(), walled = panel.path.points[i].walled, i=nextPoint}
								),false,true
							)
						),true
					)
				end)

				if panel.mode == "floors" then
					mouse.setR(function()
						panel.path.points[i].walled = not panel.path.points[i].walled
					end)
				end
			end


		end

		trace("panel.lineHovered",panel.lineHovered)
		
		panel.hoveredPath = nil
	end

end

function editor.togglePath(path)
	local path = path or pathsPanel.path
	path.enabled = not path.enabled 
end

function editor.renamePath(path)
	namer:typeString("Path Name",path.name,{x=mouse.x,y=mouse.y},function(x) path.name = x end)
end

function editor.movePathToRoom()
	local panel 		= pathsPanel
	room[pathsPanel.mode][panel.current] 	= deepcopy(panel.path)
	for p,point in ipairs(room[pathsPanel.mode][panel.current].points) do 
		point.x=point.x+panel.entity.x
		point.y=point.y+panel.entity.y
		point.z=point.z+panel.entity.z
	end
	panel.paths[panel.current] = nil
	editor.openPathsPanel(room,panel.current)
end

function editor.dropNewPathPoint()
	local panel 		= pathsPanel
	if keypressed("n") and panel.open then 
		lume.clear(selectedEntities)
		
		if lume.count(panel.entity[pathsPanel.mode])==0 then 
			editor.newPath(panel)
		else
			editor.newPathPoint({
				x=mouseLocalDrop.x-panel.entity.x,
				y=mouseLocalDrop.y-panel.entity.y,
				z=mouseLocalDrop.z-panel.entity.z,
				i=#panel.path.points+1
			})
		end
	end
end

function editor.newPath(panel,base,i)
	local offset  			= editor.intersect
	local angle
	
	if panel.mode == "floors" then
		editor.newPathPoint 	({ x = offset.x-250 , y = offset.y , z = offset.z 		, walled = true , i=1},true)
		editor.newPathPoint 	({ x = offset.x+250 , y = offset.y , z = offset.z 		, walled = true , i=2})
		editor.newPathPoint 	({ x = offset.x+250 , y = offset.y , z = offset.z+500 	, walled = true , i=3})
		editor.newPathPoint 	({ x = offset.x-250 , y = offset.y , z = offset.z+500 	, walled = true , i=4})
	else
		if base and base.points then 
			local p1 = base.points[i]
			local p2 = base.points[i==#base.points and 1 or i+1]
			local p3 = vec3((p1.x+p2.x)/2,(p1.y+p2.y)/2,(p1.z+p2.z)/2)
			local snapPoint = {
				x = p3.x,
				y = p3.y,
				z = p3.z,
				id 	= p1.id,
				floor 	= base.key
			}

			editor.newPathPoint 	({ x = p3.x 	, y = p3.y , z = p3.z 		, i=1 ,snapPoint=snapPoint},{width=vec3.dist(p1,p2)/2})
			angle  								= math.angle(p1.x,p1.z, p2.x,p2.z)-pi/2
			editor.newPathPoint 	({ x = p3.x + math.cos(angle)*80, y = p3.y -50 , z = p3.z + math.sin(angle)*80 ,i=2})

		else
			editor.newPathPoint 	({ x = offset.x 	, y = offset.y , z = offset.z 		, i=1 },true)
			angle  		= love.math.random( -pi, pi )
			editor.newPathPoint 	({ x = offset.x + math.sin(angle)*100, y = offset.y + math.cos(angle)*100, z = offset.z + 0,i=2})
		end
	end
end

function editor.setCurrentPath(k)
	pathsPanel.current 	= k or ""
	pathsPanel.path 	= k and lume.randomchoice(pathsPanel.paths) or pathsPanel.paths[k]
	editor.preparePathPoints()
end

function editor.newPathPoint(newPoint,newPath,insert)
	local panel 		= pathsPanel
	local newPoint 		= newPoint or 
		(panel.paths[panel.current] and lume.merge(lume.clone(panel.paths[panel.current].points[#panel.path.points]),{i=#panel.path.points+1}) or {})

	newPoint.id=uuid()

	if newPath then 
		for p,path in ipairs(lume.sort(panel.paths,"index")) do
			panel.paths[path.key].index=p
		end 
		local newID = uuid()
		local r,g,b 	= hsvToRgb(math.random(), 0.45, 0.7,1)
		panel.paths[newID]= { 	
			enabled =	true, 	
			speed 	=	0,	
			startPos=	0,	
			normPos =	0,	
			smoothing= 	0,
			thicknessEnabled=true,
			mode = panel.mode,
			width 	= 	panel.mode=="ramps" and 50 or nil,
			loop 	=	"repeat",
			walled 	=	"gaps",	
			stepsEnabled  = true,
			name 	= 	"Untitled "..lume.count(panel.paths),
			key 	= 	newID,
			color 	= 	{r=r,g=g,b=b,a=1},
			points 	=	{lume.merge(newPoint,pathsPanel.entity.isEntity and { x = 0, y = 0, z = 0, i=1} or {i=1})},
			index 	= 	lume.count(panel.paths)+1
		}
		if type(newPath)=="table" then 
			for k,v in pairs(panel.paths[newID]) do 
				if newPath[k] then 
					panel.paths[newID][k] = newPath[k] 
				end
			end
		end
		panel.current 	= newID
		panel.path 		= panel.paths[panel.current]
		pathsPanel.changed = {panel.mode,panel.current}
		scene.time=-1
	else
		if insert then 
			newPoint.i=newPoint.i+1
		end
		table.insert(panel.path.points,newPoint.i,newPoint) 	
	end
	return editor.preparePathPoints(newPoint)
end


function editor.contextPaths(room,mode)
	pathItems = {}
	for p,path in pairs(room[mode] or {}) do 
		local hover =  function()
			pathsPanel.preview 		= true
			pathsPanel.id 			= room.key
			pathsPanel.hoveredPath  = p
			pathsPanel.mode 		= mode
		end
		table.insert(pathItems,{
			{	
				name = "×", align="center",size=1, col = {r=0.8,g=0.2,b=0.2,a=0.4}, 
				warning="open",
				hover= hover,
				func = function() 
					editor.deletePath(room,path.key)
					return "remove"
				end 
			},
			{	
				name = "", 	
				align="left",
				size=(mode=="floors") and 6 or 3, 
				col = {r=path.color.r+0.2,g=path.color.g+0.2,b=path.color.b+0.2,a=0.1},
				func = function() 
					editor.openPathsPanel( room, p, mode )
				end ,
				hover= hover,
				update 	= function(x)
					x.name = room[mode][p].name
					x.tcol = (path.enabled==false) and {a=150} or nil
				end
			},
			(mode=="ramps" or mode=="paths") and {	
				size=3,
				align="center",
				hover= hover,
				col = {r=0.4,g=0.4,b=0.4,a=0.1},
				name=(mode=="ramps") and "width" or "speed", 		
				update=function()
					pathsPanel.changed={pathsPanel.mode,pathsPanel.current}
				end,
				slider={target=path,  style="pct", prop=(mode=="ramps") and "width" or "speed", min=(mode=="ramps") and 10 or 0, max=(mode=="ramps") and 110 or 1,	round=0.01,noval=true}
			} or 1,
			{	
				name = "", align="center",size=1,button=true, col = {r=0,g=0,b=0,a=0.6},
				hover= hover,
				col  = {r=0.5,g=0.7,b=0.6,a=0.2},
				func = function() 
					if pathsPanel.mode=="paths" then 
						path.loop=cycleTable(pathsPanel.loopTypes,path.loop) 
					else
						path.walled=cycleTable(pathsPanel.wallTypes,path.walled) 
					end 
					return "toggle"
				end,
				update 	= function(x)
					x.text = mode=="paths" and "-l"..tostring(lume.find(pathsPanel.loopTypes,path.loop)) or "-w"..tostring(lume.find(pathsPanel.wallTypes,path.walled))
				end
			},
			{	
				name = "···", align="center",size=-1,col = {r=0,g=0,b=0,a=0.6},
				hover= hover,
				func = function() 
					namer:typeString(
						mode:sub(1,-2).." name", 
						room[mode][p].name, 
						getMouse(), 
						function(x) 
							room[mode][p].name = x
						end
					)
					return "rename"
				end
			},
			{	
				name = "", align="center",size=1, col = {r=0,g=0,b=0,a=0.6},
				hover= hover,
				func = function() 
					path.enabled=not path.enabled
					return "toggle"
				end,
				update 	= function(x)
					x.text = path.enabled and "ticked" or "unticked"
				end
			}
		})
	end
	table.insert(pathItems, {name="New "..capFirst(mode):sub(1,-2), col = {r=0.2,g=0.6,b=0.3,a=0.4}, func=function()
		editor.openPathsPanel(room,nil,mode)
		editor.newPath(pathsPanel)
	end})
	return pathItems
end

function editor.contextBuild(room)
	return {	name="Build", align="left",subWidth=200  ,items = lume.concat({{
		{	name="Paths", 		func = function() 	editor.openPathsPanel( room ) end , subitems=editor.contextPaths(room,"paths") 	, align="center"},
		{	name="Ramps", 		func = function() 	editor.openRampsPanel( room ) end , subitems=editor.contextPaths(room,"ramps") 	, align="center"},
		{	name="Floors", 		func = function() 	editor.openFloorPanel( room ) end , subitems=editor.contextPaths(room,"floors") , align="center"}
	}})}
end

function editor.isCurrentPath(path)
	return (pathsPanel.mode == path.mode and pathsPanel.current == path.id)
end

function editor.contextPath(room,mode,id)
	local path = room[mode][id]

	local toggleMode = function() 
		if pathsPanel.mode=="paths" then 
			path.loop=cycleTable(pathsPanel.loopTypes,path.loop) 
		else
			path.walled=cycleTable(pathsPanel.wallTypes,path.walled) 
		end 
		return "toggle"
	end
	local props = {
		ramps = {
			{name="width",min=10,max=110},
			{name="smooth",min=0,max=1,toggle=true},
			{name="steps",min=0,max=1,toggle=true},
			{name="stepHeight",min=0,max=1},
			{name="wall",min=0,max=1,toggle=true},
			{name="thickness",min=0,max=1,toggle=true},
			{name="roof",toggle=true},
		},
		floors= {
			{name="wall",min=0,max=1,toggle=true},
			{name="smooth",min=0,max=1,toggle=true},
			{name="railing",min=0,max=1,toggle=true},
			{name="grass",min=0,max=1,toggle=true},
			{name="thickness",min=0,max=1,toggle=true},
			{name="roof",toggle=true},
		},
		paths = {
			{name="speed",min=0,max=1},
			{name="smooth",min=0,max=1,toggle=true},
			{name="wall",min=0,max=1,toggle=true},
		}
	}
	pathItems = {}

	local rename = function() 
		namer:typeString(
			mode:sub(1,-2).." name", 
			path.name, 
			getMouse(), 
			function(x) 
				path.name = x
			end
		)
		return "rename"
	end

	table.insert(pathItems,{
		{	
		name = "", align="center", col = {r=0.8,g=0.2,b=0.2,a=0.4}, 
		warning="open",
		hover= hover,
		align="left",
		size=-1,
		func = function() 
			editor.deletePath(room,path.key)
			editor.closePathsPanel()
		end ,
		update = function()
			if mouse.time<2 or (mouse.down.L and mouse.moved) then 
				pathsPanel.changed={editor.clickedModel.mode,editor.clickedModel.id} 
			end
		end
	},
		{	
			name = "", 	
			align="left",
			size=7, 
			col = {r=path.color.r+0.2,g=path.color.g+0.2,b=path.color.b+0.2,a=0.1},
			func = rename ,
			hover= hover,
			update 	= function(x)
				x.name = path.name
				x.tcol = (path.enabled==false) and {a=150} or nil
			end
		},
		{	
			name = "···", align="center",size=-1,col = {r=0,g=0,b=0,a=0.6},
			hover= hover,
			func = rename
		},
		editor.makeToggle(path,"enabled")[2]
	})

	
	table.insert(pathItems,{
		{	
			name = "Edge Mode", align="center",size=8,button=true, col = {r=0,g=0,b=0,a=0.6},
			hover= hover,
			align="left",
			col  = {r=0.5,g=0.7,b=0.6,a=0.2},
			func = toggleMode,
			update 	= function(x)
				x.text = mode=="paths" and "Loop mode: "..path.loop or "Edge mode: "..path.walled
			end
		},{	
			name = "Edge Mode", align="center",size=-1,button=true, col = {r=0,g=0,b=0,a=0.6},
			hover= hover,
			col  = {r=0.5,g=0.7,b=0.6,a=0.2},
			func=toggleMode,
			update 	= function(x)
				x.text = mode=="paths" and "-l"..tostring(lume.find(pathsPanel.loopTypes,path.loop)) or "-w"..tostring(lume.find(pathsPanel.wallTypes,path.walled))
			end
		}
	})
	

	-- fix colors for ramps

		if mode~="paths" then 
			table.insert(pathItems,editor.makeToggle(path.roof,"enabled",{name="roof",colors={"inner","outer"}}))
			table.insert(pathItems,editor.makeToggle(path.floor,"enabled",{name="floor",colors={"inner","outer"}}))
		end

		table.insert(pathItems,editor.makeToggle(path.wall,{"height","enabled","wall"} ,{colors={"inner","outer"},min=1,max=500},
				{
					editor.makeToggle(path.railing,{"count","enabled","railing"},empty,{
						editor.makeSlider(path.railing,"width",{name="width",min=0,max=8,round=1}),
						editor.makeSlider(path.railing.rails,{"count","enabled","mid rails"},{min=0,max=8,round=1},{
							editor.makeSlider(path.railing.rails,"width",{name="width",min=0,max=8,round=1}),
						})
					}),
					editor.makeToggle(path.cornice,{"style","enabled","cornice"}),
				}
			)
		)

		table.insert(pathItems,editor.makeSlider(path,"thickness",{min=1,max=30}))

		if mode=="ramps" then
			table.insert(pathItems,editor.makeToggle(path,"gradient"))
			table.insert(pathItems,editor.makeSlider(path,"width",{min=20,max=100}))
			table.insert(pathItems,editor.makeSlider(path.steps,{"height","enabled","steps"}))
		end



	--table.insert(pathItems, {name="New "..capFirst(mode):sub(1,-2), col = {r=0.2,g=0.6,b=0.3,a=0.4}, func=function()
	--	editor.openPathsPanel(room,p,mode)
	--	editor.newPath(pathsPanel)
	--end})

	return pathItems
end