local wezterm = require("wezterm")
local config = wezterm.config_builder()

local colors = require("modules/colors")
colors.apply_to_config(config)

config.unix_domains = { { name = "unix" } }
config.default_gui_startup_args = { "connect", "unix" }

config.font = wezterm.font("JetBrainsMono Nerd Font")

config.use_fancy_tab_bar = false
config.tab_bar_at_bottom = true

-- https://github.com/wez/wezterm/issues/5990
config.front_end = "WebGpu"

local act = wezterm.action
local sessionizer = require("modules/sessionizer")
local navigator = require("modules/navigator")

-- timeout_milliseconds defaults to 1000 and can be omitted
config.leader = { key = "b", mods = "CTRL", timeout_milliseconds = 1000 }

config.keys = {
	{ key = "b", mods = "LEADER|CTRL", action = act.ActivateLastTab },
	{ key = "p", mods = "LEADER", action = act.ActivateTabRelative(-1) },
	{ key = "p", mods = "LEADER|CTRL", action = act.ActivateTabRelative(-1) },
	{ key = "n", mods = "LEADER", action = act.ActivateTabRelative(1) },
	{ key = "n", mods = "LEADER|CTRL", action = act.ActivateTabRelative(1) },
	{ key = "s", mods = "LEADER", action = act.ShowLauncherArgs({ flags = "WORKSPACES" }) },

	{ key = "\\", mods = "LEADER", action = act.SplitHorizontal({ domain = "CurrentPaneDomain" }) },
	{ key = "-", mods = "LEADER", action = act.SplitVertical({ domain = "CurrentPaneDomain" }) },
	{ key = "c", mods = "LEADER", action = act.SpawnTab("CurrentPaneDomain") },

	{ key = "a", mods = "LEADER", action = act.AttachDomain("unix") },
	{ key = "d", mods = "LEADER|CTRL", action = act.DetachDomain("CurrentPaneDomain") },

	-- Integration with neovim panes
	-- { key = "h", mods = "CTRL", action = act.EmitEvent("ActivatePaneDirection-left") },
	-- { key = "j", mods = "CTRL", action = act.EmitEvent("ActivatePaneDirection-down") },
	-- { key = "k", mods = "CTRL", action = act.EmitEvent("ActivatePaneDirection-up") },
	-- { key = "l", mods = "CTRL", action = act.EmitEvent("ActivatePaneDirection-right") },

	{ key = "f", mods = "LEADER", action = wezterm.action_callback(sessionizer.toggle) },
}

return config