package com.ecep.contract.util;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

import javafx.beans.property.Property;
import javafx.scene.control.TextField;
import javafx.util.StringConverter;
import javafx.util.converter.LocalDateTimeStringConverter;
import lombok.Getter;
import lombok.Setter;

public class LocalDateTimeConfig extends AbstractConfigBounder<LocalDateTime> {
    @Getter
    @Setter
    private javafx.util.StringConverter<LocalDateTime> controlConverter;

    public LocalDateTimeConfig(String string) {
        super(string);
    }

    @Override
    public TextField getControl() {
        return (TextField) super.getControl();
    }

    @Override
    public javafx.util.StringConverter<LocalDateTime> getConverter() {
        javafx.util.StringConverter<LocalDateTime> converter = super.getConverter();
        if (converter == null) {
            converter = new LocalDateTimeStringConverter(DateTimeFormatter.ISO_LOCAL_DATE_TIME, null);
            setConverter(converter);
        }
        return converter;
    }

    @Override
    void bindBidirectional(Property<LocalDateTime> property) {
        StringConverter<LocalDateTime> converter = getControlConverter();
        if (converter == null) {
            converter = getConverter();
        }
        getControl().textProperty().bindBidirectional(property, converter);
    }
}
