using System;
using Server;
using Knives.Utils;

namespace Knives.Chat3
{
    public enum FilterPenalty { None, Ban, Jail }

	public class Filter
	{
        public static string FilterText(Mobile m, string s)
        {
            return FilterText(m, s, true);
        }

		public static string FilterText( Mobile m, string s, bool punish )
		{try{

			string filter = "";
			string subOne = "";
			string subTwo = "";
			string subThree = "";
			int index = 0;

			for( int i = 0; i < Data.Filters.Count; ++i )
			{
				filter = Data.Filters[i].ToString();

				if ( filter == "" )
				{
					Data.Filters.Remove( filter );
					continue;
				}

				index = s.ToLower().IndexOf( filter );

				if ( index >= 0 )
				{
					if ( m.AccessLevel == AccessLevel.Player && punish)
					{
                        if (Data.FilterPenalty != FilterPenalty.None)
                            m.SendMessage(Data.GetData(m).SystemC, General.Local(111) + " " + filter);

                        if (Data.FilterPenalty == FilterPenalty.Ban)
                            Data.GetData(m).Ban(TimeSpan.FromMinutes(Data.FilterBanLength));

                        if (Data.FilterPenalty == FilterPenalty.Jail)
                        {
                            //Insert your jail method here
                        }
                         
                        if (Data.FilterPenalty != FilterPenalty.None)
                            return "";
					}

					subOne = s.Substring( 0, index );
					subTwo = "";

					for( int ii = 0; ii < filter.Length; ++ii )
						subTwo+="*";

					subThree = s.Substring( index+filter.Length, s.Length-filter.Length-index );

					s = subOne + subTwo + subThree;

					i--;
				}
			}

			}catch{ Errors.Report( General.Local(176) ); }

			return s;
		}
	}
}