-- Everforest Dark Theme for Lumacs
-- Enhanced version with rich styling using all available face attributes
-- Defined in Lua using the theme API

local theme = editor:create_and_register_theme("everforest-dark")

-- Everforest color palette (expanded)
local bg0 = lumacs.Color(45, 49, 48)          -- #2d3130
local bg1 = lumacs.Color(52, 56, 56)          -- #343838  
local bg2 = lumacs.Color(58, 62, 62)          -- #3a3e3e
local fg  = lumacs.Color(211, 198, 170)       -- #d3c6aa

-- Syntax colors
local red     = lumacs.Color(230, 126, 128)   -- #e67e80
local orange  = lumacs.Color(230, 152, 117)   -- #e69875
local yellow  = lumacs.Color(219, 188, 127)   -- #dbbc7f
local green   = lumacs.Color(167, 192, 128)   -- #a7c080
local cyan    = lumacs.Color(131, 192, 146)   -- #83c092
local blue    = lumacs.Color(125, 174, 163)   -- #7fbbb3
local purple  = lumacs.Color(208, 135, 162)   -- #d699b5
local grey    = lumacs.Color(146, 131, 116)   -- #928374

-- Lighter variants
local red_light   = lumacs.Color(240, 146, 148)
local green_light = lumacs.Color(187, 212, 148)
local blue_light  = lumacs.Color(145, 194, 183)

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

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

-- Text syntax elements
theme:set_color(lumacs.ThemeElement.Keyword, red, bg0)
theme:set_color(lumacs.ThemeElement.String, green, bg0)
theme:set_color(lumacs.ThemeElement.Comment, grey, bg0)
theme:set_color(lumacs.ThemeElement.Function, blue, bg0)
theme:set_color(lumacs.ThemeElement.Type, yellow, bg0)
theme:set_color(lumacs.ThemeElement.Number, purple, bg0)
theme:set_color(lumacs.ThemeElement.Constant, orange, bg0)
theme:set_color(lumacs.ThemeElement.Variable, cyan, bg0)
theme:set_color(lumacs.ThemeElement.Builtin, purple, bg0)
theme:set_color(lumacs.ThemeElement.Preprocessor, orange, bg0)
theme:set_color(lumacs.ThemeElement.Operator, red, bg0)
theme:set_color(lumacs.ThemeElement.Error, lumacs.Color(255, 255, 255), red)
theme:set_color(lumacs.ThemeElement.Warning, bg0, orange)

-- UI elements
theme:set_color(lumacs.ThemeElement.StatusLine, bg0, fg)
theme:set_color(lumacs.ThemeElement.StatusLineInactive, grey, bg1)
theme:set_color(lumacs.ThemeElement.MessageLine, fg, bg0)
theme:set_color(lumacs.ThemeElement.LineNumber, grey, bg0)
theme:set_color(lumacs.ThemeElement.LineNumberCurrent, yellow, bg0)
theme:set_color(lumacs.ThemeElement.Cursor, bg0, fg)
theme:set_color(lumacs.ThemeElement.Selection, lumacs.Color(255, 255, 255), blue)
theme:set_color(lumacs.ThemeElement.SearchMatch, bg0, yellow)
theme:set_color(lumacs.ThemeElement.SearchFail, lumacs.Color(255, 255, 255), red)
theme:set_color(lumacs.ThemeElement.MatchParen, bg0, green_light)

-- Minibuffer elements
theme:set_color(lumacs.ThemeElement.MinibufferPrompt, cyan, bg0)
theme:set_color(lumacs.ThemeElement.MinibufferInput, fg, bg1)
theme:set_color(lumacs.ThemeElement.MinibufferCompletion, fg, bg1)
theme:set_color(lumacs.ThemeElement.MinibufferMatch, bg0, blue)

-- Window elements
theme:set_color(lumacs.ThemeElement.WindowBorder, grey, bg0)
theme:set_color(lumacs.ThemeElement.WindowBorderActive, cyan, bg0)
theme:set_color(lumacs.ThemeElement.WindowSeparator, grey, bg0)
theme:set_color(lumacs.ThemeElement.TabLine, grey, bg1)
theme:set_color(lumacs.ThemeElement.TabLineSel, fg, green)

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

