import { Button, DatePickerPopup, Date, Palette } from "std-widgets.slint";
import { VLabeledComponent } from "LabeledComponent.slint";
import { VButton } from "Button.slint";



export component VDatePicker inherits VLabeledComponent {
	in-out property<Date> date;
	in-out property<string> dateDisplay: formatZeroPadding(date.day) + "/" + formatZeroPadding(date.month) + "/" + date.year;

	pure function formatZeroPadding(number: int) -> string {
		if (number < 10) {
			return "0\{number}";
		}
		return number;
	}

	button := VButton {
		text: dateDisplay;
		enabled: root.enabled;
		clicked => { taskDateInput.show() }
	}

	taskDateInput := DatePickerPopup {
		accepted(date) => { root.date = date }
	}
}
