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

import com.ecep.contract.util.ProxyUtils;
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.CustomerSatisfactionSurvey;
import com.ecep.contract.model.Project;
import com.ecep.contract.service.CustomerSatisfactionSurveyService;
import com.ecep.contract.service.ProjectService;
import com.ecep.contract.util.FxmlPath;
import com.ecep.contract.vm.CustomerSatisfactionSurveyViewModel;

import javafx.event.ActionEvent;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.Slider;
import javafx.scene.control.Tab;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.stage.WindowEvent;
import lombok.Setter;

@Lazy
@Scope("prototype")
@Component
@FxmlPath("/ui/project/customer-satisfaction-survey.fxml")
public class CustomerSatisfactionSurveyWindowController
        extends AbstEntityController<CustomerSatisfactionSurvey, CustomerSatisfactionSurveyViewModel> {
    public BorderPane root;
    public Tab baseInfoTab;

    public Button importExcelBtn;
    public Button exportExcelBtn;

    public TextField applicantField;
    public TextField applyTimeField;

    public TextField authorizationFileField;
    public Button openAuthorizationFileBtn;
    public Button changeAuthorizationFileBtn;
    public TextArea descriptionField;
    public TextField codeField;
    public TextField dateField;
    public TextField totalScoreField;
    public Slider slider1;
    public Slider slider2;
    public Slider slider3;
    public Slider slider4;
    public Slider slider5;
    public Slider slider6;
    public Slider slider7;
    public Slider slider8;
    public Slider slider9;
    public Slider slider10;
    public Label sliderLabel1;
    public Label sliderLabel2;
    public Label sliderLabel3;
    public Label sliderLabel4;
    public Label sliderLabel5;
    public Label sliderLabel6;
    public Label sliderLabel7;
    public Label sliderLabel8;
    public Label sliderLabel9;
    public Label sliderLabel10;

    CustomerSatisfactionSurveyService getSatisfactionSurveyService() {
        return getCachedBean(CustomerSatisfactionSurveyService.class);
    }

    ProjectService getProjectService() {
        return getCachedBean(ProjectService.class);
    }

    @Override
    public void onShown(WindowEvent windowEvent) {
        super.onShown(windowEvent);
        Project project = viewModel.getProject().get();
        if (!ProxyUtils.isInitialized(project)) {
            project = getProjectService().findById(project.getId());
        }
        getTitle().set("[" + viewModel.getId().get() + "] " + project.getCode() + " 项目客户满意度调查");
    }

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

    @Override
    public CustomerSatisfactionSurveyService getViewModelService() {
        return getSatisfactionSurveyService();
    }

    public void onRefreshAction(ActionEvent event) {
        refreshByButton((Button) event.getSource());
    }
}
