import { Button, VerticalBox, CheckBox, Date, ScrollView, ComboBox } from "std-widgets.slint";
import { VPopupIconMenu, VDatePicker, VTimePicker, VCheckBox, VButton, VTag, VText, VTextInput, Svg, Palette } from "@selenite";

export struct TaskEditData {
	title: string,
	date: Date,
}

export component TaskEdit inherits VerticalLayout {
	out property <bool> should-show;
	in property <bool> allow-edit-date;
	in-out property <TaskEditData> task;

	callback accepted(TaskEditData);

	private property <Date> newDate: task.date;

	public function show(task: TaskEditData) {
		root.task = task;
		should-show = true;
	}
	public function close() {
	    should-show = false;
	}

	// Render

	if !should-show : Rectangle {}

	if should-show : Rectangle {
		function modify() {
			root.accepted({
				title: newTaskTitleInput.text,
				date: newDate
			});
		}
		background: Palette.background;
		border-radius: 8px;
		VerticalLayout {
			padding: 16px;
			spacing: 8px;
		
			newTaskTitleInput := VTextInput {
				text: root.task.title;
				accepted => { modify() }
			}
			HorizontalLayout {
				alignment: start;
				spacing: 8px;
				if root.allow-edit-date : taskDateInput := VDatePicker {
					date: task.date;
					enabled: true;
					edited(date) => { newDate = date; }
				}
				VButton {
					text: "Modify";
					icon-svg: Svg.correct;
					icon-colorize: greenyellow;
					clicked => { modify() }
				}
			}
		}
	}
}
