-- Decompiled with the Synapse X Luau decompiler.

local l__LocalPlayer__1 = game.Players.LocalPlayer;
local l__ReplicatedStorage__1 = game.ReplicatedStorage;
function getLevel(p1)
	local v2 = 0;
	local l__Value__3 = l__ReplicatedStorage__1.Pets.Settings.MaxPetLevel.Value;
	local v4 = 0 - 1;
	while true do
		if 100 * v4 + v2 <= p1 then
			if v4 ~= l__ReplicatedStorage__1.Pets.Settings.MaxPetLevel.Value then

			else
				return v4;
			end;
			if p1 < 100 * v4 + v2 + (100 + 25 * v4) then
				return v4;
			end;
		end;
		v2 = v2 + v4 * 25;
		if 0 <= 1 then
			if v4 < l__Value__3 then

			else
				break;
			end;
		elseif l__Value__3 < v4 then

		else
			break;
		end;
		v4 = v4 + 1;	
	end;
end;
function GetFolderFromPetID(p2)
	local v5, v6, v7 = pairs(l__LocalPlayer__1.Pets:GetChildren());
	while true do
		local v8, v9 = v5(v6, v7);
		if v8 then

		else
			break;
		end;
		v7 = v8;
		if v9.PetID.Value == p2 then
			return v9;
		end;	
	end;
	return nil;
end;
function getLayoutOrder(p3)
	local v10 = GetFolderFromPetID(p3);
	local l__Value__11 = l__ReplicatedStorage__1.Pets.Rarities:FindFirstChild(l__ReplicatedStorage__1.Pets.Models:FindFirstChild(v10.Name).Settings.Rarity.Value).Order.Value;
	local l__Value__12 = l__ReplicatedStorage__1.Pets.Settings.MaxPetLevel.Value;
	local v13 = getLevel(v10.TotalXP.Value);
	local v14 = {};
	local v15 = 0;
	local v16, v17, v18 = pairs(l__ReplicatedStorage__1.Pets.Models:GetChildren());
	while true do
		local v19, v20 = v16(v17, v18);
		if v19 then

		else
			break;
		end;
		v18 = v19;
		v14[#v14 + 1] = v20;	
	end;
	table.sort(v14, function(p4, p5)
		return p4:GetFullName() < p5:GetFullName();
	end);
	local v21, v22, v23 = pairs(v14);
	while true do
		local v24 = nil;
		local v25 = nil;
		v25, v24 = v21(v22, v23);
		if v25 then

		else
			break;
		end;
		v23 = v25;
		if v10.Equipped.Value == true then
			if v10.Name == v24.Name then
				return l__Value__12 * #v14 * (#l__ReplicatedStorage__1.Pets.Rarities:GetChildren() - l__Value__11) + v15 * l__Value__12 + (l__Value__12 - v13);
			end;
		elseif v10.Name == v24.Name then
			return #v14 * #l__ReplicatedStorage__1.Pets.Rarities:GetChildren() * l__Value__12 + l__Value__12 * #v14 * (#l__ReplicatedStorage__1.Pets.Rarities:GetChildren() - l__Value__11) + v15 * l__Value__12 + (l__Value__12 - v13);
		end;
		v15 = v15 + 1;	
	end;
end;
local u2 = Color3.fromRGB(100, 100, 100);
local l__Inventory__3 = script.Parent.Parent.Parent.Parent.MainFrame.Inventory;
local l__Pets__4 = l__LocalPlayer__1:WaitForChild("Pets");
local l__TextLabel__5 = script.Parent.Parent.Parent.Parent.MainFrame.StorageDisplay.TextLabel;
local l__Data__6 = l__LocalPlayer__1:WaitForChild("Data");
local l__TextLabel__7 = script.Parent.Parent.Parent.Parent.MainFrame.EquippedDisplay.TextLabel;
local l__ImageColor3__8 = script.Parent.ImageColor3;
script.Parent.MouseButton1Click:Connect(function()
	if script.Parent.TextLabel.Text == "Equip" then
		local v26, v27 = l__ReplicatedStorage__1.RemoteEvents.PetActionRequest:InvokeServer("Equip", {
			PetID = script.Parent.Parent.Parent.PetID.Value
		});
		if v26 == "Success" then
			script.Parent.ImageColor3 = u2;
			script.Parent.TextLabel.Text = "Unequip";
			for v28, v29 in pairs(l__Inventory__3:GetChildren()) do
				if not v29:IsA("UIGridLayout") then
					v29.LayoutOrder = getLayoutOrder(v29.PetID.Value);
					if v29.PetID.Value == script.Parent.Parent.Parent.PetID.Value then
						v29.EquipMarker.Visible = true;
					end;
				end;
			end;
			local v30 = 0;
			for v31, v32 in pairs(l__Pets__4:GetChildren()) do
				if v32.Equipped.Value == true then
					v30 = v30 + 1;
				end;
			end;
			l__TextLabel__5.Text = #l__Pets__4:GetChildren() .. "/" .. l__Data__6.MaxStorage.Value;
			l__TextLabel__7.Text = v30 .. "/" .. l__Data__6.MaxEquip.Value;
			return;
		elseif v26 == "Error" then
			print(v27);
			return;
		end;
	elseif script.Parent.TextLabel.Text == "Unequip" then
		local v33, v34 = l__ReplicatedStorage__1.RemoteEvents.PetActionRequest:InvokeServer("Unequip", {
			PetID = script.Parent.Parent.Parent.PetID.Value
		});
		if v33 == "Success" then
			script.Parent.ImageColor3 = l__ImageColor3__8;
			script.Parent.TextLabel.Text = "Equip";
			for v35, v36 in pairs(l__Inventory__3:GetChildren()) do
				if not v36:IsA("UIGridLayout") then
					v36.LayoutOrder = getLayoutOrder(v36.PetID.Value);
					if v36.PetID.Value == script.Parent.Parent.Parent.PetID.Value then
						v36.EquipMarker.Visible = false;
					end;
				end;
			end;
			local v37 = 0;
			for v38, v39 in pairs(l__Pets__4:GetChildren()) do
				if v39.Equipped.Value == true then
					v37 = v37 + 1;
				end;
			end;
			l__TextLabel__5.Text = #l__Pets__4:GetChildren() .. "/" .. l__Data__6.MaxStorage.Value;
			l__TextLabel__7.Text = v37 .. "/" .. l__Data__6.MaxEquip.Value;
			return;
		elseif v33 == "Error" then
			print(v34);
		end;
	end;
end);