@using Entities.Contracts
@using Entities.DTO
@using TechHelper.Client.Exam
@using TechHelper.Client.Pages.Exam.QuestionCard

<MudPaper @onclick:stopPropagation Style="background-color:transparent" Elevation="0">
	<MudPaper Elevation=@Elevation Class=@Class @onclick="HandleClick" Style="@Style">

		<MudStack Row="true" Class="justify-content-between align-content-center" Style="background-color: transparent">
			<MudText Class="justify-content-lg-start" Typo="Typo.h6">@ExamStruct.Title</MudText>
			<MudStack Row="true" Class="align-content-center">
				<MudText Class="ma-auto" Align="Align.Center" Typo="Typo.body2"> Num: @ExamStruct.ChildrenAssignmentQuestion.Count</MudText>
				<MudText Class="ma-auto" Align="Align.Center" Typo="Typo.body2"><b>总分:</b> @ExamStruct.Score 分</MudText>
				<MudToggleIconButton @bind-Toggled="ExamStruct.BCorrect"
									 Icon="@Icons.Material.Filled.Close"
									 Color="@Color.Error"
									 ToggledIcon="@Icons.Material.Filled.Check"
									 ToggledColor="@Color.Success"
									 title="@(ExamStruct.BCorrect ? "On" : "Off")" />

				<MudIconButton Color="Color.Tertiary" Icon="@Icons.Material.Filled.ExpandLess" Size="Size.Small" />
				<MudIconButton Color="Color.Tertiary" Icon="@Icons.Material.Filled.ExpandMore" Size="Size.Small" />
				<MudIconButton Icon="@Icons.Material.Filled.Delete" aria-label="delete" Size="Size.Small" />
				<MudChip T="string" Color="Color.Info" Class="justify-content-end">@ExamStruct.StructType</MudChip>
			</MudStack>
		</MudStack>

		@if (ExamStruct.Question != null)
		{
			<QuestionCard Question="ExamStruct.Question" Index="ExamStruct.Index" Elevation=0 Class="my-2 pa-1 rounded-xl"  />
		}

		@foreach (var examStruct in ExamStruct.ChildrenAssignmentQuestion)
		{
			<ExamStructView ExamStruct="examStruct" ClickedStruct="HandleChildStructClick" Elevation=@(examStruct.Question != null
								 && examStruct.ChildrenAssignmentQuestion.Count == 0 ? 0 : 0) Class="@($"my-2 pa-1 rounded-xl {(examStruct.StructType != AssignmentStructType.Question ? "my-5" : "my-1")}")"
						Style=@(examStruct.StructType switch
	  {
		  AssignmentStructType.Question => "background-color: #ececec",
		  AssignmentStructType.Group => "background-color: #ffffff",
		  AssignmentStructType.Struct => "background-color: #cccccccc",
		  AssignmentStructType.SubQuestion => "background-color: #ffffff",
		  AssignmentStructType.Option => "background-color: #ffffff",
		  _ => "background-color: transparent"
	  }) />
				}

	</MudPaper>
</MudPaper>


@* 						Style=@(examStruct.StructType switch
	  {
		  AssignmentStructType.Question => "background-color: #ffffff",
		  AssignmentStructType.Composite => "background-color: #ececec",
		  AssignmentStructType.Struct => "background-color: #dcdcdc",
		  AssignmentStructType.SubQuestion => "background-color: #ffffff",
		  AssignmentStructType.Option => "background-color: #dddddd",
		  _ => "background-color: transparent"
	  })  *@

@code {
	[Parameter]
	public AssignmentQuestionDto ExamStruct { get; set; } = new AssignmentQuestionDto();

	[Parameter]
	public EventCallback<AssignmentQuestionDto> ClickedStruct { get; set; }

	[Parameter]
	public string Class { get; set; } = "my-2 pa-1";

	[Parameter]
	public int Elevation { get; set; } = 0;

	[Parameter]
	public string Style { get; set; } = "background-color : #eeeeee";

	private async void HandleClick()
	{
		await ClickedStruct.InvokeAsync(ExamStruct);
	}

	private async void HandleChildStructClick(AssignmentQuestionDto clickedChildExamStruct)
	{
		await ClickedStruct.InvokeAsync(clickedChildExamStruct);
	}
}