enum EVehicleBrandState
{
	Default = 0,
	New = 1,
	Selected = 2,
}

class VehicleBrandFilterLogicController extends BaseButtonView
{
	private editable var m_brandLogo : inkImageRef;
	private editable var m_brandText : inkTextRef;
	private var m_brand : CName;
	private var m_brandAsString : String;
	private var m_state : EVehicleBrandState;
	private var m_isHovered : Bool;
	private var m_styleWidget : weak< inkWidget >;
	private var m_newOffers : array< CName >;

	protected event OnInitialize()
	{
		m_styleWidget = this.GetRootWidget();
		m_isHovered = false;
		super.OnInitialize();
	}

	public function SetUp( brand : CName, state : EVehicleBrandState )
	{
		m_brand = brand;
		m_brandAsString = VehicleShopUtils.BrandToTexturePartString( brand );
		inkImageRef.SetTexturePart( m_brandLogo, StringToName( m_brandAsString + "_logo" ) );
		inkTextRef.SetText( m_brandText, GetLocalizedText( VehicleShopUtils.BrandToLocKey( m_brand ) ) );
		UpdateState( state );
	}

	protected override function ButtonStateChanged( oldState : inkEButtonState, newState : inkEButtonState )
	{
		if( newState == inkEButtonState.Hover )
		{
			UpdateState( EVehicleBrandState.Selected );
		}
		else if( oldState == inkEButtonState.Hover )
		{
			UpdateState( EVehicleBrandState.Default );
		}
	}

	public function UpdateState( state : EVehicleBrandState )
	{
		m_state = state;
		RefreshState();
	}

	public function SetHoverState( isHovered : Bool )
	{
		m_isHovered = isHovered;
		if( m_isHovered )
		{
			RefreshState();
		}
		else
		{
			UpdateState( m_state );
		}
	}

	public function RefreshState()
	{
		m_styleWidget.SetState( StateValueToName( m_state ) );
	}

	private function StateValueToName( state : EVehicleBrandState ) : CName
	{
		switch( state )
		{
			case EVehicleBrandState.New:
				return ( ( m_isHovered ) ? ( 'HoverNew' ) : ( 'New' ) );
			case EVehicleBrandState.Selected:
				if( m_isHovered )
				{
					return ( ( HasNewOffers() ) ? ( 'HoverSelectedNew' ) : ( 'HoverSelected' ) );
				}
				else
				{
					return ( ( HasNewOffers() ) ? ( 'SelectedNew' ) : ( 'Selected' ) );
				}
			default:
				return ( ( m_isHovered ) ? ( 'Hover' ) : ( 'Default' ) );
		}
	}

	public function AddNewOffer( offerFact : CName )
	{
		if( !( m_newOffers.Contains( offerFact ) ) )
		{
			m_newOffers.PushBack( offerFact );
		}
	}

	public function RemoveNewOffer( offerFact : CName )
	{
		if( m_newOffers.Contains( offerFact ) )
		{
			m_newOffers.Remove( offerFact );
			if( m_newOffers.Size() == 0 )
			{
				UpdateState( EVehicleBrandState.Selected );
			}
		}
	}

	public function HasNewOffers() : Bool
	{
		return m_newOffers.Size() > 0;
	}

	public function GetBrand() : CName
	{
		return m_brand;
	}

}

