package com.ecep.contract.controller.employee;

import java.time.LocalDate;

import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.ecep.contract.constant.CloudServiceConstant;
import com.ecep.contract.controller.AbstManagerWindowController;
import com.ecep.contract.model.Department;
import com.ecep.contract.model.Employee;
import com.ecep.contract.service.EmployeeService;
import com.ecep.contract.task.EmployeesSyncTask;
import com.ecep.contract.util.FxmlPath;
import com.ecep.contract.util.UITools;
import com.ecep.contract.vm.EmployeeViewModel;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.CheckBox;
import javafx.scene.control.TableColumn;
import javafx.stage.Stage;

@Lazy
@Scope("prototype")
@Component
@FxmlPath("/ui/employee/employee-manager.fxml")
public class EmployeeManagerWindowController
        extends AbstManagerWindowController<Employee, EmployeeViewModel, EmployeeManagerSkin> {

    @FXML
    public TableColumn<EmployeeViewModel, Number> idColumn;
    @FXML
    public TableColumn<EmployeeViewModel, String> accountColumn;
    @FXML
    public TableColumn<EmployeeViewModel, Department> departmentColumn;
    @FXML
    public TableColumn<EmployeeViewModel, String> nameColumn;
    @FXML
    public TableColumn<EmployeeViewModel, String> aliasColumn;
    @FXML
    public TableColumn<EmployeeViewModel, String> codeColumn;
    @FXML
    public TableColumn<EmployeeViewModel, String> emailColumn;
    @FXML
    public TableColumn<EmployeeViewModel, LocalDate> createdColumn;
    @FXML
    public TableColumn<EmployeeViewModel, LocalDate> entryDateColumn;
    @FXML
    public TableColumn<EmployeeViewModel, LocalDate> leaveDateColumn;
    @FXML
    public TableColumn<EmployeeViewModel, Boolean> activeColumn;
    @FXML
    public CheckBox activeCheckBox;

    @Override
    public void show(Stage stage) {
        super.show(stage);
        getTitle().set("员工管理");
    }

    @Override
    protected EmployeeManagerSkin createDefaultSkin() {
        return new EmployeeManagerSkin(this);
    }

    /**
     * 从 U8系统 同步员工数据
     */
    public void onSyncFromU8Action(ActionEvent event) {
       EmployeesSyncTask task = new EmployeesSyncTask();
        UITools.showTaskDialogAndWait("从 " + CloudServiceConstant.U8_NAME + " 同步员工数据", task, null);
    }


    public void onBaseTableRefreshAction(ActionEvent event) {
        getSkin().loadTableDataSet(true);
    }

    public void onCreateNewAction(ActionEvent event) {
        getSkin().onTableCreateNewAction(event);
    }

    @Override
    public EmployeeService getViewModelService() {
        return getEmployeeService();
    }
}
