package view;

import javafx.collections.FXCollections;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.scene.control.cell.PropertyValueFactory;
import model.InventoryReport;
import model.DataManager;
import java.util.List;

public class InventoryReportView extends BorderPane {

    private TableView<InventoryReport> tableView;

    public InventoryReportView() {
        initializeUI();
    }

    private void initializeUI() {
        // 顶部标题区域
        Label titleLabel = new Label("库存报表");
        titleLabel.setStyle("-fx-font-size: 20px; -fx-font-weight: bold;");
        titleLabel.setAlignment(Pos.CENTER);
        setTop(titleLabel);

        // 中间表格区域
        tableView = createTableView();
        setCenter(tableView);

        // 加载库存报表数据
        loadInventoryReportData();
    }

    private TableView<InventoryReport> createTableView() {
        TableView<InventoryReport> table = new TableView<>();

        TableColumn<InventoryReport, String> goodsIdCol = new TableColumn<>("货物编号");
        goodsIdCol.setCellValueFactory(new PropertyValueFactory<>("goodsId"));

        TableColumn<InventoryReport, String> goodsNameCol = new TableColumn<>("货物名称");
        goodsNameCol.setCellValueFactory(new PropertyValueFactory<>("goodsName"));

        TableColumn<InventoryReport, Integer> totalQuantityCol = new TableColumn<>("总数量");
        totalQuantityCol.setCellValueFactory(new PropertyValueFactory<>("totalQuantity"));

        TableColumn<InventoryReport, String> supplierCol = new TableColumn<>("供应商");
        supplierCol.setCellValueFactory(new PropertyValueFactory<>("supplier"));

        TableColumn<InventoryReport, String> remarkCol = new TableColumn<>("备注");
        remarkCol.setCellValueFactory(new PropertyValueFactory<>("remark"));

        table.getColumns().addAll(goodsIdCol, goodsNameCol, totalQuantityCol, supplierCol, remarkCol);

        return table;
    }

    private void loadInventoryReportData() {
        List<InventoryReport> reports = DataManager.generateInventoryReport();
        tableView.setItems(FXCollections.observableArrayList(reports));
    }
}

