package com.ecep.contract.controller.permission;

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.controller.AbstEntityController;
import com.ecep.contract.model.EmployeeRole;
import com.ecep.contract.service.EmployeeRoleService;
import com.ecep.contract.service.PermissionService;
import com.ecep.contract.util.FxmlPath;
import com.ecep.contract.vm.EmployeeRoleViewModel;

import javafx.fxml.FXML;
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.TextField;
import javafx.scene.layout.BorderPane;
import javafx.stage.Window;
import javafx.stage.WindowEvent;


@Lazy
@Scope("prototype")
@Component
@FxmlPath("/ui/employee/role.fxml")
public class EmployeeRoleWindowController extends AbstEntityController<EmployeeRole, EmployeeRoleViewModel> {
    private static final Logger logger = LoggerFactory.getLogger(EmployeeRoleWindowController.class);


    public static void show(EmployeeRoleViewModel viewModel, Window window) {
        show(EmployeeRoleWindowController.class, viewModel, window);
    }

    public BorderPane root;
    public TabPane tabPane;

    /*

     */
    public Tab baseInfoTab;
    public TextField nameField;
    public TextField codeField;
    public CheckBox systemAdministratorField;
    public CheckBox managerField;
    public DatePicker createdField;
    @FXML
    public CheckBox activeField;
    public Label versionLabel;
    /*

     */
    public Tab functionsTab;
    public ListSelectionView<com.ecep.contract.model.Function> functionsField;

    /*

     */
    public Tab permissionsTab;


    @Autowired
    PermissionService permissionService;
    @Autowired
    EmployeeRoleService employeeRoleService;

    @Override
    public void onShown(WindowEvent windowEvent) {
        super.onShown(windowEvent);
        getTitle().bind(viewModel.getName().map(name -> "[" + viewModel.getId().get() + "] " + name + " 角色详情"));
    }

    @Override
    protected void registerTabSkins() {
        registerTabSkin(baseInfoTab, tab -> new EmployeeRoleTabSkinBase(this));
        registerTabSkin(functionsTab, tab -> new EmployeeRoleTabSkinFunctions(this));
    }

    @Override
    public EmployeeRoleService getViewModelService() {
        return employeeRoleService;
    }
}
