local f=Cheer.CreateComponent("\066\084\068\111\099\107",View,true)function f.Start(S)View.Visible=true;(getfenv(1)).Core=S local v=f.AddSelectionButton(S.Assets.UndoInactiveDecal,"\085\078\068\079\n\040\083\104\105\102\116 \043 \090\041")local h=f.AddSelectionButton(S.Assets.RedoInactiveDecal,"\082\069\068\079\n\040\083\104\105\102\116 \043 \089\041")local l=f.AddSelectionButton(S.Assets.DeleteInactiveDecal,"\068\069\076\069\084\069\n\040\083\104\105\102\116 \043 \088\041")local u=f.AddSelectionButton(S.Assets.ExportInactiveDecal,"\069\088\080\079\082\084\n\040\083\104\105\102\116 \043 \080\041")local N=f.AddSelectionButton(S.Assets.CloneInactiveDecal,"\067\076\079\078\069\n\040\083\104\105\102\116 \043 \067\041")Cheer.Bind(v,S.History.Undo)Cheer.Bind(h,S.History.Redo)Cheer.Bind(N,S.CloneSelection)Cheer.Bind(l,S.DeleteSelection)Cheer.Bind(u,S.ExportSelection)Cheer.Bind(S.History.Changed,function()v.Image=S.History.Index==0 and S.Assets.UndoInactiveDecal or S.Assets.UndoActiveDecal h.Image=S.History.Index==#S.History.Stack and S.Assets.RedoInactiveDecal or S.Assets.RedoActiveDecal end)Cheer.Bind(S.Selection.Changed,function()N.Image=#S.Selection.Items==0 and S.Assets.CloneInactiveDecal or S.Assets.CloneActiveDecal l.Image=#S.Selection.Items==0 and S.Assets.DeleteInactiveDecal or S.Assets.DeleteActiveDecal u.Image=#S.Selection.Items==0 and S.Assets.ExportInactiveDecal or S.Assets.ExportActiveDecal end)Cheer.Bind(S.ToolChanged,function()for f,v in pairs(f.ToolButtons)do v.BackgroundTransparency=f==S.CurrentTool and 0 or 1 end end)Cheer.Bind(View.InfoButtons.HelpButton,function()(Cheer(View.ToolInformation)).HideCurrentSection()View.HelpInfo.Visible=not View.HelpInfo.Visible end);(Cheer(View.ToolInformation)).Start(S)return f end function f.AddSelectionButton(f,S)local v=View.SelectionButton:Clone()local h=#View.SelectionButtons:GetChildren()v.Parent=View.SelectionButtons v.Image=f v.Visible=true v.Position=UDim2.new((h%2)*.5,0,0,v.AbsoluteSize.Y*math.floor(h/2));(Cheer(View.Tooltip,v)).Start(S)return v end f.ToolButtons={}function f.AddToolButton(S,v,h,l)local u=View.ToolButton:Clone()local N=#View.ToolButtons:GetChildren()u.Parent=View.ToolButtons u.BackgroundColor3=h.Color and h.Color.Color or Color3.new(0,0,0)u.BackgroundTransparency=Core.CurrentTool==h and 0 or 1 u.Image=S u.Visible=true u.Hotkey.Text=v f.ToolButtons[h]=u Cheer.Bind(u,Support.Call(Core.EquipTool,h));(Cheer(View.ToolInformation)).RegisterSection(l)Support.AddGuiInputListener(u,"\066\101\103\097\110",{"\077\111\117\115\101\066\117\116\116\111\110\049"},false,function()(Cheer(View.ToolInformation)).ProcessClick(h,l)end)Support.AddGuiInputListener(u,"\066\101\103\097\110",{"\077\111\117\115\101\077\111\118\101\109\101\110\116"},false,function()(Cheer(View.ToolInformation)).ProcessHover(h,l)end)Support.AddGuiInputListener(u,"\069\110\100\101\100",{"\077\111\117\115\101\077\111\118\101\109\101\110\116"},true,function()(Cheer(View.ToolInformation)).ProcessUnhover(h,l)end)local P=nil Support.AddGuiInputListener(u,"\066\101\103\097\110",{"\084\111\117\099\104"},false,function()local f=tick()P=f wait(.5)if P==f then(Cheer(View.ToolInformation)).ProcessClick(h,l)end end)Support.AddGuiInputListener(u,"\069\110\100\101\100",{"\084\111\117\099\104"},true,function()P=nil end)u.Position=UDim2.new((N%2)*.5,0,0,u.AbsoluteSize.Y*math.floor(N/2))return u end

local Component = Cheer.CreateComponent('BTDock', View, true);

function Component.Start(Core)

	-- Show the view
	View.Visible = true;

	-- Store core API reference
	getfenv(1).Core = Core;

	-- Create selection buttons
	local UndoButton = Component.AddSelectionButton(Core.Assets.UndoInactiveDecal, 'UNDO\n(Shift + Z)');
	local RedoButton = Component.AddSelectionButton(Core.Assets.RedoInactiveDecal, 'REDO\n(Shift + Y)');
	local DeleteButton = Component.AddSelectionButton(Core.Assets.DeleteInactiveDecal, 'DELETE\n(Shift + X)');
	local ExportButton = Component.AddSelectionButton(Core.Assets.ExportInactiveDecal, 'EXPORT\n(Shift + P)');
	local CloneButton = Component.AddSelectionButton(Core.Assets.CloneInactiveDecal, 'CLONE\n(Shift + C)');

	-- Connect selection buttons to core systems
	Cheer.Bind(UndoButton, Core.History.Undo);
	Cheer.Bind(RedoButton, Core.History.Redo);
	Cheer.Bind(CloneButton, Core.CloneSelection);
	Cheer.Bind(DeleteButton, Core.DeleteSelection);
	Cheer.Bind(ExportButton, Core.ExportSelection);

	-- Highlight history selection buttons according to state
	Cheer.Bind(Core.History.Changed, function ()
		UndoButton.Image = (Core.History.Index == 0) and Core.Assets.UndoInactiveDecal or Core.Assets.UndoActiveDecal;
		RedoButton.Image = (Core.History.Index == #Core.History.Stack) and Core.Assets.RedoInactiveDecal or Core.Assets.RedoActiveDecal;
	end);

	-- Highlight clone/delete/export buttons according to selection state
	Cheer.Bind(Core.Selection.Changed, function ()
		CloneButton.Image = (#Core.Selection.Items == 0) and Core.Assets.CloneInactiveDecal or Core.Assets.CloneActiveDecal;
		DeleteButton.Image = (#Core.Selection.Items == 0) and Core.Assets.DeleteInactiveDecal or Core.Assets.DeleteActiveDecal;
		ExportButton.Image = (#Core.Selection.Items == 0) and Core.Assets.ExportInactiveDecal or Core.Assets.ExportActiveDecal;
	end);

	-- Highlight current tools
	Cheer.Bind(Core.ToolChanged, function ()
		for Tool, Button in pairs(Component.ToolButtons) do
			Button.BackgroundTransparency = (Tool == Core.CurrentTool) and 0 or 1;
		end;
	end);

	-- Toggle help section on help button click
	Cheer.Bind(View.InfoButtons.HelpButton, function ()
		Cheer(View.ToolInformation).HideCurrentSection();
		View.HelpInfo.Visible = not View.HelpInfo.Visible;
	end);

	-- Start tool information section manager
	Cheer(View.ToolInformation).Start(Core);

	-- Return component for chaining
	return Component;

end;

function Component.AddSelectionButton(InitialIcon, Tooltip)

	-- Create the button
	local Button = View.SelectionButton:Clone();
	local Index = #View.SelectionButtons:GetChildren();
	Button.Parent = View.SelectionButtons;
	Button.Image = InitialIcon;
	Button.Visible = true;

	-- Position the button
	Button.Position = UDim2.new(Index % 2 * 0.5, 0, 0, Button.AbsoluteSize.Y * math.floor(Index / 2));

	-- Add a tooltip to the button
	Cheer(View.Tooltip, Button).Start(Tooltip);

	-- Return the button
	return Button;

end;

Component.ToolButtons = {};

function Component.AddToolButton(Icon, Hotkey, Tool, InfoSection)

	-- Create the button
	local Button = View.ToolButton:Clone();
	local Index = #View.ToolButtons:GetChildren();
	Button.Parent = View.ToolButtons;
	Button.BackgroundColor3 = Tool.Color and Tool.Color.Color or Color3.new(0, 0, 0);
	Button.BackgroundTransparency = (Core.CurrentTool == Tool) and 0 or 1;
	Button.Image = Icon;
	Button.Visible = true;
	Button.Hotkey.Text = Hotkey;

	-- Register the button
	Component.ToolButtons[Tool] = Button;

	-- Trigger tool when button is pressed
	Cheer.Bind(Button, Support.Call(Core.EquipTool, Tool));

	-- Register information section
	Cheer(View.ToolInformation).RegisterSection(InfoSection);

	-- Trigger information section on interactions with button
	Support.AddGuiInputListener(Button, 'Began', {'MouseButton1'}, false, function ()
		Cheer(View.ToolInformation).ProcessClick(Tool, InfoSection)
	end)
	Support.AddGuiInputListener(Button, 'Began', {'MouseMovement'}, false, function ()
		Cheer(View.ToolInformation).ProcessHover(Tool, InfoSection)
	end)
	Support.AddGuiInputListener(Button, 'Ended', {'MouseMovement'}, true, function ()
		Cheer(View.ToolInformation).ProcessUnhover(Tool, InfoSection)
	end)

	-- Time how long each press on the button lasts
	local TouchStart = nil
	Support.AddGuiInputListener(Button, 'Began', {'Touch'}, false, function ()
		local Timestamp = tick()
		TouchStart = Timestamp
		wait(0.5)

		-- Trigger tool info if still touching after delay
		if TouchStart == Timestamp then
			Cheer(View.ToolInformation).ProcessClick(Tool, InfoSection)
		end
	end)
	Support.AddGuiInputListener(Button, 'Ended', {'Touch'}, true, function ()
		TouchStart = nil
	end)

	-- Position the button
	Button.Position = UDim2.new(Index % 2 * 0.5, 0, 0, Button.AbsoluteSize.Y * math.floor(Index / 2));

	-- Return the button
	return Button;

end;
