UI/ToolInfo/ToolInfoPanel.razor
@using Sandbox;
@using Sandbox.UI;
@inherits PanelComponent
@namespace Sandbox

@if ( !Hud.IsVisible( HudElement.ToolInfo ) )
    return;

@if ( !HasAnyAction )
    return;

<root>
 <div class="name">
  <span class="icon">@InfoIcon</span>
  <span>@Info?.Name</span>
 </div>

 <div class="panel">

  @if ( !string.IsNullOrEmpty( Info?.Description ) )
  {
   <div class="description">@Info.Description</div>
  }

  <div class="actions">
   @if (!string.IsNullOrEmpty(Info?.PrimaryAction))
   {
    <div class="action">
     <InputHint Action="attack1" class="key" />
     <span class="text">@Info.PrimaryAction</span>
    </div>
   }
   @if (!string.IsNullOrEmpty(Info?.SecondaryAction))
   {
    <div class="action">
     <InputHint Action="attack2" class="key" />
     <span class="text">@Info.SecondaryAction</span>
    </div>
   }
   @if (!string.IsNullOrEmpty(Info?.ReloadAction))
   {
    <div class="action">
     <InputHint Action="reload" class="key" />
     <span class="text">@Info.ReloadAction</span>
    </div>
   }
  </div>
 </div>
</root>

@code
{
	IToolInfo CurrentToolInfo
	{
		get
		{
			var inv = Player?.GetComponent<PlayerInventory>();
			
			if ( !inv.IsValid() || !inv.ActiveWeapon.IsValid() )
				return null;
			
			if ( inv.ActiveWeapon.GetComponentInChildren<IToolInfo>() is { IsValid: true } toolInfo )
				return toolInfo;

			return inv?.ActiveWeapon as IToolInfo;
		}
	}

	Player Player => Player.FindLocalPlayer();

	IToolInfo Info => CurrentToolInfo;
	string InfoIcon => Info is null ? "build" : Game.TypeLibrary.GetType( Info.GetType() )?.Icon ?? "build";

	bool HasAnyAction => !string.IsNullOrEmpty( Info?.PrimaryAction )
	                     || !string.IsNullOrEmpty( Info?.SecondaryAction )
	                     || !string.IsNullOrEmpty( Info?.ReloadAction );

	protected override void OnUpdate()
	{
		SetClass( "visible", CurrentToolInfo is not null );
	}

	protected override int BuildHash() => System.HashCode.Combine( Info?.Name, InfoIcon, Info?.Description, Info?.PrimaryAction, Info?.SecondaryAction, Info?.ReloadAction, Hud.IsVisible( HudElement.ToolInfo ) );
}