--==================--
-- Tokyo Night Theme --
--==================--
-- https://github.com/folke/tokyonight.nvim/blob/main/extras/lua/

local moon_palette = {
	bg = "#222436",
	-- bg_dark = "#1e2030",
	-- bg_dark1 = "#191B29",
	bg_highlight = "#2f334d",
	-- bg_visual = "#2d3f76",
	-- black = "#1b1d2b",
	blue = "#82aaff",
	-- blue0 = "#3e68d7",
	-- blue1 = "#65bcff",
	-- blue2 = "#0db9d7",
	-- blue5 = "#89ddff",
	-- blue6 = "#b4f9f8",
	-- blue7 = "#394b70",
	-- border_highlight = "#589ed7",
	-- comment = "#636da6",
	-- cyan = "#86e1fc",
	-- dark3 = "#545c7e",
	-- dark5 = "#737aa2",
	fg = "#c8d3f5",
	-- fg_dark = "#828bb8",
	-- fg_gutter = "#3b4261",
	green = "#c3e88d",
	-- green1 = "#4fd6be",
	-- green2 = "#41a6b5",
	-- magenta = "#c099ff",
	-- magenta2 = "#ff007c",
	-- orange = "#ff966c",
	-- purple = "#fca7ea",
	red = "#ff757f",
	-- red1 = "#c53b53",
	-- black_bright = "#444a73",
	-- blue_bright = "#9ab8ff",
	-- cyan_bright = "#b2ebff",
	-- green_bright = "#c7fb6d",
	-- magenta_bright = "#caabff",
	-- red_bright = "#ff8d94",
	-- yellow_bright = "#ffd8ab",
	yellow = "#ffc777",
}

local storm_palette = {
	bg = "#24283b",
	-- bg_dark = "#1f2335",
	-- bg_dark1 = "#1b1e2d",
	bg_highlight = "#292e42",
	-- bg_visual = "#2e3c64",
	black = "#1d202f",
	blue = "#7aa2f7",
	-- blue0 = "#3d59a1",
	-- blue1 = "#2ac3de",
	-- blue2 = "#0db9d7",
	-- blue5 = "#89ddff",
	-- blue6 = "#b4f9f8",
	-- blue7 = "#394b70",
	-- border_highlight = "#29a4bd",
	-- comment = "#565f89",
	-- cyan = "#7dcfff",
	-- dark3 = "#545c7e",
	-- dark5 = "#737aa2",
	fg = "#c0caf5",
	-- fg_dark = "#a9b1d6",
	-- fg_gutter = "#3b4261",
	green = "#9ece6a",
	-- green1 = "#73daca",
	-- green2 = "#41a6b5",
	-- magenta = "#bb9af7",
	-- magenta2 = "#ff007c",
	-- orange = "#ff9e64",
	-- purple = "#9d7cd8",
	red = "#f7768e",
	-- red1 = "#db4b4b",
	-- teal = "#1abc9c",
	-- black_bright = "#414868",
	-- blue_bright = "#8db0ff",
	-- cyan_bright = "#a4daff",
	-- green_bright = "#9fe044",
	-- magenta_bright = "#c7a9ff",
	-- red_bright = "#ff899d",
	-- yellow_bright = "#faba4a",
	yellow = "#e0af68",
}

