-- Dracula Theme for Lumacs
-- Enhanced version with rich styling using all available face attributes
-- Based on the official Dracula color scheme

local theme = editor:create_and_register_theme("dracula")

-- Dracula color palette
local background = lumacs.Color(40, 42, 54)     -- #282a36
local current    = lumacs.Color(68, 71, 90)     -- #44475a
local selection  = lumacs.Color(68, 71, 90)     -- #44475a
local foreground = lumacs.Color(248, 248, 242)  -- #f8f8f2
local comment    = lumacs.Color(98, 114, 164)   -- #6272a4

-- Dracula colors
local cyan      = lumacs.Color(139, 233, 253)   -- #8be9fd
local green     = lumacs.Color(80, 250, 123)    -- #50fa7b
local orange    = lumacs.Color(255, 184, 108)   -- #ffb86c
local pink      = lumacs.Color(255, 121, 198)   -- #ff79c6
local purple    = lumacs.Color(189, 147, 249)   -- #bd93f9
local red       = lumacs.Color(255, 85, 85)     -- #ff5555
local yellow    = lumacs.Color(241, 250, 140)   -- #f1fa8c

-- Additional colors for variety
local dark_purple = lumacs.Color(139, 97, 199)  -- #8b61c7
local light_bg    = lumacs.Color(50, 52, 64)    -- #323440

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

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

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

-- UI elements
theme:set_color(lumacs.ThemeElement.StatusLine, foreground, dark_purple)
theme:set_color(lumacs.ThemeElement.StatusLineInactive, comment, current)
theme:set_color(lumacs.ThemeElement.MessageLine, foreground, background)
theme:set_color(lumacs.ThemeElement.LineNumber, comment, background)
theme:set_color(lumacs.ThemeElement.LineNumberCurrent, orange, background)
theme:set_color(lumacs.ThemeElement.Cursor, background, foreground)
theme:set_color(lumacs.ThemeElement.Selection, foreground, selection)
theme:set_color(lumacs.ThemeElement.SearchMatch, background, orange)
theme:set_color(lumacs.ThemeElement.SearchFail, foreground, red)
theme:set_color(lumacs.ThemeElement.MatchParen, background, cyan)

-- Minibuffer elements
theme:set_color(lumacs.ThemeElement.MinibufferPrompt, pink, background)
theme:set_color(lumacs.ThemeElement.MinibufferInput, foreground, current)
theme:set_color(lumacs.ThemeElement.MinibufferCompletion, foreground, current)
theme:set_color(lumacs.ThemeElement.MinibufferMatch, background, purple)

-- Window elements
theme:set_color(lumacs.ThemeElement.WindowBorder, current, background)
theme:set_color(lumacs.ThemeElement.WindowBorderActive, purple, background)
theme:set_color(lumacs.ThemeElement.WindowSeparator, current, background)
theme:set_color(lumacs.ThemeElement.TabLine, comment, current)
theme:set_color(lumacs.ThemeElement.TabLineSel, foreground, purple)

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

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

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

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

-- Comments (comment blue, italic, light weight)
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 (green, bold)
local function_face = lumacs.FaceAttributes()
function_face.foreground = green
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 (foreground, normal)
local variable_face = lumacs.FaceAttributes()
variable_face.foreground = foreground
variable_face.inherit = "default"
theme:set_face("font-lock-variable-name-face", variable_face)

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

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

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

-- Numbers (purple, normal)
local number_face = lumacs.FaceAttributes()
number_face.foreground = purple
number_face.inherit = "default"
theme:set_face("font-lock-number-face", number_face)

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

-- Mode line (status bar) - purple background, bold
local modeline_face = lumacs.FaceAttributes()
modeline_face.foreground = foreground
modeline_face.background = dark_purple
modeline_face.weight = lumacs.FontWeight.Bold
modeline_face.family = "Inter"
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 = current
modeline_inactive_face.weight = lumacs.FontWeight.Normal
modeline_inactive_face.inherit = "mode-line"
theme:set_face("mode-line-inactive", modeline_inactive_face)

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

-- Line numbers (comment, small)
local line_number_face = lumacs.FaceAttributes()
line_number_face.foreground = comment
line_number_face.background = background
line_number_face.family = "JetBrains Mono"
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 = 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 = background
cursor_face.background = foreground
cursor_face.inverse = true
cursor_face.weight = lumacs.FontWeight.Bold
cursor_face.inherit = "default"
theme:set_face("cursor", cursor_face)

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

-- Search matches (orange background, bold)
local isearch_face = lumacs.FaceAttributes()
isearch_face.foreground = background
isearch_face.background = orange
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 = foreground
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 = foreground
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 = current
window_divider_face.background = background
theme:set_face("window-divider", window_divider_face)

-- Active window border (highlighted)
local window_divider_active_face = lumacs.FaceAttributes()
window_divider_active_face.foreground = purple
window_divider_active_face.background = background
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 = foreground
completion_face.background = current
completion_face.inherit = "default"
theme:set_face("completions-common-part", completion_face)

-- Highlighted completion
local completion_selected_face = lumacs.FaceAttributes()
completion_selected_face.foreground = background
completion_selected_face.background = purple
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 Dracula styling.", theme:name()))