-- If in-game, enable ctrl hotkeys for sibling selection & selection clearing

if Mode == 'Tool' then
	AssignHotkey({ 'LeftControl', 'LeftBracket' }, Support.Call(Targeting.SelectSiblings, false, false));
	AssignHotkey({ 'RightControl', 'LeftBracket' }, Support.Call(Targeting.SelectSiblings, false, false));
	AssignHotkey({ 'LeftControl', 'R' }, Support.Call(Selection.Clear, true));
	AssignHotkey({ 'RightControl', 'R' }, Support.Call(Selection.Clear, true));
end;

function IsSelectable(Object)
	-- Returns whether `Object` can be selected

	-- Check if `Object` exists, is not locked, and is not ignored
	if not Object or not Object.Parent or not Object:IsA 'BasePart' or Object.Locked or IsIgnored(Object) then
		return false;
	end;

	-- If areas are enabled, check if `Object` violates any areas
	if Security.AreAreasEnabled() then
		return not Security.ArePartsViolatingAreas({ Object }, Player, true, {});
	end;

	-- If no checks fail, `Object` is selectable
	return Object;

end;

function IsIgnored(Object)
	-- TODO: Add ignoring capability
end;

function SetParent(Parent)
	-- Sets the current default parent for parts

end;

function ExportSelection()
	-- Exports the selected parts

	-- Make sure that there are items in the selection
	if #Selection.Items == 0 then
		return;
	end;

	-- Start an export dialog
	local Dialog = Cheer(Tool.Interfaces.ExportDialog, UI).Start();

	-- Send the exporting request to the server
	Try(SyncAPI.Invoke, SyncAPI, 'Export', Selection.Items)

	-- Display creation ID on success
	:Then(function (CreationId)
		Dialog.SetResult(CreationId);
		PlayConfirmationSound();
		print('[Building Tools by F3X] Uploaded Export:', CreationId);
	end)

	-- Display error messages on failure
	:Catch('Http requests are not enabled', function ()
		Dialog.SetError('Please enable HTTP requests');
	end)
	:Catch('Export failed due to server-side error', function ()
		Dialog.SetError('An error occurred, try again');
	end)
	:Catch('Post data too large', function ()
		Dialog.SetError('Try splitting up your build');
	end)
	:Catch(function (Error, Stack, Attempt)
		Dialog.SetError('An unknown error occurred, try again')
		warn('❌ [Building Tools by F3X] Failed to export selection', '\n\nError:\n', Error, '\n\nStack:\n', Stack);
	end);

end;
