using System.Linq;
using Plus.Communication.Packets.Outgoing.Rooms.Furni;
using Plus.HabboHotel.Items.Crafting;
using Plus.HabboHotel.Rooms;

namespace Plus.Communication.Packets.Incoming.Rooms.Furni
{
    class GetCraftingItemEvent : IPacketEvent
    {
        public void Parse(HabboHotel.GameClients.GameClient Session, ClientPacket Packet)
        {
            var result = Packet.PopString();

            CraftingRecipe recipe = null;

            foreach (CraftingRecipe Receta in PlusEnvironment.GetGame().GetCraftingManager().CraftingRecipes.Values)
            {
                if (Receta.Result.Contains(result))
                {
                    recipe = Receta;
                    break;
                }
            }

            var Final = PlusEnvironment.GetGame().GetCraftingManager().GetRecipe(recipe.Id);

            Session.SendMessage(new CraftingResultComposer(recipe, true));


            
            foreach (Room R in PlusEnvironment.GetGame().GetRoomManager().GetRooms().ToList())
            {
                R.GetGameMap().GenerateMaps();
                Session.SendMessage(new CraftableProductsComposer());
            }
        }
    }
}