class TooltipProgessBarController extends inkLogicController
{
	protected editable var m_progressFill : inkWidgetRef;
	protected editable var m_hintHolder : inkWidgetRef;
	protected editable var m_progressHolder : inkWidgetRef;
	protected editable var m_postprogressHolder : inkWidgetRef;
	protected editable var m_hintTextHolder : inkCompoundRef;
	protected editable var m_libraryPath : inkWidgetLibraryReference;
	protected editable var m_postprogressText : inkTextRef;
	private var m_isCraftable : Bool;
	private var m_isCrafted : Bool;

	public function SetProgressState( craftingMode : CraftingMode, isCraftable : Bool )
	{
		switch( craftingMode )
		{
			case CraftingMode.craft:
				AddButtonHints( 'UI_Apply', "UI-Crafting-hold-to-craft" );
			inkTextRef.SetText( m_postprogressText, "UI-Crafting-Crafted" );
			break;
			case CraftingMode.upgrade:
				AddButtonHints( 'UI_Apply', GetLocalizedText( "LocKey#42735" ) );
			inkTextRef.SetText( m_postprogressText, GetLocalizedText( "LocKey#42735" ) );
			break;
			default:
				break;
		}
		m_isCraftable = isCraftable;
		inkWidgetRef.SetVisible( m_hintHolder, !( m_isCrafted ) && m_isCraftable );
		inkWidgetRef.SetVisible( m_progressHolder, false );
		inkWidgetRef.SetVisible( m_postprogressHolder, m_isCrafted );
		if( m_isCraftable )
		{
			RegisterToGlobalInputCallback( 'OnPostOnHold', this, 'OnHold' );
			RegisterToGlobalInputCallback( 'OnPostOnRelease', this, 'OnRelease' );
		}
	}

	private function AddButtonHints( actionName : CName, const label : ref< String > )
	{
		var buttonHint : LabelInputDisplayController;
		inkCompoundRef.RemoveAllChildren( m_hintTextHolder );
		buttonHint = ( ( LabelInputDisplayController )( SpawnFromExternal( inkCompoundRef.Get( m_hintTextHolder ), inkWidgetLibraryResource.GetPath( m_libraryPath.widgetLibrary ), m_libraryPath.widgetItem ).GetController() ) );
		buttonHint.SetInputActionLabel( actionName, label );
	}

	protected event OnHold( evt : inkPointerEvent )
	{
		var progress : Float;
		progress = evt.GetHoldProgress();
		m_isCrafted = false;
		if( ( ( evt.IsAction( 'craft_item' ) || evt.IsAction( 'click' ) ) && m_isCraftable ) && !( m_isCrafted ) )
		{
			inkWidgetRef.SetVisible( m_hintHolder, false );
			inkWidgetRef.SetVisible( m_progressHolder, true );
			inkWidgetRef.SetVisible( m_postprogressHolder, false );
			inkWidgetRef.SetScale( m_progressFill, Vector2( progress, 1.0 ) );
			if( progress >= 1.0 )
			{
				m_isCrafted = true;
				inkWidgetRef.SetScale( m_progressFill, Vector2( 0.0, 1.0 ) );
				inkWidgetRef.SetVisible( m_progressHolder, false );
				inkWidgetRef.SetVisible( m_hintHolder, !( m_isCrafted ) && m_isCraftable );
				inkWidgetRef.SetVisible( m_postprogressHolder, m_isCrafted );
			}
		}
	}

	protected event OnRelease( evt : inkPointerEvent )
	{
		inkWidgetRef.SetVisible( m_progressHolder, false );
		inkWidgetRef.SetVisible( m_hintHolder, !( m_isCrafted ) && m_isCraftable );
		inkWidgetRef.SetVisible( m_postprogressHolder, m_isCrafted );
		m_isCrafted = false;
	}

	protected event OnUninitialize()
	{
		UnregisterFromGlobalInputCallback( 'OnPostOnHold', this, 'OnHold' );
		UnregisterFromGlobalInputCallback( 'OnPostOnRelease', this, 'OnRelease' );
	}

}

