import { VerticalBox, CheckBox } from "std-widgets.slint";
import { VButton, VText, VTextInput, Palette } from "@selenite";

export struct ModifySourceParam {
	id: int,
	name: string,
	path: string
}

export component EditSourceWindow inherits Window {
	in-out property <int> id;
	in-out property name <=> nameInput.text;
	in-out property path <=> pathInput.text;

	title: "Mirai - Edit source";
	min-height: 100px;
	max-height: 4000px; // needed, otherwise the window wants to fit the content (on Swaywm)
	min-width: 400px;
	background: Palette.background;

	callback modify-source(ModifySourceParam);
	callback delete-source(int);

    VerticalLayout {
		padding: 16px;
		spacing: 8px;
		nameInput := VTextInput {
			label: "Name";
		}
		pathInput := VTextInput {
			label: "Path";
		}
		VButton {
			text: "Save";
			clicked => { 
				root.modify-source({
					id: root.id,
					name: nameInput.text,
					path: pathInput.text
		  		})
			}
		}
		VButton {
			text: "Delete";
			background-color: Palette.red;
			double-clicked => { 
				root.delete-source(root.id)
			}
		}
     }
}

export { Palette } // Export to make it visible to the C++ backend
