package com.ecep.contract.controller.project.sale_type;

import java.time.LocalDate;

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.model.ProjectSaleType;
import com.ecep.contract.service.SaleTypeService;
import com.ecep.contract.util.FxmlPath;
import com.ecep.contract.vm.DeliverySignMethodViewModel;
import com.ecep.contract.vm.ProjectSaleTypeViewModel;

import javafx.scene.control.CheckBox;
import javafx.scene.control.DatePicker;
import javafx.scene.control.Label;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import javafx.stage.Window;


@Lazy
@Scope("prototype")
@Component
@FxmlPath("/ui/project/sale-type.fxml")
public class ProjectSaleTypeWindowController
        extends AbstEntityController<ProjectSaleType, ProjectSaleTypeViewModel> {
    private static final Logger logger = LoggerFactory.getLogger(ProjectSaleTypeWindowController.class);


    public static void show(ProjectSaleTypeViewModel viewModel, Window window) {
        show(ProjectSaleTypeWindowController.class, viewModel, window);
    }

    public BorderPane root;
    public TabPane tabPane;

    /*

     */
    public Tab baseInfoTab;
    public TextField nameField;
    public TextField codeField;
    public CheckBox storeByYearField;
    public TextField pathField;
    public DatePicker createdField;
    public VBox criticalProjectBox;
    public CheckBox criticalProjectDecisionField;
    public TextField criticalProjectLimitField;
    public CheckBox activeField;
    public TextArea descriptionField;
    public Label versionLabel;
    /*

     */
    public Tab requireFilesTab;
    public ListSelectionView<ContractFileType> fileTypesField;

    /*

     */
    public Tab signMethodTab;
    public TableView<DeliverySignMethodViewModel> signMethodTable;
    public TableColumn<DeliverySignMethodViewModel, Number> signMethodTable_idColumn;
    public TableColumn<DeliverySignMethodViewModel, String> signMethodTable_codeColumn;
    public TableColumn<DeliverySignMethodViewModel, String> signMethodTable_nameColumn;
    public TableColumn<DeliverySignMethodViewModel, String> signMethodTable_descriptionColumn;
    public TableColumn<DeliverySignMethodViewModel, LocalDate> signMethodTable_createdColumn;

    @Autowired
    protected SaleTypeService saleTypeService;

    @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 ProjectSaleTypeBaseTabSkin(this));
        registerTabSkin(requireFilesTab, tab -> new ProjectSaleTypeRequireFilesTabSkin(this));
        registerTabSkin(signMethodTab, tab -> new SignMethodTabSkin(this));
    }

    @Override
    public SaleTypeService getViewModelService() {
        return saleTypeService;
    }


}
