using CMSMicroservice.Protobuf.Protos.UserOrder;
using FrontOffice.Main.Utilities;
using Microsoft.AspNetCore.Components;
using Messages = CMSMicroservice.Protobuf.Protos;

namespace FrontOffice.Main.Pages.Store;

public partial class OrderDetail : ComponentBase
{
    [Inject] private OrderService OrderService { get; set; } = default!;

    [Parameter] public long id { get; set; }

    private GetUserOrderResponse? _order;
    private bool _loading;

    protected override async Task OnParametersSetAsync()
    {
        _loading = true;
        _order = await OrderService.GetOrderAsync(id);
        _loading = false;
    }

    private static string FormatPrice(long price) => string.Format("{0:N0} تومان", price);

    private string GetStatusText(Messages.PaymentStatus orderPaymentStatus)
    {
        return orderPaymentStatus switch
        {
            Messages.PaymentStatus.Pending => "در انتظار پرداخت",
            Messages.PaymentStatus.Success => "پرداخت شده",
            Messages.PaymentStatus.Reject => "پرداخت ناموفق",
            _ => "نامشخص",
        };
    }

    private string GetPaymentMethodText(Messages.PaymentMethod orderPaymentMethod)
    {
        return orderPaymentMethod switch
        {
            Messages.PaymentMethod.Wallet => "کیف پول",
            Messages.PaymentMethod.Ipg => "درگاه پرداخت اینترنتی",
            _ => "نامشخص",
        };
    }

    private static string GetProductImageUrl(string? imageUrl)
        => string.IsNullOrWhiteSpace(imageUrl) ? "/images/product-placeholder.svg" : imageUrl.TrimStart('/');
}
