@inject ISnackbar Snackbar
@inject IRestWrapper RestWrapper
@inject IUserUtility UserUtility
@inject IDialogService DialogService

<MudDialog class="mx-auto">
    <DialogContent>
        <MudStack>
            <MudDivider class="-mt-3" />
            <CommentItemTemplate Comment="Review" />
            <MudGrid class="-ml-5">
                <MudItem sm="11">
                    <MudTextField @bind-Value="ViewModel.AnswerContent" Lines="4" T="string" Label="پاسخ دادن به نظر" Variant="Variant.Outlined"></MudTextField>
                </MudItem>
                <MudItem sm="1">
                    <MudIconButton class="mt-1.5 px-3 py-9"
                                   Icon="@Icons.Material.Outlined.Check"
                                   Variant="Variant.Outlined"
                                   Size="Size.Large"
                                   Color="Color.Info" OnClick="@(async()=>await ViewModel.SubmitAnswer())"></MudIconButton>
                </MudItem>
            </MudGrid>
        </MudStack>
    </DialogContent>
    <DialogActions>
        <MudStack Row="true" class="mx-4 mb-2 w-full">


            <BaseButtonUi class="w-64 rounded-md" IsProcessing="@ViewModel.IsProcessing"
                          Icon="@Icons.Material.Outlined.Check"
                          Variant="Variant.Filled" Color="Color.Success"
                          Content="تایید کردن نظر" />

            <BaseButtonUi class="w-64 rounded-md" IsProcessing="@ViewModel.IsProcessing"
                          Icon="@Icons.Material.Outlined.CommentsDisabled"
                          Variant="Variant.Outlined" Color="Color.Warning"
                          Content="حذف کردن" />

            <MudSpacer />
            <MudButton Variant="Variant.Outlined" Size="Size.Large" Color="Color.Error" OnClick="@(ViewModel.Cancel)">بستن</MudButton>
        </MudStack>
    </DialogActions>
</MudDialog>


@code {

    [CascadingParameter]
    MudDialogInstance MudDialog { get; set; }

    [Parameter]
    public CommentSDto? Review { get; set; }

    public ReviewActionDialogBoxViewModel ViewModel { get; set; }

    protected override async Task OnInitializedAsync()
    {
        if (Review == null)
            ViewModel = new ReviewActionDialogBoxViewModel(Snackbar, RestWrapper, UserUtility, DialogService, MudDialog);
        else
            ViewModel = new ReviewActionDialogBoxViewModel(Snackbar, RestWrapper, UserUtility, DialogService, MudDialog, Review);
        await ViewModel.InitializeAsync();
        await base.OnInitializedAsync();
    }
}
