package com.ecep.contract.controller.vendor.group;

import org.controlsfx.control.ListSelectionView;
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.ContractFileType;
import com.ecep.contract.controller.AbstEntityController;
import com.ecep.contract.util.FxmlPath;
import com.ecep.contract.model.VendorGroup;
import com.ecep.contract.service.VendorGroupService;
import com.ecep.contract.vm.VendorGroupViewModel;

import javafx.scene.control.CheckBox;
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.scene.layout.BorderPane;
import javafx.stage.Stage;
import javafx.stage.Window;

/**
 * 供应商类型窗口控制器
 */
@Lazy
@Scope("prototype")
@Component
@FxmlPath("/ui/company/vendor/group.fxml")
public class VendorGroupWindowController
        extends AbstEntityController<VendorGroup, VendorGroupViewModel> {
    private static final Logger logger = LoggerFactory.getLogger(VendorGroupWindowController.class);



    public static void show(VendorGroupViewModel item, Window owner) {
        show(VendorGroupWindowController.class, item, owner);
    }

    public BorderPane root;
    public TabPane tabPane;


    public Tab baseInfoTab;
    public TextField nameField;
    public TextField codeField;
    public CheckBox priceComparisonField;
    public CheckBox requireQuotationSheetForBidField;
    public TextArea descriptionField;
    public Label versionLabel;
    public CheckBox activeField;


    public Tab requireFilesTab;
    public ListSelectionView<ContractFileType> fileTypesField;

    @Autowired
    VendorGroupService vendorGroupService;

    @Override
    public void show(Stage stage) {
        super.show(stage);
        getTitle().bind(viewModel.getName().map(name -> "[" + viewModel.getId().get() + "] " + name + " 供应商类型详情"));
    }

    @Override
    protected void registerTabSkins() {
        registerTabSkin(baseInfoTab, tab -> new VendorGroupBaseTabSkin(this));
        registerTabSkin(requireFilesTab, tab -> new VendorGroupRequireFilesTabSkin(this));
    }

    @Override
    public VendorGroupService getViewModelService() {
        return vendorGroupService;
    }
}
