using System;
using Server.Gumps;
using Server.Network;
using Server.Engines.Craft;
using Server.Items;
namespace Server.Engines.Craft
{
	public class QueueAmountGump : Gump
	{
		private Mobile m_From;
		private CraftSystem m_System;
		private CraftItem m_Item;
		private Type m_ResType;
		private BaseTool m_Tool;

		public QueueAmountGump( Mobile from, CraftSystem system, CraftItem item, Type resType, BaseTool tool ) : base( 200, 200 )
		{
			m_From = from;
			m_System = system;
			m_Item = item;
			m_ResType = resType;
			m_Tool = tool;

			// Match the theme: 5054 background, 2624 tiles
			AddBackground( 0, 0, 250, 160, 5054 );
			AddImageTiled( 10, 10, 230, 22, 2624 );
			AddAlphaRegion( 10, 10, 230, 140 );

			AddHtml( 10, 12, 230, 20, "<CENTER><BASEFONT COLOR=#FFFFFF>AMOUNT TO QUEUE</BASEFONT></CENTER>", false, false );
			
			// Input Box
			AddImageTiled( 50, 50, 150, 25, 2624 );
			AddTextEntry( 55, 52, 140, 20, 0x480, 1, "1" ); 

			// Buttons
			AddButton( 40, 110, 4005, 4007, 1, GumpButtonType.Reply, 0 ); // OK
			AddLabel( 70, 113, 0x480, "ADD " );

			AddButton( 150, 110, 4017, 4019, 0, GumpButtonType.Reply, 0 ); // CANCEL
            AddLabel( 185, 113, 0x480, "CANCEL " );
		}

		public override void OnResponse( NetState sender, RelayInfo info )
		{
			if ( info.ButtonID == 1 )
			{
				TextRelay relay = info.GetTextEntry( 1 );
				int amount = 0;

				if ( relay != null && int.TryParse( relay.Text, out amount ) && amount > 0 )
				{
					CraftQueue queue = CraftQueueManager.GetQueue( m_From, m_System );
					queue.Entries.Add( new CraftQueueEntry( m_Item, m_ResType, amount ) );
					m_From.SendMessage( 0x35, "Added {0} of that item to your queue.", amount );
				}
				else
				{
					m_From.SendMessage( 0x22, "Invalid amount." );
				}
			}
			
			// Always return to the craft gump
			m_From.SendGump( new CraftGump( m_From, m_System, m_Tool, null ) );
		}
	}
}
