<MudPaper @onclick:stopPropagation>
	<MudPaper Outlined="false" Elevation="0"
			  @onclick="HandleClick"
			  @onmouseover="HandleMouseOver"
			  @onmouseout="HandleMouseOut">

		@if (IsSelected)
		{

			<MudIconButton Icon="@Icons.Material.Filled.MoveUp" Color="Color.Success" Size="Size.Small" OnClick="HandleMoveUp" />
			<MudIconButton Icon="@Icons.Material.Filled.MoveDown" Color="Color.Success" Size="Size.Small" OnClick="HandleMoveDown" />
			<MudIconButton Icon="@Icons.Material.Filled.Delete" Color="Color.Error" Size="Size.Small" OnClick="HandleDelete" />
		}


		@switch (QuestionElement.QuestionType)
		{
			case BaseQuestionType.Text:
				<Blank IsSelected="IsSelected" QuestionItem="QuestionElement.QuestionItem" />
				break;
			case BaseQuestionType.Radio:
				<RadioChoice IsSelected="IsSelected" QuestionItem="QuestionElement.QuestionItem" />
				break;
		}

	</MudPaper>
</MudPaper>


@code {


	[Parameter]
	public QuestionElement QuestionElement { get; set; }


	[Parameter]
	public bool IsSelected { get; set; }

	[Parameter]
	public EventCallback<int> OnSelected { get; set; }


	[Parameter]
	public EventCallback<int> OnDeleted { get; set; }

	[Parameter]
	public EventCallback<int> MoveUp { get; set; }

	[Parameter]
	public EventCallback<int> MoveDown { get; set; }

	private bool _isHovered = false;

	private async Task HandleDelete()
	{
		await OnDeleted.InvokeAsync(QuestionElement.Index);
	}

	private async Task HandleMoveUp()
	{
		await MoveUp.InvokeAsync(QuestionElement.Index);
	}

	private async Task HandleMoveDown()
	{
		await MoveDown.InvokeAsync(QuestionElement.Index);
	}


	private async Task HandleClick(MouseEventArgs args)
	{
		if (QuestionElement.QuestionItem != null && OnSelected.HasDelegate)
		{

			await OnSelected.InvokeAsync(QuestionElement.Index);
		}
	}


	private void HandleMouseOver()
	{
		_isHovered = true;
		StateHasChanged();
	}

	private void HandleMouseOut()
	{
		_isHovered = false;
		StateHasChanged();
	}

	private void OnCompeli()
	{
		IsSelected = false;
		StateHasChanged();
	}
}
