local panel

local function openFloors(entity, path)
	paths_openPanel(entity, path, "floors")
end

local function openRamps(entity, path)
	paths_openPanel(entity, path, "ramps")
end

local function 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

local function clearPoints()
	for p, point in ipairs(panel.points or {}) do
		scene_deleteEntity(point)
	end
	panel.points = lume.clear(panel.points or {})
end

local function newPointEntity(point, entity, num, path)
	local pointEntity = scene_newEntity(panel.room, { x = point.x, y = point.y, z = point.z, simple = true })

	pointEntity.mode = panel.mode
	pointEntity.uid = (entity.uid or entity.key) .. num
	pointEntity.pointIndex = point.i
	pointEntity.pathID = path
	pointEntity.fresh = true

	if panel.mode == "ramps" then
		pointEntity.snapPoint = point.snapPoint
	end

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

local function preparePoints(newPoint)
	clearPoints()
	lume.clear(editor.selectedEntities)
	local rpoint
	if lume.count(panel.paths) > 0 and panel.path then
		local index = newPoint and newPoint.i or #panel.path.points
		for p, point in ipairs(panel.path.points) do
			local newPoint = newPointEntity(point, panel.entity, p, panel.current)
			newPoint.color = panel.path.color
			table.insert(panel.points, newPoint)
			scene_updateEntityRenderInfo(newPoint)
			if p == index then
				rpoint = newPoint
			end
		end
	end
	return rpoint
end

local function setCurrentPath(k)
	panel.current = k or ""
	panel.path = k and lume.randomchoice(panel.paths) or panel.paths[k]
	preparePoints()
end

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

local function deletePathWarning(target, path)
	namer_warning("This path has over 10 points, are you sure you want to delete it", function()
		deletePath(target, path)
	end)
end

