local M do M={}local O=1 local y=O local function K(K,e,d,P,h)local o=false local i=Create(Icon("\073\109\097\103\101\066\117\116\116\111\110",K),{Name=d.."\066\117\116\116\111\110";Visible=Option.Modifiable and Option.Selectable;Position=UDim2_new(1,(-4+-(GUI_SIZE+2)*y)+2,.25,-GUI_SIZE/2);Size=UDim2_new(0,GUI_SIZE,0,GUI_SIZE);Parent=headerFrame})local v=Create("\084\101\120\116\076\097\098\101\108",{Name=d.."\084\101\120\116";Text=d,Visible=false,BackgroundTransparency=1;TextXAlignment="\082\105\103\104\116";Font=FONT,FontSize=FONT_SIZE;Position=UDim2_new(0,0,0,0);Size=UDim2_new(1,-(GUI_SIZE+2)*O,1,0);Parent=headerFrame})i.MouseEnter:connect(function()if o then i.BackgroundTransparency=.9 end end)i.MouseLeave:connect(function()i.BackgroundTransparency=1 end)y=y+1 M[#M+1]={Obj=i,Cond=h}QuickButtons[#M+1]={Obj=i;Cond=h;Toggle=function(M)if M then o=true Icon(i,e)else o=false Icon(i,K)end end}return i end local function e(M)M.Parent=nil RemoteEvent:InvokeServer("\068\101\108\101\116\101",M)end;(K(ACTION_DELETE,ACTION_DELETE_OVER,"\068\101\108\101\116\101",true,function()return#Selection:Get()>0 end)).MouseButton1Click:connect(function()if not Option.Modifiable then return end local M=Selection:Get()for O=1,#M,1 do pcall(e,M[O])end Selection:Set({})end);(K(ACTION_PASTE,ACTION_PASTE_OVER,"\080\097\115\116\101",true,function()return#Selection:Get()>0 and#clipboard>0 end)).MouseButton1Click:connect(function()if not Option.Modifiable then return end local M=Selection.List[1]or workspace for O=1,#clipboard,1 do(clipboard[O]:Clone()).Parent=M end RemoteEvent:InvokeServer("\080\097\115\116\101",M)end);(K(ACTION_COPY,ACTION_COPY_OVER,"\067\111\112\121",true,function()return#Selection:Get()>0 end)).MouseButton1Click:connect(function()if not Option.Modifiable then return end clipboard={}local M=Selection.List RemoteEvent:InvokeServer("\067\108\101\097\114\067\108\105\112\098\111\097\114\100")for O=1,#M,1 do table.insert(clipboard,M[O]:Clone())RemoteEvent:InvokeServer("\067\111\112\121",M[O])end updateActions()end);(K(ACTION_CUT,ACTION_CUT_OVER,"\067\117\116",true,function()return#Selection:Get()>0 end)).MouseButton1Click:connect(function()if not Option.Modifiable then return end clipboard={}local M=Selection.List local O={}for y=1,#M,1 do local K=M[y]:Clone()if K then table.insert(clipboard,K)table.insert(O,M[y])RemoteEvent:InvokeServer("\067\111\112\121",M[y])end end for M=1,#O,1 do pcall(e,O[M])end updateActions()end)end
----------------------------------------------------------------
----------------------------------------------------------------
----------------------------------------------------------------
----------------------------------------------------------------
---- Actions

local actionButtons
do
	actionButtons = {}

	local totalActions = 1
	local currentActions = totalActions
	local function makeButton(icon, over, name, vis, cond)
		local buttonEnabled = false

		local button = Create(Icon("ImageButton", icon), {
			Name = name .. "Button",
			Visible = Option.Modifiable and Option.Selectable,
			Position = UDim2_new(1, -4 + -(GUI_SIZE + 2) * currentActions + 2, 0.25, -GUI_SIZE / 2),
			Size = UDim2_new(0, GUI_SIZE, 0, GUI_SIZE),
			Parent = headerFrame,
		})

		local tipText = Create("TextLabel", {
			Name = name .. "Text",
			Text = name,
			Visible = false,
			BackgroundTransparency = 1,
			TextXAlignment = "Right",
			Font = FONT,
			FontSize = FONT_SIZE,
			Position = UDim2_new(0, 0, 0, 0),
			Size = UDim2_new(1, -(GUI_SIZE + 2) * totalActions, 1, 0),
			Parent = headerFrame,
		})

		button.MouseEnter:connect(function()
			if buttonEnabled then
				button.BackgroundTransparency = 0.9
			end
			--Icon(button,over)
			--tipText.Visible = true
		end)
		button.MouseLeave:connect(function()
			button.BackgroundTransparency = 1
			--Icon(button,icon)
			--tipText.Visible = false
		end)

		currentActions = currentActions + 1
		actionButtons[#actionButtons + 1] = { Obj = button, Cond = cond }
		QuickButtons[#actionButtons + 1] = {
			Obj = button,
			Cond = cond,
			Toggle = function(on)
				if on then
					buttonEnabled = true
					Icon(button, over)
				else
					buttonEnabled = false
					Icon(button, icon)
				end
			end,
		}
		return button
	end

	--local clipboard = {}
	local function delete(o)
		o.Parent = nil
		RemoteEvent:InvokeServer("Delete", o)
	end

	-- DELETE
	makeButton(ACTION_DELETE, ACTION_DELETE_OVER, "Delete", true, function()
		return #Selection:Get() > 0
	end).MouseButton1Click:connect(function()
		if not Option.Modifiable then
			return
		end
		local list = Selection:Get()
		for i = 1, #list do
			pcall(delete, list[i])
		end
		Selection:Set({})
	end)

	-- PASTE
	makeButton(ACTION_PASTE, ACTION_PASTE_OVER, "Paste", true, function()
		return #Selection:Get() > 0 and #clipboard > 0
	end).MouseButton1Click:connect(function()
		if not Option.Modifiable then
			return
		end
		local parent = Selection.List[1] or workspace
		for i = 1, #clipboard do
			clipboard[i]:Clone().Parent = parent
		end

		RemoteEvent:InvokeServer("Paste", parent)
	end)

	-- COPY
	makeButton(ACTION_COPY, ACTION_COPY_OVER, "Copy", true, function()
		return #Selection:Get() > 0
	end).MouseButton1Click:connect(function()
		if not Option.Modifiable then
			return
		end
		clipboard = {}
		local list = Selection.List

		RemoteEvent:InvokeServer("ClearClipboard")
		for i = 1, #list do
			table.insert(clipboard, list[i]:Clone())
			RemoteEvent:InvokeServer("Copy", list[i])
		end
		updateActions()
	end)

	-- CUT
	makeButton(ACTION_CUT, ACTION_CUT_OVER, "Cut", true, function()
		return #Selection:Get() > 0
	end).MouseButton1Click:connect(function()
		if not Option.Modifiable then
			return
		end
		clipboard = {}
		local list = Selection.List
		local cut = {}
		for i = 1, #list do
			local obj = list[i]:Clone()
			if obj then
				table.insert(clipboard, obj)
				table.insert(cut, list[i])

				RemoteEvent:InvokeServer("Copy", list[i])
			end
		end
		for i = 1, #cut do
			pcall(delete, cut[i])
		end
		updateActions()
	end)

	-- FREEZE

	-- SORT
	-- local actionSort = makeButton(ACTION_SORT,ACTION_SORT_OVER,"Sort")
end