local night_palette = {
	bg = "#1a1b26",
	-- bg_dark = "#16161e",
	-- bg_dark1 = "#0C0E14",
	bg_highlight = "#292e42",
	-- bg_visual = "#283457",
	-- black = "#15161e",
	blue = "#7aa2f7",
	-- blue0 = "#3d59a1",
	-- blue1 = "#2ac3de",
	-- blue2 = "#0db9d7",
	-- blue5 = "#89ddff",
	-- blue6 = "#b4f9f8",
	-- blue7 = "#394b70",
	-- border_highlight = "#27a1b9",
	-- comment = "#565f89",
	-- cyan = "#7dcfff",
	-- dark3 = "#545c7e",
	-- dark5 = "#737aa2",
	fg = "#c0caf5",
	-- fg_dark = "#a9b1d6",
	-- fg_gutter = "#3b4261",
	green = "#9ece6a",
	-- green1 = "#73daca",
	-- green2 = "#41a6b5",
	-- magenta = "#bb9af7",
	-- magenta2 = "#ff007c",
	-- orange = "#ff9e64",
	-- purple = "#9d7cd8",
	red = "#f7768e",
	-- red1 = "#db4b4b",
	-- black_bright = "#414868",
	-- blue_bright = "#8db0ff",
	-- cyan_bright = "#a4daff",
	-- green_bright = "#9fe044",
	-- magenta_bright = "#c7a9ff",
	-- red_bright = "#ff899d",
	-- yellow_bright = "#faba4a",
	yellow = "#e0af68",
}

local day_palette = {
	bg = "#e1e2e7",
	-- bg_dark = "#d0d5e3",
	-- bg_dark1 = "#c1c9df",
	bg_highlight = "#c4c8da",
	-- bg_visual = "#b7c1e3",
	-- black = "#b4b5b9",
	blue = "#2e7de9",
	-- blue0 = "#7890dd",
	-- blue1 = "#188092",
	-- blue2 = "#07879d",
	-- blue5 = "#006a83",
	-- blue6 = "#2e5857",
	-- blue7 = "#92a6d5",
	-- border_highlight = "#4094a3",
	-- comment = "#848cb5",
	-- cyan = "#007197",
	-- dark3 = "#8990b3",
	-- dark5 = "#68709a",
	fg = "#3760bf",
	-- fg_dark = "#6172b0",
	-- fg_gutter = "#a8aecb",
	green = "#587539",
	-- green1 = "#387068",
	-- green2 = "#38919f",
	-- magenta = "#9854f1",
	-- magenta2 = "#d20065",
	-- orange = "#b15c00",
	-- purple = "#7847bd",
	red = "#f52a65",
	-- red1 = "#c64343",
	-- black_bright = "#a1a6c5",
	-- blue_bright = "#358aff",
	-- cyan_bright = "#007ea8",
	-- green_bright = "#5c8524",
	-- magenta_bright = "#a463ff",
	-- red_bright = "#ff4774",
	-- yellow_bright = "#a27629",
	yellow = "#8c6c3e",
}

--- Gets the Tokyo Night theme.
--- @param flavor string Flavor of the theme: "night".
--- @return table theme Used in Yatline.
local function tokyo_night_theme(flavor)
	local palettes = {
		moon = moon_palette,
		storm = storm_palette,
		night = night_palette,
		day = day_palette,
	}

	local palette = palettes[flavor] or night_palette

	return {
		section_separator_open = "",
		section_separator_close = "",

		inverse_separator_open = "",
		inverse_separator_close = "",

		part_separator_open = "|",
		part_separator_close = "|",

		style_a = {
			fg = palette.bg,
			bg_mode = {
				normal = palette.blue,
				select = palette.yellow,
				un_set = palette.red,
			},
		},
		style_b = { bg = palette.bg_highlight, fg = palette.fg },
		style_c = { bg = palette.bg, fg = palette.fg },

		permissions_t_fg = palette.blue,
		permissions_r_fg = palette.yellow,
		permissions_w_fg = palette.red,
		permissions_x_fg = palette.green,
		permissions_s_fg = palette.fg,

		selected = { icon = "󰻭", fg = palette.yellow },
		copied = { icon = "", fg = palette.green },
		cut = { icon = "", fg = palette.red },

		total = { icon = "", fg = palette.yellow },
		succ = { icon = "", fg = palette.green },
		fail = { icon = "", fg = palette.red },
		found = { icon = "", fg = palette.blue },
		processed = { icon = "", fg = palette.green },
	}
end

return {
	setup = function(_, args)
		args = args or "night"

		return tokyo_night_theme(args)
	end,
}