-- Base default face
local default_face = lumacs.FaceAttributes()
default_face.foreground = fg
default_face.background = bg0
default_face.family = "Fira 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 (bold, red)
local keyword_face = lumacs.FaceAttributes()
keyword_face.foreground = red
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 (grey, italic, lighter weight)
local comment_face = lumacs.FaceAttributes()
comment_face.foreground = grey
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 (yellow, bold)
local type_face = lumacs.FaceAttributes()
type_face.foreground = yellow
type_face.weight = lumacs.FontWeight.Bold
type_face.inherit = "default"
theme:set_face("font-lock-type-face", type_face)

-- Variables (cyan, normal)
local variable_face = lumacs.FaceAttributes()
variable_face.foreground = cyan
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 (purple, bold)
local builtin_face = lumacs.FaceAttributes()
builtin_face.foreground = purple
builtin_face.weight = lumacs.FontWeight.Bold
builtin_face.inherit = "default"
theme:set_face("font-lock-builtin-face", builtin_face)

-- Preprocessor (orange, bold, underline)
local preprocessor_face = lumacs.FaceAttributes()
preprocessor_face.foreground = orange
preprocessor_face.weight = lumacs.FontWeight.Bold
preprocessor_face.underline = true
preprocessor_face.inherit = "default"
theme:set_face("font-lock-preprocessor-face", preprocessor_face)

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

-- Mode line (status bar) - bold, inverted
local modeline_face = lumacs.FaceAttributes()
modeline_face.foreground = bg0
modeline_face.background = fg
modeline_face.weight = lumacs.FontWeight.Bold
modeline_face.family = "Sans"
modeline_face.height = 100
theme:set_face("mode-line", modeline_face)

-- Inactive mode line
local modeline_inactive_face = lumacs.FaceAttributes()
modeline_inactive_face.foreground = grey
modeline_inactive_face.background = bg1
modeline_inactive_face.weight = lumacs.FontWeight.Normal
modeline_inactive_face.inherit = "mode-line"
theme:set_face("mode-line-inactive", modeline_inactive_face)

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

-- Line numbers (grey, small)
local line_number_face = lumacs.FaceAttributes()
line_number_face.foreground = grey
line_number_face.background = bg0
line_number_face.family = "Fira Code"
line_number_face.height = 90  -- Smaller than main text
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 = yellow
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 = bg0
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 (blue background, bold)
local region_face = lumacs.FaceAttributes()
region_face.foreground = lumacs.Color(255, 255, 255)
region_face.background = blue
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 = bg0
isearch_face.background = yellow
isearch_face.weight = lumacs.FontWeight.Bold
theme:set_face("isearch", isearch_face)

-- Failed search (red background, bold)
local isearch_fail_face = lumacs.FaceAttributes()
isearch_fail_face.foreground = lumacs.Color(255, 255, 255)
isearch_fail_face.background = red
isearch_fail_face.weight = lumacs.FontWeight.Bold
isearch_fail_face.underline = true
theme:set_face("isearch-fail", isearch_fail_face)

-- === ERROR AND WARNING FACES ===

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

-- Warning (orange, bold)
local warning_face = lumacs.FaceAttributes()
warning_face.foreground = orange
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)

-- === WINDOW AND UI ELEMENTS ===

-- Window borders
local window_divider_face = lumacs.FaceAttributes()
window_divider_face.foreground = grey
window_divider_face.background = bg0
theme:set_face("window-divider", window_divider_face)

-- Active window border (highlighted)
local window_divider_active_face = lumacs.FaceAttributes()
window_divider_active_face.foreground = cyan
window_divider_active_face.background = bg0
window_divider_active_face.weight = lumacs.FontWeight.Bold
theme:set_face("window-divider-active", window_divider_active_face)

-- === COMPLETION AND MINIBUFFER ===

-- Completion candidates
local completion_face = lumacs.FaceAttributes()
completion_face.foreground = fg
completion_face.background = bg1
completion_face.inherit = "default"
theme:set_face("completions-common-part", completion_face)

-- Highlighted completion
local completion_selected_face = lumacs.FaceAttributes()
completion_selected_face.foreground = bg0
completion_selected_face.background = blue
completion_selected_face.weight = lumacs.FontWeight.Bold
theme:set_face("completions-first-difference", completion_selected_face)

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