-- Ayu Dark Theme for Lumacs
-- Enhanced version with rich styling using all available face attributes
-- Based on the popular Ayu color scheme (Dark variant)

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

-- Ayu Dark color palette
local bg           = lumacs.Color(15, 20, 25)     -- #0f1419
local bg_darker    = lumacs.Color(12, 16, 20)     -- #0c1014
local panel_bg     = lumacs.Color(20, 25, 31)     -- #14191f
local selection_bg = lumacs.Color(33, 42, 51)     -- #212a33
local line_bg      = lumacs.Color(25, 32, 39)     -- #191f27
local guide        = lumacs.Color(42, 54, 66)     -- #2a3642
local comment      = lumacs.Color(92, 99, 112)    -- #5c6370
local fg           = lumacs.Color(230, 225, 207)  -- #e6e1cf
local fg_idle      = lumacs.Color(131, 135, 139)  -- #83878b

-- Ayu colors
local red      = lumacs.Color(242, 151, 142)      -- #f2978a
local orange   = lumacs.Color(255, 160, 102)      -- #ffa066
local yellow   = lumacs.Color(255, 214, 138)      -- #ffd68a
local green    = lumacs.Color(172, 218, 123)      -- #acd67b
local cyan     = lumacs.Color(149, 230, 203)      -- #95e6cb
local blue     = lumacs.Color(115, 186, 255)      -- #73baff
local purple   = lumacs.Color(212, 159, 255)      -- #d49fff
local pink     = lumacs.Color(255, 140, 204)      -- #ff8ccc

-- Additional colors for variety
local dark_red    = lumacs.Color(240, 113, 120)   -- #f07178
local dark_orange = lumacs.Color(255, 140, 77)    -- #ff8c4d
local dark_blue   = lumacs.Color(89, 158, 240)    -- #599ef0
local bright_fg   = lumacs.Color(255, 255, 255)   -- #ffffff

-- === 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, purple, bg)
theme:set_color(lumacs.ThemeElement.String, green, bg)
theme:set_color(lumacs.ThemeElement.Comment, comment, bg)
theme:set_color(lumacs.ThemeElement.Function, yellow, bg)
theme:set_color(lumacs.ThemeElement.Type, cyan, bg)
theme:set_color(lumacs.ThemeElement.Number, orange, bg)
theme:set_color(lumacs.ThemeElement.Constant, blue, bg)
theme:set_color(lumacs.ThemeElement.Variable, fg, bg)
theme:set_color(lumacs.ThemeElement.Builtin, red, bg)
theme:set_color(lumacs.ThemeElement.Preprocessor, pink, bg)
theme:set_color(lumacs.ThemeElement.Operator, orange, bg)
theme:set_color(lumacs.ThemeElement.Error, bright_fg, dark_red)
theme:set_color(lumacs.ThemeElement.Warning, bg, yellow)

-- UI elements
theme:set_color(lumacs.ThemeElement.StatusLine, fg, panel_bg)
theme:set_color(lumacs.ThemeElement.StatusLineInactive, fg_idle, bg_darker)
theme:set_color(lumacs.ThemeElement.MessageLine, fg, bg)
theme:set_color(lumacs.ThemeElement.LineNumber, guide, bg)
theme:set_color(lumacs.ThemeElement.LineNumberCurrent, orange, bg)
theme:set_color(lumacs.ThemeElement.Cursor, bg, orange)
theme:set_color(lumacs.ThemeElement.Selection, fg, selection_bg)
theme:set_color(lumacs.ThemeElement.SearchMatch, bg, yellow)
theme:set_color(lumacs.ThemeElement.SearchFail, bright_fg, dark_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, panel_bg)
theme:set_color(lumacs.ThemeElement.MinibufferCompletion, fg_idle, panel_bg)
theme:set_color(lumacs.ThemeElement.MinibufferMatch, bg, purple)

-- Window elements
theme:set_color(lumacs.ThemeElement.WindowBorder, guide, bg)
theme:set_color(lumacs.ThemeElement.WindowBorderActive, blue, bg)
theme:set_color(lumacs.ThemeElement.WindowSeparator, guide, bg)
theme:set_color(lumacs.ThemeElement.TabLine, fg_idle, panel_bg)
theme:set_color(lumacs.ThemeElement.TabLineSel, fg, dark_blue)

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

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

-- Keywords (purple, bold)
local keyword_face = lumacs.FaceAttributes()
keyword_face.foreground = purple
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 (yellow, bold)
local function_face = lumacs.FaceAttributes()
function_face.foreground = yellow
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 (blue, bold)
local constant_face = lumacs.FaceAttributes()
constant_face.foreground = blue
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 = panel_bg
modeline_face.weight = lumacs.FontWeight.Bold
modeline_face.family = "Helvetica"
modeline_face.height = 100
theme:set_face("mode-line", modeline_face)

-- Inactive mode line
local modeline_inactive_face = lumacs.FaceAttributes()
modeline_inactive_face.foreground = fg_idle
modeline_inactive_face.background = bg_darker
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 (guide, small)
local line_number_face = lumacs.FaceAttributes()
line_number_face.foreground = guide
line_number_face.background = bg
line_number_face.family = "Source Code Pro"
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 = orange
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 = orange
cursor_face.inverse = true
cursor_face.weight = lumacs.FontWeight.Bold
cursor_face.inherit = "default"
theme:set_face("cursor", cursor_face)

-- Selection/region (selection_bg background)
local region_face = lumacs.FaceAttributes()
region_face.foreground = fg
region_face.background = selection_bg
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 = bright_fg
error_face.background = dark_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 Ayu Dark styling.", theme:name()))