package rainbowPackage;

import javafx.scene.paint.Color;

public class DeterminerForBasisImageHit
{
	private Color fxColor = Color.BEIGE, tempColor = Color.OLIVE, basisPRColor = Color.INDIANRED;
	private TransparencySlider transparencySlider = new TransparencySlider( Color.BLACK );
	private RainbowSoftColor rainbowSoftColor = new RainbowSoftColor( new double[]{0,0,0,1} );
	private ColorTooSimilar colorTooSimilarFunction = new ColorTooSimilar();
	private ColorDecide colorDecide = new ColorDecide();
	private IndependentTextBackgroundColorPasser independentTextBackgroundColorPasser = new IndependentTextBackgroundColorPasser();
	//private boolean returnImmediatly = false;

	public DeterminerForBasisImageHit()	{	}

	public Color ToFXColor()
	{
		return transparencySlider.ToFXColor();
	}

	public Color PixelColorDetermine( Color BasisPRColor, Color BackgroundBasisPRColor, Color BrowserPRColor, Color InitialColorContrastingChoice, Color ColorTooSimilarReplacementColor, double ColorDifference, boolean InvertBasisFromBackground, boolean AuxiliarySwitch, boolean InvertBasisPicture, boolean InvertBoth, boolean NextStepColorTooSimilarEffect, boolean TextOutlineBlendingToBasisInvert, Color TextColorToOverlay, Color BackgroundColorToOverlay, Color BasisOverlaySperateTextColor, Color BasisOverlaySperateBackgroundColor, boolean TextColorOverlay, boolean BackgroundColorOverlay, boolean ShowBasisOverlayForText, boolean ShowBasisOverlayForBackground, boolean BasisOverlaySeperateTextFade, boolean BasisOverlaySeperateBackgroundFade, boolean BasisImageStandOutHit, boolean SomeTargetColorHit, boolean BrowserTextHit, double TextTransitionFactor, boolean SomeTargetColorHitFromDisplayType, boolean LaterReversed, boolean TypeOfDisplayIsBackgroundToBasisFullDisplay, boolean UseFadeAtAll, Color ColorFromSplash2D )
	{
		basisPRColor = BasisPRColor;
		fxColor = ColorFromSplash2D;
		transparencySlider.set( ColorFromSplash2D );
		if ( BasisImageStandOutHit && ( InvertBoth || InvertBasisPicture ) )
		{
			tempColor = basisPRColor;
			basisPRColor = tempColor.invert();
		}
		if ( AuxiliarySwitch && !UseFadeAtAll )//if ( !UseFadeAtAll )
		{
			if ( !BasisImageStandOutHit && SomeTargetColorHit )
				return transparencySlider.ToFXColor();
			else if ( BasisImageStandOutHit && SomeTargetColorHit )
			{
				if ( !BrowserTextHit && ShowBasisOverlayForBackground )
				{
					transparencySlider.set( basisPRColor );
					return transparencySlider.ToFXColor();
				}
				else if ( !BrowserTextHit )//&& !ShowBasisOverlayForBackground )
				{
					return transparencySlider.ToFXColor();
				}
				else if ( ShowBasisOverlayForText )// BrowserTextHit && 
				{
					tempColor = basisPRColor;
					fxColor = tempColor.invert();
					if ( colorTooSimilarFunction.ColorTooSimilarFunction( fxColor, basisPRColor, ColorDifference ) )
						fxColor = Color.rgb(0,255,0);
					//return transparencySlider.TransparencySliderFunction( 1, TextTransitionFactor, fxColor, basisPRColor );
					//if ( TextTransitionFactor < 0.001 && !TextOutlineBlendingToBasisInvert )
					//	transparencySlider.set( fxColor );
					//else
					//{
					transparencySlider.TransparencySliderFunction( 1, TextTransitionFactor, fxColor, basisPRColor );//Order May Be Backwards Due To Bug!
					//}
					//colorDecide.NextColorDecide( basisPRColor, BackgroundBasisPRColor, transparencySlider.ToFXColor(), BrowserPRColor, InitialColorContrastingChoice, ColorTooSimilarReplacementColor, ColorDifference, SomeTargetColorHitFromDisplayType, SomeTargetColorHit, !BrowserTextHit, NextStepColorTooSimilarEffect, InvertBasisFromBackground, TypeOfDisplayIsBackgroundToBasisFullDisplay );
					return transparencySlider.ToFXColor();// */
				}
				/*else if ( TextTransitionFactor < 0.001 )//&& !ShowBasisOverlayForText )
				{
					fxColor = colorDecide.NextColorDecide( basisPRColor, BackgroundBasisPRColor, transparencySlider.ToFXColor(), BrowserPRColor, InitialColorContrastingChoice, ColorTooSimilarReplacementColor, ColorDifference, SomeTargetColorHitFromDisplayType, SomeTargetColorHit, !BrowserTextHit, NextStepColorTooSimilarEffect, InvertBasisFromBackground, TypeOfDisplayIsBackgroundToBasisFullDisplay );
					transparencySlider.set( fxColor );
					return transparencySlider.ToFXColor();
				}
				else
				{
					//System.out.println("Before Bug; TextTransitionFactor: " + TextTransitionFactor + " TextOutlineBlendingToBasisInvert: " + TextOutlineBlendingToBasisInvert + " transparencySlider.ToFXColor(): " + transparencySlider.ToFXColor() );
					if ( TextOutlineBlendingToBasisInvert )
						transparencySlider.TransparencySliderFunction( 1, TextTransitionFactor, fxColor, basisPRColor );
					//System.out.println("Before Bug2; TextTransitionFactor: " + TextTransitionFactor + " TextOutlineBlendingToBasisInvert: " + TextOutlineBlendingToBasisInvert + " transparencySlider.ToFXColor(): " + transparencySlider.ToFXColor() );
					fxColor = colorDecide.NextColorDecide( basisPRColor, BackgroundBasisPRColor, transparencySlider.ToFXColor(), BrowserPRColor, InitialColorContrastingChoice, ColorTooSimilarReplacementColor, ColorDifference, SomeTargetColorHitFromDisplayType, SomeTargetColorHit, !BrowserTextHit, NextStepColorTooSimilarEffect, InvertBasisFromBackground, TypeOfDisplayIsBackgroundToBasisFullDisplay );
					//System.out.println("After colorDecide; TextTransitionFactor: " + TextTransitionFactor + " TextOutlineBlendingToBasisInvert: " + TextOutlineBlendingToBasisInvert + " transparencySlider.ToFXColor(): " + transparencySlider.ToFXColor() );
					if ( !TextOutlineBlendingToBasisInvert )
					{
						//System.out.println("Before transparencySlider.TransparencySliderFunction; TextTransitionFactor: " + TextTransitionFactor + " fxColor: " + fxColor + " basisPRColor: " + basisPRColor );
						transparencySlider.TransparencySliderFunction( 1, TextTransitionFactor, fxColor, basisPRColor );
						//System.out.println("After transparencySlider.TransparencySliderFunction; TextTransitionFactor: " + TextTransitionFactor + " TextOutlineBlendingToBasisInvert: " + TextOutlineBlendingToBasisInvert + " transparencySlider.ToFXColor(): " + transparencySlider.ToFXColor() );
					}
					else
						transparencySlider.set( fxColor );
					//System.out.println("After Bug; TextTransitionFactor: " + TextTransitionFactor + " TextOutlineBlendingToBasisInvert: " + TextOutlineBlendingToBasisInvert + " transparencySlider.ToFXColor(): " + transparencySlider.ToFXColor() );
					return transparencySlider.ToFXColor();
				}// */
			}
			else// if ( !SomeTargetColorHit )
			{
				if ( ( InvertBasisPicture && !BrowserTextHit ) || ( !InvertBasisPicture && BrowserTextHit ) )
				{
					tempColor = basisPRColor;
					fxColor = tempColor.invert();
					if ( colorTooSimilarFunction.ColorTooSimilarFunction( fxColor, basisPRColor, ColorDifference ) )
						fxColor = Color.rgb(0,255,0);
				}
				else if ( BrowserTextHit )
					fxColor = basisPRColor;
				transparencySlider.set( fxColor );
				return transparencySlider.ToFXColor();
			}
		}// #/
		else if ( SomeTargetColorHit )
		{
			if ( !BasisImageStandOutHit )
			{
				if ( UseFadeAtAll && ( BackgroundColorOverlay || TextColorOverlay ) )
					transparencySlider.set( independentTextBackgroundColorPasser.IndependentTextBackgroundColorPasserFunction ( fxColor, TextColorToOverlay, BackgroundColorToOverlay, BackgroundColorOverlay, TextColorOverlay, BrowserTextHit ) );
				//if ( !BrowserTextHit )
				return transparencySlider.ToFXColor();
			}
			else// if ( BasisImageStandOutHit )
			{
				if ( !BrowserTextHit )
				{
					if ( UseFadeAtAll )
					{
						if ( BasisOverlaySeperateBackgroundFade )
							if ( ShowBasisOverlayForBackground )
								//transparencySlider.set( Color.BLUEVIOLET );
								transparencySlider.CombineColors( basisPRColor, BasisOverlaySperateBackgroundColor );//transparencySlider.set( independentTextBackgroundColorPasser.IndependentTextBackgroundColorPasserFunction ( basisPRColor, BasisOverlaySperateTextColor, BasisOverlaySperateBackgroundColor, BasisOverlaySeperateBackgroundFade, BasisOverlaySeperateTextFade, BrowserTextHit ) );
							else// if ( !ShowBasisOverlayForBackground )
								transparencySlider.CombineColors( fxColor, BasisOverlaySperateBackgroundColor );//transparencySlider.set( independentTextBackgroundColorPasser.IndependentTextBackgroundColorPasserFunction ( fxColor, BasisOverlaySperateTextColor, BasisOverlaySperateBackgroundColor, BasisOverlaySeperateBackgroundFade, BasisOverlaySeperateTextFade, BrowserTextHit ) );
						else if ( ShowBasisOverlayForBackground )//!BasisOverlaySeperateBackgroundFade
							transparencySlider.set( basisPRColor );
						fxColor = transparencySlider.ToFXColor();
						if ( BackgroundColorOverlay && !BasisOverlaySeperateBackgroundFade )
							transparencySlider.CombineColors( fxColor, BackgroundColorToOverlay );//transparencySlider.set( independentTextBackgroundColorPasser.IndependentTextBackgroundColorPasserFunction ( fxColor, TextColorToOverlay, BackgroundColorToOverlay, BackgroundColorOverlay, TextColorOverlay, BrowserTextHit ) );
						
						return transparencySlider.ToFXColor();
					}
					else if ( ShowBasisOverlayForBackground )
						transparencySlider.set( basisPRColor );
					return transparencySlider.ToFXColor();
				}
				else// if ( BrowserTextHit )
				{
					if ( ShowBasisOverlayForText )
					{
						tempColor = basisPRColor;
						fxColor = tempColor.invert();
						if ( colorTooSimilarFunction.ColorTooSimilarFunction( fxColor, basisPRColor, ColorDifference ) )
							fxColor = Color.rgb(0,255,0);
						if ( !( TextTransitionFactor > 0.001 && !TextOutlineBlendingToBasisInvert ) )
							transparencySlider.set( fxColor );
						else
							transparencySlider.TransparencySliderFunction( 1, TextTransitionFactor, fxColor, basisPRColor );
						transparencySlider.set( fxColor );
					}
					if ( UseFadeAtAll )
					{
						if ( BasisOverlaySeperateTextFade )//There Can Be Something To Change The Order Of BasisOverlaySeperateTextFade & TextColorOverlay
							transparencySlider.CombineColors( fxColor, BasisOverlaySperateTextColor );//transparencySlider.set( independentTextBackgroundColorPasser.IndependentTextBackgroundColorPasserFunction ( fxColor, BasisOverlaySperateTextColor, BasisOverlaySperateBackgroundColor, BasisOverlaySeperateBackgroundFade, BasisOverlaySeperateTextFade, BrowserTextHit ) );
						else if ( TextColorOverlay )// !BasisOverlaySeperateTextFade )
							transparencySlider.CombineColors( fxColor, TextColorToOverlay );//transparencySlider.set( independentTextBackgroundColorPasser.IndependentTextBackgroundColorPasserFunction ( fxColor, TextColorToOverlay, BackgroundColorToOverlay, BackgroundColorOverlay, TextColorOverlay, BrowserTextHit ) );	
						fxColor = transparencySlider.ToFXColor();
						transparencySlider.TransparencySliderFunction( 1, TextTransitionFactor, fxColor, basisPRColor );
						if ( TextColorOverlay || BasisOverlaySeperateTextFade )
							return transparencySlider.ToFXColor();
					}
					else if ( ShowBasisOverlayForText )
						return transparencySlider.ToFXColor();
					/*else if ( TextTransitionFactor < 0.001 )//&& !ShowBasisOverlayForText )
					{
						fxColor = colorDecide.NextColorDecide( basisPRColor, BackgroundBasisPRColor, transparencySlider.ToFXColor(), BrowserPRColor, InitialColorContrastingChoice, ColorTooSimilarReplacementColor, ColorDifference, SomeTargetColorHitFromDisplayType, SomeTargetColorHit, !BrowserTextHit, NextStepColorTooSimilarEffect, InvertBasisFromBackground, TypeOfDisplayIsBackgroundToBasisFullDisplay );
						transparencySlider.set( fxColor );
						return transparencySlider.ToFXColor();
					}
					else if ( TextOutlineBlendingToBasisInvert )
					{
						fxColor = transparencySlider.ToFXColor();
						transparencySlider.TransparencySliderFunction( 1, TextTransitionFactor, fxColor, basisPRColor );
					}
					fxColor = colorDecide.NextColorDecide( basisPRColor, BackgroundBasisPRColor, transparencySlider.ToFXColor(), BrowserPRColor, InitialColorContrastingChoice, ColorTooSimilarReplacementColor, ColorDifference, SomeTargetColorHitFromDisplayType, SomeTargetColorHit, !BrowserTextHit, NextStepColorTooSimilarEffect, InvertBasisFromBackground, TypeOfDisplayIsBackgroundToBasisFullDisplay );
					//fxColor = colorDecide.ToFXColor();
					if ( TextTransitionFactor > 0.999 )
						transparencySlider.set( basisPRColor );
					else if ( TextTransitionFactor < 0.001 )
						transparencySlider.set( fxColor );
					else if ( !TextOutlineBlendingToBasisInvert )
						//transparencySlider.set( Color.DARKCYAN );
						transparencySlider.TransparencySliderFunction( 1, TextTransitionFactor, fxColor, basisPRColor );
					else
						transparencySlider.set( fxColor );
					return transparencySlider.ToFXColor();// */
				}
			}
		}
		else// if ( !SomeTargetColorHit )
		{
			if ( ( InvertBasisPicture && !BrowserTextHit ) || ( !InvertBasisPicture && BrowserTextHit ) )
			{
				tempColor = basisPRColor;
				fxColor = tempColor.invert();
				if ( colorTooSimilarFunction.ColorTooSimilarFunction( fxColor, basisPRColor, ColorDifference ) )
					fxColor = Color.rgb(0,255,0);
			}
			else if ( BrowserTextHit )
				fxColor = basisPRColor;
			transparencySlider.set( fxColor );
			return transparencySlider.ToFXColor();
		}
		//returnImmediatly = false;//BasisImageStandOutHit && BrowserTextHit && !TextOutlineBlendingToBasisInvert && TextTransitionFactor > 0.01 && TextTransitionFactor < 0.99;
		//if ( returnImmediatly )// || ( basisImageStandOutHit && browserTextHit && !TextOutlineBlendingToBasisInvert && textTransitionFactor > 0.04 && textTransitionFactor < 0.96 ) )
		//{
		//	return transparencySlider.ToFXColor();
		//}
		//fxColor = colorDecide.NextColorDecide( basisPRColor, BackgroundBasisPRColor, transparencySlider.ToFXColor(), BrowserPRColor, InitialColorContrastingChoice, ColorTooSimilarReplacementColor, ColorDifference, SomeTargetColorHitFromDisplayType, SomeTargetColorHit, !BrowserTextHit, NextStepColorTooSimilarEffect, InvertBasisFromBackground, TypeOfDisplayIsBackgroundToBasisFullDisplay );
		//return fxColor;
		/*if ( TextOutlineBlendingToBasisInvert )
		{
			fxColor = transparencySlider.ToFXColor();
			transparencySlider.TransparencySliderFunction( 1, TextTransitionFactor, fxColor, basisPRColor );
		}// */
		/*if ( BrowserTextHit && TextTransitionFactor < 0.001 )// BrowserTextHit Too
			fxColor = colorDecide.NextColorDecide( basisPRColor, BackgroundBasisPRColor, transparencySlider.ToFXColor(), BrowserPRColor, InitialColorContrastingChoice, ColorTooSimilarReplacementColor, ColorDifference, SomeTargetColorHitFromDisplayType, SomeTargetColorHit, !BrowserTextHit, NextStepColorTooSimilarEffect, InvertBasisFromBackground, TypeOfDisplayIsBackgroundToBasisFullDisplay );
		else
			fxColor = transparencySlider.ToFXColor();
		//fxColor = colorDecide.ToFXColor();
		if ( TextTransitionFactor > 0.999 )
			transparencySlider.set( basisPRColor );
		else if ( TextTransitionFactor < 0.001 )
			transparencySlider.set( fxColor );
		else //if ( !TextOutlineBlendingToBasisInvert )
			//transparencySlider.set( Color.DARKCYAN );
			transparencySlider.TransparencySliderFunction( 1, TextTransitionFactor, fxColor, basisPRColor );//fxColor, basisPRColor Flipped Around To Fix Bug
		//else
		//	transparencySlider.set( fxColor );
		return transparencySlider.ToFXColor();// */
		/*fxColor = transparencySlider.ToFXColor();
		if ( TextTransitionFactor > 0.1 )
			transparencySlider.TransparencySliderFunction( 1, TextTransitionFactor, fxColor, basisPRColor );
		return colorDecide.NextColorDecide( basisPRColor, BackgroundBasisPRColor, transparencySlider.ToFXColor(), BrowserPRColor, InitialColorContrastingChoice, ColorTooSimilarReplacementColor, ColorDifference, SomeTargetColorHitFromDisplayType, SomeTargetColorHit, !BrowserTextHit, NextStepColorTooSimilarEffect, InvertBasisFromBackground, TypeOfDisplayIsBackgroundToBasisFullDisplay );*/
		fxColor = transparencySlider.ToFXColor();
		//rainbowSoftColor.set(fxColor);
		return colorDecide.NextColorDecide( basisPRColor, BackgroundBasisPRColor, fxColor, BrowserPRColor, InitialColorContrastingChoice, ColorTooSimilarReplacementColor, ColorDifference, SomeTargetColorHitFromDisplayType, SomeTargetColorHit, !BrowserTextHit, NextStepColorTooSimilarEffect, InvertBasisFromBackground, TypeOfDisplayIsBackgroundToBasisFullDisplay );
	}
}
