UI/HeightCalibrationPanel.razor
@using Sandbox;
@using Sandbox.UI;
@inherits PanelComponent
@namespace Sandbox

<root>
	<div class="container">
		<label class="title">Height Calibration</label>
		<label class="instruction">Stand upright, then press Calibrate.</label>

		<div class="height">
			<label class="value">@HeightFeet</label>
			<label class="value">@HeightCentimeters</label>
		</div>

		<div class="buttons">
			<button class="button" onclick="@OnCalibrate">Calibrate</button>
			<button class="button @(CanContinue ? "" : "disabled")" onclick="@OnContinue">Continue</button>
		</div>
	</div>
</root>

@code
{
	private PlayerSession Session { get; set; }

	private bool CanContinue => Session.IsValid() && Session.HasCalibratedHeight;

	private string HeightFeet =>
		Session.IsValid() && Session.HasCalibratedHeight
			? PlayerSession.FormatHeightFeet( Session.StandingEyeHeight )
			: "—";

	private string HeightCentimeters =>
		Session.IsValid() && Session.HasCalibratedHeight
			? PlayerSession.FormatHeightCentimeters( Session.StandingEyeHeight )
			: "—";

	protected override void OnStart()
	{
		Session = GetComponentInParent<VrCalibrationRig>()?.Session
			?? PlayerSession.CurrentSession;
	}

	private void OnCalibrate()
	{
		if ( !Session.IsValid() )
			return;

		Session.CalibrateStandingEyeHeight();
		StateHasChanged();
	}

	private void OnContinue()
	{
		if ( !CanContinue )
			return;

		Session.ConfirmCalibration();
	}

	protected override int BuildHash() => System.HashCode.Combine(
		Session?.HasCalibratedHeight,
		Session?.StandingEyeHeight
	);
}