package org.example.petshopdesktop.controllers.dialogcontrollers;

import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.stage.Stage;
import org.example.petshopdesktop.DTOs.PurchaseOrderDTO;

public class PurchaseOrderDetailsDialogController {

    @FXML private Label lblOrderId;
    @FXML private Label lblSupplier;
    @FXML private Label lblOrderDate;
    @FXML private Label lblStatus;

    private Runnable closeAction;

    public void displayPurchaseOrder(PurchaseOrderDTO order) {
        if (order == null) {
            return;
        }
        lblOrderId.setText(String.valueOf(order.getPurchaseOrderId()));
        lblSupplier.setText(order.getSupplierName() != null ? order.getSupplierName() : "");
        lblOrderDate.setText(order.getOrderDate() != null ? order.getOrderDate() : "");
        lblStatus.setText(order.getStatus() != null ? order.getStatus() : "");
    }

    public void setCloseAction(Runnable closeAction) {
        this.closeAction = closeAction;
    }

    @FXML
    void btnCloseClicked() {
        if (closeAction != null) {
            closeAction.run();
            return;
        }
        Stage stage = (Stage) lblOrderId.getScene().getWindow();
        stage.close();
    }
}
