@using NetinaShop.Domain.Entities.Users

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

<MudDialog DisableSidePadding="true" class="mx-auto">
    <DialogContent>
        <MudContainer class="max-h-[30rem]" Style="overflow-y: scroll">
            <MudStack>
                <MudDivider class="-mt-3" />
                <MudStack Spacing="0">

                    <MudText Typo="Typo.h6"><b>اطلاعات کلی</b></MudText>
                    <MudText Typo="Typo.caption">اطلاعات کلی روش ارسال را به دقت وارد کنید</MudText>
                </MudStack>
                <MudGrid>
                    <MudItem sm="12" md="6">
                        <MudTextField T="string" Label="نام" @bind-Value="@ViewModel.PageDto.Name" Variant="Variant.Outlined"></MudTextField>
                    </MudItem>
                    <MudItem sm="12" md="6">
                        <MudTextField T="string" Label="نام انبار" @bind-Value="@ViewModel.PageDto.WarehouseName" Variant="Variant.Outlined"></MudTextField>
                    </MudItem>

                    <MudItem sm="12" md="6">
                        <MudSelect T="bool" @bind-Value="@ViewModel.PageDto.IsExpressShipping" Label="ایا ارسال سریع میباشد ؟" ToStringFunc="b=>b.ToPersianString()" Variant="Variant.Outlined" AnchorOrigin="Origin.BottomCenter">
                            <MudSelectItem T="bool" Value="false" />
                            <MudSelectItem T="bool" Value="true" />
                        </MudSelect>
                    </MudItem>

                    <MudItem sm="12" md="6">
                        <MudTextField T="double" Label="هزینه ارسال" Adornment="Adornment.End" Format="N0" AdornmentText="ریالــ" @bind-Value="@ViewModel.PageDto.DeliveryCost" Variant="Variant.Outlined"></MudTextField>
                    </MudItem>


                    <MudItem sm="12" md="6">
                        <MudSelect T="bool" @bind-Value="@ViewModel.PageDto.IsOriginalWarehouse" Label="ایا ارسال از انبار اصلی میباشد ؟" ToStringFunc="b=>b.ToPersianString()" Variant="Variant.Outlined" AnchorOrigin="Origin.BottomCenter">
                            <MudSelectItem T="bool" Value="false" />
                            <MudSelectItem T="bool" Value="true" />
                        </MudSelect>
                    </MudItem>

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

            @if (ViewModel.IsEditing)
            {
                <BaseButtonUi class="w-64 rounded-md" IsProcessing="@ViewModel.IsProcessing"
                              Icon="@Icons.Material.Outlined.Check"
                              Variant="Variant.Filled" Color="Color.Success"
                              Content="ثبت ویرایش" OnClickCallback="@ViewModel.SubmitEditAsync" />
            }
            else
            {
                <BaseButtonUi class="w-64 rounded-md" IsProcessing="@ViewModel.IsProcessing"
                              Icon="@Icons.Material.Outlined.Check"
                              Variant="Variant.Filled" Color="Color.Success"
                              Content="تایید" OnClickCallback="@ViewModel.SubmitCreateAsync" />
            }
            <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 ShippingSDto? Shipping { get; set; }

    public ShippingActionDialogBoxViewModel ViewModel { get; set; }

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