local function selectMode()
	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()
				paths_openPanel(panel.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_queueButton(check)
	end
	panel.name = capFirst(panel.mode)
end

local function updatePaths()
	if input_keyPressed("escape") then
		paths_closePanel()
	end

	if panel.changed then
		if panel.changed[3] then
			panel.changed = nil
		else
			panel.changed[3] = true
		end
	end

	if panel.wallCutting then
		editor.state = "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.visible = panel.open
	editor_togglePanel(panel, true, paths_closePanel)

	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 panel.points) then
		return
	end

	panel.preview = true
  
	-- selectMode()

	if lume.count(panel.entity[panel.mode][panel.current].points) ~= lume.count(panel.points) then
		paths_openPanel(panel.room, panel.current, panel.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
			paths_closePanel()
			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 ppoint = panel.path.points[i]
			local prev = lume.clone(ppoint)
			local cPoint = point.selected and not vec3.is_zero(point.nextPosition) and point.nextPosition or point
			ppoint.x = cPoint.x
			ppoint.y = cPoint.y
			ppoint.z = cPoint.z
			ppoint.id = ppoint.id or uuid()

			if panel.mode == "ramps" then
				if point.fresh then
					if point.snapPoint then
						--point.x = -point.snapPoint.x
						--point.y = -point.snapPoint.y
						--point.z = -point.snapPoint.z
					end
				elseif point.selected then
					if editor.selectedEntities[1] == point and #editor.selectedEntities == 1 then
						trace("ZELECTED")
						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

						trace("ZNAPPP", editor.gizmo.dragging, mouse.moved, panel.snapPoint)
						if editor.gizmo.dragging and mouse.moved then
							point.snapPoint = panel.snapPoint
							ppoint.snapPoint = panel.snapPoint
						end

						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

						panel.snapPoint = nil
					end
				elseif point.snapPoint then
					--trace("HOIII2",vec3.dist(point,ppoint.snapPoint))
					trace("snappoints")
					trace(vec3(point))
					trace(-vec3(point.snapPoint))
					trace("dist", vec3.dist(point, -vec3(point.snapPoint)))
					if vec3.dist(point, -vec3(point.snapPoint)) > 0 then
						-- point.snapPoint = nil
					end

					--ppoint.snapPoint = nil
				end
			else
				panel.snapPoint = nil
				point.snapPoint = nil
				ppoint.snapPoint = nil
			end
			ppoint.snapPoint = point.snapPoint or nil
			point.fresh = false

			local changedPoint = ppoint

			ppoint.moved = (point.selected and editor.gizmo.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 editor.hoveredEntity == nil
				and not editor.coding
				and not input_keyDown("space")
			then
				mouse_set(function()
					editor_updateEntityTransform(
						editor_startDrag(
							paths_newPathPoint(
								lume.merge(
									panel.newPointPosition,
									{ id == uuid(), walled = ppoint.walled, i = nextPoint }
								),
								false,
								true
							)
						),
						true
					)
				end)

				if panel.mode == "floors" then
					mouse_setR(function()
						ppoint.walled = not ppoint.walled
					end)
				end
			end
		end

		trace("panel.lineHovered", panel.lineHovered)

		panel.hoveredPath = nil
	end
end

local function renamePath(path)
	namer_typeString("Path Name", path.name, { x = mouse.x, y = mouse.y }, function(x)
		path.name = x
	end)
end

local function contextPaths(room, mode)
	local pathItems = {}
	for p, path in pairs(room[mode] or {}) do
		local hover = function()
			panel.preview = true
			panel.id = room.key
			panel.hoveredPath = p
			panel.mode = mode
		end
		table.insert(pathItems, {
			{
				name = "-x",
				align = "center",
				size = 1,
				col = { r = 0.8, g = 0.2, b = 0.2, a = 0.4 },
				warning = "open",
				hover = hover,
				func = function()
					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()
					paths_openPanel(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()
					panel.changed = { panel.mode, panel.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 panel.mode == "paths" then
						path.loop = cycleTable(panel.loopTypes, path.loop)
					else
						path.walled = cycleTable(panel.wallTypes, path.walled)
					end
					return "toggle"
				end,
				update = function(x)
					x.text = mode == "paths" and "-l" .. tostring(lume.find(panel.loopTypes, path.loop))
						or "-w" .. tostring(lume.find(panel.wallTypes, path.walled))
				end,
			},
			{
				name = "-rename",
				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, mouse_getCoords(), 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()
			paths_openPanel(room, nil, mode)
			paths_newPath()
		end,
	})
	return pathItems
end

function paths_setPanel(p)
	panel = p
end

function paths_openPanel(entity, path, mode, room)
	if not panel.open then
		--editor_activateSidebar 	()
	end
	scene_computePath(entity)
	panel.mode = mode or "paths"
	panel.open = true
	panel.entity = entity
	panel.room = room or panel.room
	entity[panel.mode] = entity[panel.mode] or {}
	panel.paths = entity[panel.mode]
	panel.id = (entity.uid or entity.key)
	panel.current = path or getDefaultPath(panel.paths)
	panel.path = panel.paths[panel.current]
	panel.lineHovered = 0
	game_enterRoom()
	preparePoints()
end

function paths_closePanel()
	editor_deactivateSidebar()
	clearPoints()
	lume.clear(editor.selectedEntities)
	panel.open = false
	panel.currentPath = nil
	panel.id = ""
	panel.hoveredPath = ""
end

function paths_restorePathPanel()
	if panel.open then
		--paths_openPanel(scene_getEntityByID(panel.id),panel.current)
	end
end

function paths_dropNewPathPoint()
	if input_keyPressed("n") and panel.open then
		lume.clear(editor.selectedEntities)

		if lume.count(panel.entity[panel.mode]) == 0 then
			paths_newPath()
		else
			paths_newPathPoint({
				x = editor.mouseLocalDrop.x - panel.entity.x,
				y = editor.mouseLocalDrop.y - panel.entity.y,
				z = editor.mouseLocalDrop.z - panel.entity.z,
				i = #panel.path.points + 1,
			})
		end
	end
end

function paths_newPath(base, i)
	local offset = editor.intersect
	local angle

	if panel.mode == "floors" then
		paths_newPathPoint({ x = offset.x - 250, y = offset.y, z = offset.z, walled = true, i = 1 }, true)
		paths_newPathPoint({ x = offset.x + 250, y = offset.y, z = offset.z, walled = true, i = 2 })
		paths_newPathPoint({ x = offset.x + 250, y = offset.y, z = offset.z + 500, walled = true, i = 3 })
		paths_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,
			}

			paths_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
			paths_newPathPoint({ x = p3.x + math.cos(angle) * 80, y = p3.y - 50, z = p3.z + math.sin(angle) * 80, i = 2 })
		else
			paths_newPathPoint({ x = offset.x, y = offset.y, z = offset.z, i = 1 }, true)
			angle = math.random() * 2 * pi - pi
			paths_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 paths_newPathPoint(newPoint, newPath, insert)
	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, panel.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]
		panel.changed = { panel.mode, panel.current }
		game.time = -1
	else
		if insert then
			newPoint.i = newPoint.i + 1
		end
		table.insert(panel.path.points, newPoint.i, newPoint)
	end
	return preparePoints(newPoint)
end

function paths_contextBuild(room)
	return {
		name = "Build",
		align = "left",
		subWidth = 200,
		items = lume.concat({
			{
				{
					name = "Paths",
					func = function()
						paths_openPanel(room)
					end,
					subitems = contextPaths(room, "paths"),
					align = "center",
				},
				{
					name = "Ramps",
					func = function()
						openRamps(room)
					end,
					subitems = contextPaths(room, "ramps"),
					align = "center",
				},
				{
					name = "Floors",
					func = function()
						openFloors(room)
					end,
					subitems = contextPaths(room, "floors"),
					align = "center",
				},
			},
		}),
	}
end

function paths_isCurrentPath(path)
	return (panel.mode == path.mode and panel.current == path.id)
end

function paths_contextPath(room, mode, id)
	print("room", mode, id, lume.count(room[mode]), room[mode][id])
	for k, v in pairs(room[mode]) do
		print(k, v)
	end
	-- print(inspect(room[mode]))

	local path = room[mode][id]

	if not path then
		editor_tempTip("Invalid Path")
		error("INVALID PATH")
		return
	end

	local toggleMode = function()
		if panel.mode == "paths" then
			path.loop = cycleTable(panel.loopTypes, path.loop)
		else
			path.walled = cycleTable(panel.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, mouse_getCoords(), function(x)
			path.name = x
		end)
		return "rename"
	end

	table.insert(pathItems, {
		{
			name = "-x",
			align = "center",
			col = { r = 0.8, g = 0.2, b = 0.2, a = 0.4 },
			warning = "open",
			hover = hover,
      box=true,
			align = "left",
			size = -1,
			func = function()
				deletePath(room, path.key)
				paths_closePanel()
			end,
			update = function()
				if mouse.time < 2 or (mouse.down.L and mouse.moved) then
					panel.changed = { editor.clickedModel.mode, editor.clickedModel.id }
				end
			end,
		},
		{
			name = path.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 },
      targ=path,
      prop="name",
			editable=true,
			hover = hover,
			update = function(x)
				x.name = path.name
				x.tcol = (path.enabled == false) and { a = 150 } or nil
			end,
		},
		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(panel.loopTypes, path.loop))
					or "-w" .. tostring(lume.find(panel.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()
	--	paths_openPanel(room,p,mode)
	--	paths_newPath(panel)
	--end})

	return pathItems
end

function paths_definePanel()
	return
{
		name = "Paths",
		height = 100,
		hide = true,
		open = false,
		docked = true,
		width = 100,

		mode = "paths",
		modes = { "paths", "ramps", "floors" },
		loadedObjects = false,
		slidingSpeed = 0,
		slidingPos = 0,
		slidingSmooth = 0,
		smoothCutoff = 0.2,
		pointSize = 5,
		gridFade = 0,
		row = config.row,
		y = 0,
		object = {},
		paths = {},
		changed = {},
		loopTypes = { "loop", "repeat", "reverse" },
		loopTypesK = { "輪", "再", "逆" },
		wallTypes = { "closed", "gaps", "open" },
		wallTypesK = { "閉", "壁", "緩" },

		update = updatePaths,
	}
end
