package com.ecep.contract.controller.vendor;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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.controller.vendor.purchase.order.PurchaseOrderTabSkinBase;
import com.ecep.contract.controller.vendor.purchase.order.PurchaseOrderTabSkinBillVoucher;
import com.ecep.contract.controller.vendor.purchase.order.PurchaseOrderTabSkinItems;
import com.ecep.contract.model.PurchaseOrder;
import com.ecep.contract.service.PurchaseOrdersService;
import com.ecep.contract.util.FxmlPath;
import com.ecep.contract.vm.PurchaseOrderViewModel;

import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.stage.Stage;

@Lazy
@Scope("prototype")
@Component
@FxmlPath("/ui/contract/purchase-orders.fxml")
public class PurchaseOrderWindowController
        extends AbstEntityController<PurchaseOrder, PurchaseOrderViewModel> {
    private static final Logger logger = LoggerFactory.getLogger(PurchaseOrderWindowController.class);
    public TabPane tabPane;
    public Tab baseInfoTab;
    public Tab itemTab;
    public Tab billVoucherTab;


    public TextField refIdField;
    public TextField codeField;
    public TextArea descriptionField;
    public Button saveBtn;

    public TextField employeeField;
    public TextField makerField;
    public TextField makeDateField;
    public TextField verifierField;
    public TextField verifierDateField;
    public TextField modifierField;
    public TextField modifierDateField;
    public TextField closerDateField;
    public TextField closerField;
    public Label versionLabel;

    @Autowired
    private PurchaseOrdersService service;

    @Override
    public void show(Stage stage) {
        super.show(stage);
        getTitle().set("采购订单详情");
    }

    @Override
    protected void registerTabSkins() {
        registerTabSkin(baseInfoTab, tab -> new PurchaseOrderTabSkinBase(this));
        registerTabSkin(itemTab, tab -> new PurchaseOrderTabSkinItems(this));
        registerTabSkin(billVoucherTab, tab -> new PurchaseOrderTabSkinBillVoucher(this));
    }

    PurchaseOrdersService getService() {
        if (service == null) {
            service = getBean(PurchaseOrdersService.class);
        }
        return service;
    }

    @Override
    public PurchaseOrdersService getViewModelService() {
        return getService();
    }
}
