-- Tokyo Night Theme for Lumacs
-- Enhanced version with rich styling using all available face attributes
-- Based on the popular Tokyo Night color scheme

local theme = editor:create_and_register_theme("tokyo-night")

-- Tokyo Night color palette
local bg          = lumacs.Color(26, 27, 38)     -- #1a1b26
local bg_dark     = lumacs.Color(22, 22, 30)     -- #16161e  
local bg_float    = lumacs.Color(22, 22, 30)     -- #16161e
local bg_highlight = lumacs.Color(40, 42, 56)    -- #292e42
local bg_popup    = lumacs.Color(22, 22, 30)     -- #16161e
local bg_search   = lumacs.Color(61, 89, 161)    -- #3d59a1
local bg_sidebar  = lumacs.Color(22, 22, 30)     -- #16161e
local bg_statusline = lumacs.Color(22, 22, 30)   -- #16161e
local bg_visual   = lumacs.Color(56, 62, 90)     -- #383e5a
local border      = lumacs.Color(22, 22, 30)     -- #16161e
local comment     = lumacs.Color(86, 95, 137)    -- #565f89
local fg          = lumacs.Color(192, 202, 245)  -- #c0caf5
local fg_dark     = lumacs.Color(169, 177, 214)  -- #a9b1d6
local fg_gutter   = lumacs.Color(60, 70, 110)    -- #3c466e

-- Tokyo Night colors
local blue        = lumacs.Color(125, 180, 255)  -- #7dcfff
local blue0       = lumacs.Color(61, 89, 161)    -- #3d59a1
local blue1       = lumacs.Color(44, 82, 130)    -- #2c5282
local blue2       = lumacs.Color(0, 111, 184)    -- #006fb8
local blue5       = lumacs.Color(137, 180, 250)  -- #89b4fa
local blue6       = lumacs.Color(179, 214, 255)  -- #b3d6ff
local blue7       = lumacs.Color(188, 225, 251)  -- #bce1fb
local cyan        = lumacs.Color(125, 207, 255)  -- #7dcfff
local green       = lumacs.Color(158, 206, 106)  -- #9ece6a
local green1      = lumacs.Color(115, 179, 85)   -- #73b755
local green2      = lumacs.Color(65, 166, 181)   -- #41a6b5
local magenta     = lumacs.Color(187, 154, 247)  -- #bb9af7
local magenta2    = lumacs.Color(255, 0, 135)    -- #ff0087
local orange      = lumacs.Color(255, 158, 100)  -- #ff9e64
local purple      = lumacs.Color(159, 120, 255)  -- #9f78ff
local red         = lumacs.Color(247, 118, 142)  -- #f7768e
local red1        = lumacs.Color(219, 75, 75)    -- #db4b4b
local teal        = lumacs.Color(26, 188, 156)   -- #1abc9c
local yellow      = lumacs.Color(224, 175, 104)  -- #e0af68

-- === SET ALL THEME ELEMENTS (Complete theming) ===

-- Special elements (base)
theme:set_color(lumacs.ThemeElement.Background, fg, bg)
theme:set_color(lumacs.ThemeElement.Foreground, fg, bg)
theme:set_color(lumacs.ThemeElement.Normal, fg, bg)

-- Text syntax elements
theme:set_color(lumacs.ThemeElement.Keyword, magenta, bg)
theme:set_color(lumacs.ThemeElement.String, green, bg)
theme:set_color(lumacs.ThemeElement.Comment, comment, bg)
theme:set_color(lumacs.ThemeElement.Function, blue, bg)
theme:set_color(lumacs.ThemeElement.Type, cyan, bg)
theme:set_color(lumacs.ThemeElement.Number, orange, bg)
theme:set_color(lumacs.ThemeElement.Constant, orange, bg)
theme:set_color(lumacs.ThemeElement.Variable, fg, bg)
theme:set_color(lumacs.ThemeElement.Builtin, red, bg)
theme:set_color(lumacs.ThemeElement.Preprocessor, purple, bg)
theme:set_color(lumacs.ThemeElement.Operator, blue5, bg)
theme:set_color(lumacs.ThemeElement.Error, fg, red)
theme:set_color(lumacs.ThemeElement.Warning, bg, yellow)

