-- Pull in the wezterm API
local wezterm = require("wezterm")

-- require plugin

local sessionizer = wezterm.plugin.require("https://github.com/mikkasendke/sessionizer.wezterm")

-- initialize module vairable

local module = {}

local edu_schema = {
	options = {
		prompt = "Select a project: ",
	},
	"EDU",
	"default",
	wezterm.home_dir .. "/Polybox_ETH/",
	wezterm.home_dir .. "/Nextcloud/Vault/edu/ETH/hs25/analysis_I",
	wezterm.home_dir .. "/Nextcloud/Vault/edu/ETH/fs26/analysis_II",
	wezterm.home_dir .. "/Nextcloud/Vault/edu/ETH/fs26/informatik_I",
	wezterm.home_dir .. "/Nextcloud/Vault/edu/ETH/fs26/italian",
	wezterm.home_dir .. "/Nextcloud/Vault/edu/ETH/fs26/lineare_algebra_wiederholung",
	wezterm.home_dir .. "/Nextcloud/Vault/edu/ETH/fs26/mathematische_methoden",
	wezterm.home_dir .. "/Nextcloud/Vault/edu/ETH/fs26/nus_II",
	wezterm.home_dir .. "/Nextcloud/Vault/edu/ETH/fs26/physik_I",
	sessionizer.FdSearch({ fd_path = "/opt/homebrew/bin/fd", wezterm.home_dir .. "/Projects/EDU" }),
}

local sw_schema = {
	options = {
		prompt = "Select a project: ",
	},
	"software",
	"default",
	{ label = "JirR02", id = wezterm.home_dir .. "/Projects/JirR02" },
	{ label = "blogwiki", id = wezterm.home_dir .. "/Projects/JR/blogwiki" },
	sessionizer.FdSearch({ fd_path = "/opt/homebrew/bin/fd", wezterm.home_dir .. "/Projects/JR/sw" }),
	sessionizer.FdSearch({ fd_path = "/opt/homebrew/bin/fd", wezterm.home_dir .. "/Projects/Private" }),
	sessionizer.FdSearch({ fd_path = "/opt/homebrew/bin/fd", wezterm.home_dir .. "~/Projects/Public" }),
}

local hw_schema = {
	options = {
		prompt = "Select a project: ",
	},
	"hardware",
	"default",
	wezterm.home_dir .. "/Nextcloud/Vault/maker_space",
	sessionizer.FdSearch({ fd_path = "/opt/homebrew/bin/fd", wezterm.home_dir .. "/Projects/JR/hw" }),
}

local choice = {
	{ label = "EDU", id = "edu" },
	{ label = "JR Software", id = "sw" },
	{ label = "JR Hardware", id = "hw" },
}

-- key map

module.keys = {
	{
		key = "s",
		mods = "LEADER",
		action = wezterm.action_callback(function(window, pane)
			window:perform_action(
				wezterm.action.InputSelector({
					title = "Choose Session Category",
					choices = choice,
					action = wezterm.action_callback(function(inner_window, inner_pane, id, label)
						-- If the user escapes/cancels, do nothing
						if not id then
							return
						end

						-- Select the schema based on the ID chosen
						local selected_schema
						if id == "edu" then
							selected_schema = edu_schema
						elseif id == "sw" then
							selected_schema = sw_schema
						elseif id == "hw" then
							selected_schema = hw_schema
						end

						-- Now trigger the actual sessionizer with the sub-schema
						inner_window:perform_action(sessionizer.show(selected_schema), inner_pane)
					end),
				}),
				pane
			)
		end),
	},
}

return module
