-- Decompiled with the Synapse X Luau decompiler.


local l__ReplicatedStorage__1 = game.ReplicatedStorage;
function getLevel(p1)
	local v1 = 0;
	local l__Value__2 = l__ReplicatedStorage__1.Pets.Settings.MaxPetLevel.Value;
	local v3 = 0 - 1;
	while true do
		if 100 * v3 + v1 <= p1 then
			if v3 ~= l__ReplicatedStorage__1.Pets.Settings.MaxPetLevel.Value then

			else
				return v3;
			end;
			if p1 < 100 * v3 + v1 + (100 + 25 * v3) then
				return v3;
			end;
		end;
		v1 = v1 + v3 * 25;
		if 0 <= 1 then
			if v3 < l__Value__2 then

			else
				break;
			end;
		elseif l__Value__2 < v3 then

		else
			break;
		end;
		v3 = v3 + 1;	
	end;
end;
local l__LocalPlayer__2 = game.Players.LocalPlayer;
function GetFolderFromPetID(p2)
	for v7, v8 in pairs(l__LocalPlayer__2.Pets:GetChildren()) do
		if v8.PetID.Value == p2 then
			return v8;
		end;	
	end;
	return nil;
end;
function getLayoutOrder(p3)
	local v9 = GetFolderFromPetID(p3);
	local l__Value__10 = l__ReplicatedStorage__1.Pets.Rarities:FindFirstChild(l__ReplicatedStorage__1.Pets.Models:FindFirstChild(v9.Name).Settings.Rarity.Value).Order.Value;
	local l__Value__11 = l__ReplicatedStorage__1.Pets.Settings.MaxPetLevel.Value;
	local v12 = getLevel(v9.TotalXP.Value);
	local v13 = {};
	local v14 = 0;
	for v18, v19 in pairs(l__ReplicatedStorage__1.Pets.Models:GetChildren()) do
		v13[#v13 + 1] = v19;	
	end;
	table.sort(v13, function(p4, p5)
		return p4:GetFullName() < p5:GetFullName();
	end);
	for v24, v23 in pairs(v13) do
		if v9.Equipped.Value == true then
			if v9.Name == v23.Name then
				return l__Value__11 * #v13 * (#l__ReplicatedStorage__1.Pets.Rarities:GetChildren() - l__Value__10) + v14 * l__Value__11 + (l__Value__11 - v12);
			end;
		elseif v9.Name == v23.Name then
			return #v13 * #l__ReplicatedStorage__1.Pets.Rarities:GetChildren() * l__Value__11 + l__Value__11 * #v13 * (#l__ReplicatedStorage__1.Pets.Rarities:GetChildren() - l__Value__10) + v14 * l__Value__11 + (l__Value__11 - v12);
		end;
		v14 = v14 + 1;	
	end;
end;
local l__Inventory__3 = script.Parent.Parent.Parent.Parent.MainFrame.Inventory;
script.Parent.MouseButton1Click:Connect(function()
	local v25, v26 = l__ReplicatedStorage__1.RemoteEvents.PetActionRequest:InvokeServer("Delete", {
		PetID = script.Parent.Parent.Parent.PetID.Value
	});
	if v25 ~= "Success" then
		if v25 == "Error" then
			print(v26);
		end;
		return;
	end;
	script.Parent.Parent.Visible = false;
	for v27, v28 in pairs(l__Inventory__3:GetChildren()) do
		if not v28:IsA("UIGridLayout") then
			v28.LayoutOrder = getLayoutOrder(v28.PetID.Value);
		end;
	end;
end);