-- UI elements
theme:set_color(lumacs.ThemeElement.StatusLine, fg, bg_statusline)
theme:set_color(lumacs.ThemeElement.StatusLineInactive, comment, bg_sidebar)
theme:set_color(lumacs.ThemeElement.MessageLine, fg, bg)
theme:set_color(lumacs.ThemeElement.LineNumber, fg_gutter, bg)
theme:set_color(lumacs.ThemeElement.LineNumberCurrent, fg, bg)
theme:set_color(lumacs.ThemeElement.Cursor, bg, fg)
theme:set_color(lumacs.ThemeElement.Selection, fg, bg_visual)
theme:set_color(lumacs.ThemeElement.SearchMatch, bg, yellow)
theme:set_color(lumacs.ThemeElement.SearchFail, fg, red)
theme:set_color(lumacs.ThemeElement.MatchParen, bg, cyan)

-- Minibuffer elements
theme:set_color(lumacs.ThemeElement.MinibufferPrompt, blue, bg)
theme:set_color(lumacs.ThemeElement.MinibufferInput, fg, bg_popup)
theme:set_color(lumacs.ThemeElement.MinibufferCompletion, fg_dark, bg_popup)
theme:set_color(lumacs.ThemeElement.MinibufferMatch, bg, magenta)

-- Window elements
theme:set_color(lumacs.ThemeElement.WindowBorder, border, bg)
theme:set_color(lumacs.ThemeElement.WindowBorderActive, blue, bg)
theme:set_color(lumacs.ThemeElement.WindowSeparator, border, bg)
theme:set_color(lumacs.ThemeElement.TabLine, comment, bg_statusline)
theme:set_color(lumacs.ThemeElement.TabLineSel, fg, blue0)

-- === SYNTAX HIGHLIGHTING FACES (Rich Styling) ===

-- Base default face
local default_face = lumacs.FaceAttributes()
default_face.foreground = fg
default_face.background = bg
default_face.family = "Cascadia Code"
default_face.height = 110  -- 11pt
default_face.weight = lumacs.FontWeight.Normal
default_face.slant = lumacs.FontSlant.Normal
theme:set_face("default", default_face)

-- Keywords (magenta, bold)
local keyword_face = lumacs.FaceAttributes()
keyword_face.foreground = magenta
keyword_face.weight = lumacs.FontWeight.Bold
keyword_face.inherit = "default"
theme:set_face("font-lock-keyword-face", keyword_face)

-- Strings (green, italic)
local string_face = lumacs.FaceAttributes()
string_face.foreground = green
string_face.slant = lumacs.FontSlant.Italic
string_face.inherit = "default"
theme:set_face("font-lock-string-face", string_face)

-- Comments (comment, italic, light)
local comment_face = lumacs.FaceAttributes()
comment_face.foreground = comment
comment_face.slant = lumacs.FontSlant.Italic
comment_face.weight = lumacs.FontWeight.Light
comment_face.inherit = "default"
theme:set_face("font-lock-comment-face", comment_face)

-- Function names (blue, bold)
local function_face = lumacs.FaceAttributes()
function_face.foreground = blue
function_face.weight = lumacs.FontWeight.Bold
function_face.inherit = "default"
theme:set_face("font-lock-function-name-face", function_face)

-- Type names (cyan, bold)
local type_face = lumacs.FaceAttributes()
type_face.foreground = cyan
type_face.weight = lumacs.FontWeight.Bold
type_face.inherit = "default"
theme:set_face("font-lock-type-face", type_face)

-- Variables (fg, normal)
local variable_face = lumacs.FaceAttributes()
variable_face.foreground = fg
variable_face.inherit = "default"
theme:set_face("font-lock-variable-name-face", variable_face)

