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

<MudDialog DisableSidePadding="true" class="mx-auto">
    <DialogContent>
        <MudStack class="px-4">
            <MudDivider class="-mt-3" />
            <MudStack Spacing="0">

                <MudText Typo="Typo.h6"><b>جست جو از دیجیکالا</b></MudText>
                <MudText Typo="Typo.caption">میتوانید نام کالا را از دیجیکالا جست جو کرده و به فروشگاه اضافه کنید</MudText>
            </MudStack>

            <MudTextField T="string" Placeholder="جست جو بر اساس نام" Adornment="Adornment.Start" Immediate="true"
                          Clearable="true"
                          Variant="Variant.Outlined"
                          ValueChanged="@ViewModel.SearchChanged"
                          AdornmentIcon="@Icons.Material.Filled.Search" IconSize="Size.Medium" class="my-auto"
                          OnAdornmentClick="@ViewModel.SearchAsync"></MudTextField>

            <MudContainer class="h-[35rem]" Style="overflow-y: scroll">
                @if (ViewModel.IsProcessing)
                {
                    <MudProgressCircular class="my-auto" Size="Size.Large" Color="Color.Info" Indeterminate="true" />
                }
                else
                {
                    @foreach (var item in ViewModel.PageDto)
                    {
                        <MudCard Outlined="true" class="my-2">
                            <MudCardContent>
                                <MudStack Row="true">
                                    <MudImage Width="100" Height="100" Class="rounded-lg" Src="@item.MainImage" />
                                    <MudStack>
                                        <MudText Typo="Typo.body1">@item.PersianName</MudText>
                                            <MudText Typo="Typo.body1">@item.EnglishName</MudText>
                                            <MudText Typo="Typo.body2">@item.Summery</MudText>
                                            <MudText Typo="Typo.body2">قیمت : @item.Cost.ToString("N0")</MudText>
                                        </MudStack>
                                    </MudStack>
                                </MudCardContent>
                                <MudCardActions>
                                    <MudButton OnClick="async()=> await ViewModel.AddProductToShopAsync(item.ScraperId)"
                                               Variant="Variant.Outlined"
                                               Color="Color.Success">افزودن به فروشگاه</MudButton>
                                    <a href="@item.ScraperUrl" target="_blank">
                                        <MudButton class="mx-3"
                                                   Variant="Variant.Outlined"
                                                   Color="Color.Warning">مشاهده کالا</MudButton>
                                    </a>
                                </MudCardActions>
                            </MudCard>
                    }
                }


            </MudContainer>
        </MudStack>
    </DialogContent>
    <DialogActions>
        <MudStack Row="true" class="w-full mx-4 mb-2">

            @* <BaseButtonUi class="w-64 rounded-md" IsProcessing="@ViewModel.IsProcessing"
            Icon="@Icons.Material.Outlined.Check"
            Variant="Variant.Filled" Color="Color.Success"
            Content="ثبت ویرایش" OnClickCallback="@ViewModel.SubmitEditAsync" /> *@
            <MudSpacer />
            <MudButton Variant="Variant.Outlined" Size="Size.Large" Color="Color.Error" OnClick="@ViewModel.Cancel">بستن</MudButton>
        </MudStack>
    </DialogActions>
</MudDialog>
@code {

    [CascadingParameter]
    MudDialogInstance MudDialog { get; set; }

    public DigikalaProductActionDialogBoxViewModel ViewModel { get; set; }

    protected override async Task OnInitializedAsync()
    {
        ViewModel = new DigikalaProductActionDialogBoxViewModel(Snackbar, RestWrapper, UserUtility, DialogService, MudDialog);
        await ViewModel.InitializeAsync();
        await base.OnInitializedAsync();
    }
}
