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


<MudPaper Elevation="0" Class="rounded-xl" Style="background-color: transparent">
	@* <MudText>@AssignmentQuestion.Id</MudText> *@
	<MudPaper Class="ma-4 pa-5 rounded-xl">
		<MudText Class="mt-3" Typo="Typo.button"><b>包裹器属性</b></MudText>
		<MudTextField @bind-Value="AssignmentQuestion.Title" Label="Title" Variant="Variant.Text" Margin="Margin.Dense" AutoFocus="true" />
		<MudTextField @bind-Value="AssignmentQuestion.Index" Label="Index" Variant="Variant.Text" Adornment="Adornment.End" AdornmentText="." Margin="Margin.Dense" AutoFocus="true" />
		<MudTextField @bind-Value="AssignmentQuestion.Score" Label="Score" Variant="Variant.Text" Adornment="Adornment.End" AdornmentText="." Margin="Margin.Dense" AutoFocus="true" />
		<MudChipSet T="AssignmentStructType" SelectedValue="AssignmentQuestion.StructType" CheckMark SelectionMode="SelectionMode.SingleSelection" SelectedValueChanged="HandleSelectedValueChanged">
			<MudChip Text="pink" Color="Color.Secondary" Value="@AssignmentStructType.Struct">@AssignmentStructType.Struct</MudChip>
			<MudChip Text="purple" Color="Color.Primary" Value="@AssignmentStructType.Group">@AssignmentStructType.Group</MudChip>
			<MudChip Text="blue" Color="Color.Info" Value="@AssignmentStructType.Question">@AssignmentStructType.Question</MudChip>
			<MudChip Text="green" Color="Color.Warning" Value="@AssignmentStructType.SubQuestion">@AssignmentStructType.SubQuestion</MudChip>
			<MudChip Text="orange" Color="Color.Error" Value="@AssignmentStructType.Option">@AssignmentStructType.Option</MudChip>
		</MudChipSet>
	</MudPaper>
	@if (AssignmentQuestion.Question != null)
	{
		<QuestionEdit Question="AssignmentQuestion.Question" />
	}
</MudPaper>


@code {
	[Parameter]
	public AssignmentQuestionDto AssignmentQuestion { get; set; } = new AssignmentQuestionDto();
	public QuestionDto TempQuesdto;
	protected override void OnInitialized()
	{
		base.OnInitialized();
		if (AssignmentQuestion.Question != null)
		{
			TempQuesdto = AssignmentQuestion.Question;
		}
	}

	private void HandleSelectedValueChanged(AssignmentStructType type)
	{
		AssignmentQuestion.StructType = type;
		if (type != AssignmentStructType.Question && AssignmentQuestion.Question != null)
		{
			AssignmentQuestion.Title = AssignmentQuestion.Question.Title;
			AssignmentQuestion.Question = null;
		}

		if (type == AssignmentStructType.Question && AssignmentQuestion.Question == null)
		{
			if (TempQuesdto != null)
			{
				AssignmentQuestion.Question = TempQuesdto;
				if (AssignmentQuestion.Title == AssignmentQuestion.Question.Title)
				{
					AssignmentQuestion.Title = "";
				}
			}
			else
				AssignmentQuestion.Question = new QuestionDto { };
		}
		StateHasChanged();
	}
}