-- Constants (orange, bold)
local constant_face = lumacs.FaceAttributes()
constant_face.foreground = orange
constant_face.weight = lumacs.FontWeight.Bold
constant_face.inherit = "default"
theme:set_face("font-lock-constant-face", constant_face)

-- Builtin functions (red, bold, underline)
local builtin_face = lumacs.FaceAttributes()
builtin_face.foreground = red
builtin_face.weight = lumacs.FontWeight.Bold
builtin_face.underline = true
builtin_face.inherit = "default"
theme:set_face("font-lock-builtin-face", builtin_face)

-- === UI FACES (Rich Styling) ===

-- Mode line (status bar)
local modeline_face = lumacs.FaceAttributes()
modeline_face.foreground = fg
modeline_face.background = bg_statusline
modeline_face.weight = lumacs.FontWeight.Bold
modeline_face.family = "SF Pro Display"
modeline_face.height = 100
theme:set_face("mode-line", modeline_face)

-- Inactive mode line
local modeline_inactive_face = lumacs.FaceAttributes()
modeline_inactive_face.foreground = comment
modeline_inactive_face.background = bg_sidebar
modeline_inactive_face.inherit = "mode-line"
theme:set_face("mode-line-inactive", modeline_inactive_face)

-- Minibuffer prompt (blue, bold)
local minibuffer_prompt_face = lumacs.FaceAttributes()
minibuffer_prompt_face.foreground = blue
minibuffer_prompt_face.weight = lumacs.FontWeight.Bold
minibuffer_prompt_face.inherit = "default"
theme:set_face("minibuffer-prompt", minibuffer_prompt_face)

-- Line numbers (fg_gutter, small)
local line_number_face = lumacs.FaceAttributes()
line_number_face.foreground = fg_gutter
line_number_face.background = bg
line_number_face.family = "Cascadia Code"
line_number_face.height = 90
line_number_face.weight = lumacs.FontWeight.Light
theme:set_face("line-number", line_number_face)

-- Current line number (highlighted)
local line_number_current_face = lumacs.FaceAttributes()
line_number_current_face.foreground = fg
line_number_current_face.weight = lumacs.FontWeight.Bold
line_number_current_face.inherit = "line-number"
theme:set_face("line-number-current", line_number_current_face)

-- Cursor (inverse, bold)
local cursor_face = lumacs.FaceAttributes()
cursor_face.foreground = bg
cursor_face.background = fg
cursor_face.inverse = true
cursor_face.weight = lumacs.FontWeight.Bold
cursor_face.inherit = "default"
theme:set_face("cursor", cursor_face)

-- Selection/region (bg_visual background)
local region_face = lumacs.FaceAttributes()
region_face.foreground = fg
region_face.background = bg_visual
region_face.weight = lumacs.FontWeight.Bold
theme:set_face("region", region_face)

-- Search matches (yellow background, bold)
local isearch_face = lumacs.FaceAttributes()
isearch_face.foreground = bg
isearch_face.background = yellow
isearch_face.weight = lumacs.FontWeight.Bold
theme:set_face("isearch", isearch_face)

-- Error (red background, bold, underline)
local error_face = lumacs.FaceAttributes()
error_face.foreground = fg
error_face.background = red
error_face.weight = lumacs.FontWeight.Bold
error_face.underline = true
theme:set_face("error", error_face)

-- Warning (yellow, bold)
local warning_face = lumacs.FaceAttributes()
warning_face.foreground = yellow
warning_face.weight = lumacs.FontWeight.Bold
warning_face.inherit = "default"
theme:set_face("warning", warning_face)

-- Success (green, bold)
local success_face = lumacs.FaceAttributes()
success_face.foreground = green
success_face.weight = lumacs.FontWeight.Bold
success_face.inherit = "default"
theme:set_face("success", success_face)

print(string.format("Enhanced theme '%s' loaded with complete Tokyo Night styling.", theme:name()))