using System.Windows.Forms;

namespace ToyStoreApp;

public sealed partial class OrderDetailsForm : Form
{
    private readonly OrderView _order;

    public OrderDetailsForm(OrderView order)
    {
        _order = order;
        InitializeComponent();
        FillOrder();
    }

    private void CloseButton_Click(object? sender, EventArgs e)
    {
        Close();
    }

    private void FillOrder()
    {
        Text = $"Карточка заказа - {_order.OrderId}";
        articleValueLabel.Text = string.IsNullOrWhiteSpace(_order.Articles) ? "Нет позиций" : _order.Articles;
        statusValueLabel.Text = _order.Status;
        pickupPointValueLabel.Text = _order.PickupPoint;
        orderDateValueLabel.Text = FormatDate(_order.OrderDate);
        deliveryDateValueLabel.Text = FormatDate(_order.DeliveryDate);
        receiveCodeValueLabel.Text = _order.ReceiveCode;
        customerValueLabel.Text = string.IsNullOrWhiteSpace(_order.Customer) ? "Гость" : _order.Customer;
    }

    private static string FormatDate(DateTime? value)
    {
        return value.HasValue ? value.Value.ToString("dd.MM.yyyy") : "Не указана";
    }
}