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

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.Project;
import com.ecep.contract.model.ProjectBid;
import com.ecep.contract.service.ProjectBidService;
import com.ecep.contract.service.ProjectService;
import com.ecep.contract.util.FxmlPath;
import com.ecep.contract.vm.ProjectBidViewModel;

import javafx.event.ActionEvent;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.RadioButton;
import javafx.scene.control.Tab;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.stage.WindowEvent;
import lombok.Setter;

@Lazy
@Scope("prototype")
@Component
@FxmlPath("/ui/project/project-bid.fxml")
public class ProjectBidWindowController
        extends AbstEntityController<ProjectBid, ProjectBidViewModel> {
    public BorderPane root;
    public Tab baseInfoTab;

    public Button importExcelBtn;
    public Button exportExcelBtn;

    public TextField applicantField;
    public TextField applyTimeField;
    public TextField authorizerField;
    public TextField authorizationTimeField;
    public HBox levelGroup;
    public RadioButton good_radio_btn;
    public RadioButton bad_radio_btn;
    public RadioButton poor_radio_btn;
    public CheckBox standardPayWayField;
    public TextField noStandardPayWayTextField;
    public TextField amountField;
    public TextField evaluationFileField;
    public Button evaluationFileBtn;

    public TextField authorizationFileField;
    public Button openAuthorizationFileBtn;
    public Button changeAuthorizationFileBtn;
    public TextArea descriptionField;
    public TextField costField;
    public Button costBtn;
    public CheckBox standardContractTextField;
    public TextField noStandardContractTextField;
    public TextField bidAcceptanceLetterFileField;
    public Button openBidAcceptanceLetterFileBtn;
    public Button changeBidAcceptanceLetterFileBtn;

    ProjectBidService getBidService() {
        return getCachedBean(ProjectBidService.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() + " 项目投标");

        exportExcelBtn.setOnAction(this::onExportExcelAction);
    }

    private void onExportExcelAction(ActionEvent event) {
        // ProjectQuotationExportAsExcelFile tasker = new
        // ProjectQuotationExportAsExcelFile();
        // tasker.setQuotation(getEntity());
        // UITools.showTaskDialogAndWait("导出Excel", tasker, null);
    }

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

    @Override
    public ProjectBidService getViewModelService() {
        return getBidService();
    }

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