package com.ecep.contract.controller.inventory;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.ecep.contract.controller.AbstEntityController;
import com.ecep.contract.model.Inventory;
import com.ecep.contract.service.InventoryService;
import com.ecep.contract.util.FxmlPath;
import com.ecep.contract.vm.InventoryViewModel;

import javafx.beans.binding.Bindings;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.stage.WindowEvent;

@Lazy
@Scope("prototype")
@Component
@FxmlPath("/ui/inventory/inventory.fxml")
public class InventoryWindowController extends AbstEntityController<Inventory, InventoryViewModel> {
    @FXML
    public BorderPane root;
    @FXML
    public TabPane tabPane;
    @FXML
    public Tab baseInfoTab;
    @FXML
    public Tab historyPriceTab;
    @FXML
    public Tab contractsTab;

    @FXML
    public TextField nameField;
    @FXML
    public CheckBox nameLockField;
    @FXML
    public TextField catalogField;
    @FXML
    public TextField unitField;
    @FXML
    public TextField codeField;
    @FXML
    public TextField specificationField;
    @FXML
    public CheckBox specificationLockField;
    @FXML
    public TextField purchasePriceField;
    @FXML
    public TextField purchaseTaxRateField;
    @FXML
    public TextField purchaseTaxPriceField;
    @FXML
    public TextField creatorField;
    @FXML
    public TextField createTimeField;
    @FXML
    public TextField updaterField;
    @FXML
    public TextField updateDateField;
    @FXML
    public TextField saleTaxRateField;
    @FXML
    public TextField salePriceField;
    @FXML
    public TextField saleTaxPriceField;
    @FXML
    public TextArea descriptionField;
    @FXML
    public Button syncBtn;
    @FXML
    public TextField weightUnitField;
    @FXML
    public TextField sizeUnitField;
    @FXML
    public TextField volumeUnitField;
    @FXML
    public TextField weightField;
    @FXML
    public TextField packagedWeightField;
    @FXML
    public TextField sizeLengthField;
    @FXML
    public TextField sizeWidthField;
    @FXML
    public TextField sizeHeightField;
    @FXML
    public TextField volumeField;
    @FXML
    public TextField packagedSizeLengthField;
    @FXML
    public TextField packagedSizeWidthField;
    @FXML
    public TextField packagedSizeHeightField;
    @FXML
    public TextField packagedVolumeField;

    @Override
    public void onShown(WindowEvent windowEvent) {
        super.onShown(windowEvent);
        getTitle().bind(Bindings.createStringBinding(
                () -> "[" + viewModel.getId().get() + "] 存货详情 " + viewModel.getName().getValue() + " "
                        + viewModel.getSpecification().get(),
                viewModel.getName(), viewModel.getCode(), viewModel.getSpecification()));
        root.getScene().getStylesheets().add("/ui/inventory/inventory.css");
    }

    @Override
    protected void registerTabSkins() {
        registerTabSkin(baseInfoTab, tab -> new InventoryTabSkinBase(this));
        registerTabSkin(historyPriceTab, tab -> new InventoryTabSkinHistoryPrice(this));
        registerTabSkin(contractsTab, tab -> new InventoryTabSkinContracts(this));
    }

    @Override
    public InventoryService getViewModelService() {
        return getCachedBean(InventoryService.class);
    }
}
