@using CMSMicroservice.Protobuf.Protos.Commission

<MudDialog>
    <DialogContent>
        @if (Payout != null)
        {
            <MudStack Spacing="3">
                <MudPaper Class="pa-3" Elevation="0">
                    <MudText Typo="Typo.h6" Color="Color.Primary">اطلاعات کاربر</MudText>
                    <MudDivider Class="my-2" />
                    <MudSimpleTable Dense="true">
                        <tbody>
                            <tr>
                                <td><strong>شناسه کاربر:</strong></td>
                                <td>@Payout.UserId</td>
                            </tr>
                            <tr>
                                <td><strong>نام کاربر:</strong></td>
                                <td>@Payout.UserName</td>
                            </tr>
                        </tbody>
                    </MudSimpleTable>
                </MudPaper>

                <MudPaper Class="pa-3" Elevation="0">
                    <MudText Typo="Typo.h6" Color="Color.Primary">جزئیات پرداخت</MudText>
                    <MudDivider Class="my-2" />
                    <MudSimpleTable Dense="true">
                        <tbody>
                            <tr>
                                <td><strong>شناسه پرداخت:</strong></td>
                                <td>@Payout.Id</td>
                            </tr>
                            <tr>
                                <td><strong>شماره هفته:</strong></td>
                                <td>@Payout.WeekDisplayName</td>
                            </tr>
                            <tr>
                                <td><strong>تعداد بالانس:</strong></td>
                                <td>@Payout.BalancesEarned</td>
                            </tr>
                            <tr>
                                <td><strong>ارزش هر بالانس:</strong></td>
                                <td>@Payout.ValuePerBalance.ToString("N0") تومان</td>
                            </tr>
                            <tr>
                                <td><strong>مبلغ کل:</strong></td>
                                <td><strong>@Payout.TotalAmount.ToString("N0") تومان</strong></td>
                            </tr>
                            <tr>
                                <td><strong>وضعیت:</strong></td>
                                <td>
                                    <MudChip T="string" Color="@GetStatusColor(Payout.Status)" Size="Size.Small">
                                        @GetStatusText(Payout.Status)
                                    </MudChip>
                                </td>
                            </tr>
                        </tbody>
                    </MudSimpleTable>
                </MudPaper>

                @if (Payout.WithdrawalMethod != null)
                {
                    <MudPaper Class="pa-3" Elevation="0">
                        <MudText Typo="Typo.h6" Color="Color.Primary">اطلاعات برداشت</MudText>
                        <MudDivider Class="my-2" />
                        <MudSimpleTable Dense="true">
                            <tbody>
                                <tr>
                                    <td><strong>روش برداشت:</strong></td>
                                    <td>@(Payout.WithdrawalMethod.Value == 0 ? "نقدی" : "الماس")</td>
                                </tr>
                                @if (!string.IsNullOrEmpty(Payout.IbanNumber))
                                {
                                    <tr>
                                        <td><strong>شماره شبا:</strong></td>
                                        <td dir="ltr">@Payout.IbanNumber</td>
                                    </tr>
                                }
                            </tbody>
                        </MudSimpleTable>
                    </MudPaper>
                }

                <MudPaper Class="pa-3" Elevation="0">
                    <MudText Typo="Typo.h6" Color="Color.Primary">تاریخچه</MudText>
                    <MudDivider Class="my-2" />
                    <MudSimpleTable Dense="true">
                        <tbody>
                            <tr>
                                <td><strong>تاریخ ایجاد:</strong></td>
                                <td>@Payout.Created.ToDateTime().ToLocalTime().MiladiToJalaliWithTime()</td>
                            </tr>
                            <tr>
                                <td><strong>آخرین ویرایش:</strong></td>
                                @* CMS UserCommissionPayoutModel does not have LastModified - using Created as fallback *@
                                <td>@Payout.Created.ToDateTime().ToLocalTime().MiladiToJalaliWithTime()</td>
                            </tr>
                        </tbody>
                    </MudSimpleTable>
                </MudPaper>
            </MudStack>
        }
    </DialogContent>
    <DialogActions>
        <MudButton Color="Color.Primary" OnClick="Close">بستن</MudButton>
    </DialogActions>
</MudDialog>

@code {
    [CascadingParameter] IMudDialogInstance MudDialog { get; set; }
    [Parameter] public UserCommissionPayoutModel Payout { get; set; }

    private void Close() => MudDialog.Close();

    private Color GetStatusColor(int status) => status switch
    {
        0 => Color.Warning,
        1 => Color.Success,
        2 => Color.Error,
        _ => Color.Default
    };

    private string GetStatusText(int status) => status switch
    {
        0 => "در انتظار",
        1 => "پرداخت شده",
        2 => "شکست خورده",
        _ => "نامشخص"
    };
}
