package com.ecep.contract.controller;

import org.controlsfx.control.ToggleSwitch;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.ecep.contract.constant.CloudYuConstant;
import com.ecep.contract.util.BooleanConfig;
import com.ecep.contract.util.FxmlPath;
import com.ecep.contract.util.LocalDateConfig;
import com.ecep.contract.util.LocalDateTimeConfig;
import com.ecep.contract.util.StringConfig;

import javafx.fxml.FXML;
import javafx.scene.control.DatePicker;
import javafx.scene.control.TextField;
import javafx.stage.WindowEvent;

@Lazy
@Scope("prototype")
@Component
@FxmlPath("/ui/cloud/u8_config.fxml")
public class YongYouU8ConfigWindowController extends BaseController {
    @FXML
    private DatePicker auto_create_company_after;

    @FXML
    private TextField contract_latest_date;

    @FXML
    private TextField contract_latest_id;

    @FXML
    private TextField sync_elapse;
    @FXML
    private ToggleSwitch use_latest_id;

    LocalDateConfig config1 = new LocalDateConfig(CloudYuConstant.KEY_AUTO_CREATE_COMPANY_AFTER);
    LocalDateTimeConfig config2 = new LocalDateTimeConfig(CloudYuConstant.KEY_SYNC_BY_LATEST_DATE);
    StringConfig config3 = new StringConfig(CloudYuConstant.KEY_SYNC_BY_LATEST_ID);
    StringConfig config4 = new StringConfig(CloudYuConstant.KEY_SYNC_ELAPSE);
    BooleanConfig config5 = new BooleanConfig(CloudYuConstant.KEY_SYNC_USE_LATEST_ID);

    @Override
    public void onShown(WindowEvent windowEvent) {
        super.onShown(windowEvent);
        getTitle().set("用友U8配置");

        auto_create_company_after.setConverter(getCurrentEmployee().getLocalDateStringConverter());
        config1.setControl(auto_create_company_after);
        config1.initialize();

        config2.setControl(contract_latest_date);
        config2.setControlConverter(getCurrentEmployee().getLocalDateTimeStringConverter());
        config2.initialize();

        config3.setControl(contract_latest_id);
        config3.initialize();

        config4.setControl(sync_elapse);
        config4.initialize();

        config5.setControl(use_latest_id);
        config5.initialize();

    }

}
