/**
 * LaTeX command definitions with documentation for autocompletion and hover.
 */

export enum CommandCategory {
    DocumentStructure = 'Document Structure',
    TextFormatting = 'Text Formatting',
    Math = 'Mathematics',
    Environments = 'Environments',
    References = 'References & Citations',
    Graphics = 'Graphics & Floats',
    Lists = 'Lists',
    Tables = 'Tables',
    Spacing = 'Spacing & Layout',
    Fonts = 'Fonts',
    Symbols = 'Symbols',
    Conditionals = 'Conditionals',
}

export interface LaTeXCommand {
    name: string;
    signature?: string;
    description: string;
    category: CommandCategory;
    package?: string;
    snippet?: string;
    example?: string;
}

export interface LaTeXEnvironment {
    name: string;
    description: string;
    category: CommandCategory;
    package?: string;
    snippet?: string;
}

export interface LaTeXPackage {
    name: string;
    description: string;
}

// Common LaTeX commands with documentation
export const LATEX_COMMANDS: LaTeXCommand[] = [
    // Environment commands (most commonly used)
    {
        name: 'begin',
        signature: '{environment}',
        description: 'Begins a LaTeX environment',
        category: CommandCategory.Environments,
        snippet: 'begin{${1:environment}}\n\t$0\n\\\\end{${1:environment}}',
    },
    {
        name: 'end',
        signature: '{environment}',
        description: 'Ends a LaTeX environment',
        category: CommandCategory.Environments,
        snippet: 'end{${1:environment}}',
    },
    // Document structure
    {
        name: 'documentclass',
        signature: '[options]{class}',
        description: 'Specifies the type of document (article, book, report, letter, etc.)',
        category: CommandCategory.DocumentStructure,
        snippet: 'documentclass[${1:a4paper}]{${2:article}}',
        example: '\\documentclass[12pt,a4paper]{article}',
    },
    {
        name: 'usepackage',
        signature: '[options]{package}',
        description: 'Loads a LaTeX package for additional functionality',
        category: CommandCategory.DocumentStructure,
        snippet: 'usepackage{${1:package}}',
    },
    {
        name: 'input',
        signature: '{filename}',
        description: 'Includes the content of another file',
        category: CommandCategory.DocumentStructure,
        snippet: 'input{${1:filename}}',
    },
    {
        name: 'include',
        signature: '{filename}',
        description: 'Includes another file with page breaks',
        category: CommandCategory.DocumentStructure,
        snippet: 'include{${1:filename}}',
    },
    {
        name: 'part',
        signature: '{title}',
        description: 'Creates a part heading (highest level in book)',
        category: CommandCategory.DocumentStructure,
        snippet: 'part{${1:title}}',
    },
    {
        name: 'chapter',
        signature: '{title}',
        description: 'Creates a chapter heading (book, report)',
        category: CommandCategory.DocumentStructure,
        snippet: 'chapter{${1:title}}',
    },
    {
        name: 'section',
        signature: '[short]{title}',
        description: 'Creates a numbered section heading',
        category: CommandCategory.DocumentStructure,
        snippet: 'section{${1:title}}',
    },
    {
        name: 'subsection',
        signature: '[short]{title}',
        description: 'Creates a numbered subsection heading',
        category: CommandCategory.DocumentStructure,
        snippet: 'subsection{${1:title}}',
    },
    {
        name: 'subsubsection',
        signature: '[short]{title}',
        description: 'Creates a numbered subsubsection heading',
        category: CommandCategory.DocumentStructure,
        snippet: 'subsubsection{${1:title}}',
    },
    {
        name: 'paragraph',
        signature: '{title}',
        description: 'Creates a paragraph heading',
        category: CommandCategory.DocumentStructure,
        snippet: 'paragraph{${1:title}}',
    },
    {
        name: 'subparagraph',
        signature: '{title}',
        description: 'Creates a subparagraph heading',
        category: CommandCategory.DocumentStructure,
        snippet: 'subparagraph{${1:title}}',
    },
    {
        name: 'title',
        signature: '{text}',
        description: 'Sets the document title',
        category: CommandCategory.DocumentStructure,
        snippet: 'title{${1:Title}}',
    },
    {
        name: 'author',
        signature: '{name}',
        description: 'Sets the document author',
        category: CommandCategory.DocumentStructure,
        snippet: 'author{${1:Author Name}}',
    },
    {
        name: 'date',
        signature: '{date}',
        description: 'Sets the document date',
        category: CommandCategory.DocumentStructure,
        snippet: 'date{${1:\\\\today}}',
    },
    {
        name: 'maketitle',
        description: 'Generates the title from title, author, and date',
        category: CommandCategory.DocumentStructure,
    },
    {
        name: 'tableofcontents',
        description: 'Generates a table of contents',
        category: CommandCategory.DocumentStructure,
    },
    {
        name: 'listoffigures',
        description: 'Generates a list of figures',
        category: CommandCategory.DocumentStructure,
    },
    {
        name: 'listoftables',
        description: 'Generates a list of tables',
        category: CommandCategory.DocumentStructure,
    },
    {
        name: 'appendix',
        description: 'Starts the appendix section',
        category: CommandCategory.DocumentStructure,
    },
    {
        name: 'newpage',
        description: 'Starts a new page',
        category: CommandCategory.DocumentStructure,
    },
    {
        name: 'clearpage',
        description: 'Ends page and outputs all floats',
        category: CommandCategory.DocumentStructure,
    },
    {
        name: 'cleardoublepage',
        description: 'Starts on a right-hand page',
        category: CommandCategory.DocumentStructure,
    },

    // Text formatting
    {
        name: 'textbf',
        signature: '{text}',
        description: 'Makes text bold',
        category: CommandCategory.TextFormatting,
        snippet: 'textbf{${1:text}}',
    },
    {
        name: 'textit',
        signature: '{text}',
        description: 'Makes text italic',
        category: CommandCategory.TextFormatting,
        snippet: 'textit{${1:text}}',
    },
    {
        name: 'emph',
        signature: '{text}',
        description: 'Emphasizes text (typically italic)',
        category: CommandCategory.TextFormatting,
        snippet: 'emph{${1:text}}',
    },
    {
        name: 'underline',
        signature: '{text}',
        description: 'Underlines text',
        category: CommandCategory.TextFormatting,
        snippet: 'underline{${1:text}}',
    },
    {
        name: 'texttt',
        signature: '{text}',
        description: 'Typewriter (monospace) text',
        category: CommandCategory.TextFormatting,
        snippet: 'texttt{${1:text}}',
    },
    {
        name: 'textsc',
        signature: '{text}',
        description: 'Small capitals text',
        category: CommandCategory.TextFormatting,
        snippet: 'textsc{${1:text}}',
    },
    {
        name: 'textsf',
        signature: '{text}',
        description: 'Sans-serif text',
        category: CommandCategory.TextFormatting,
        snippet: 'textsf{${1:text}}',
    },
    {
        name: 'textrm',
        signature: '{text}',
        description: 'Roman (serif) text',
        category: CommandCategory.TextFormatting,
        snippet: 'textrm{${1:text}}',
    },
    {
        name: 'textmd',
        signature: '{text}',
        description: 'Medium weight text',
        category: CommandCategory.TextFormatting,
        snippet: 'textmd{${1:text}}',
    },
    {
        name: 'textup',
        signature: '{text}',
        description: 'Upright text',
        category: CommandCategory.TextFormatting,
        snippet: 'textup{${1:text}}',
    },
    {
        name: 'textsl',
        signature: '{text}',
        description: 'Slanted text',
        category: CommandCategory.TextFormatting,
        snippet: 'textsl{${1:text}}',
    },
    {
        name: 'textnormal',
        signature: '{text}',
        description: 'Normal font text',
        category: CommandCategory.TextFormatting,
        snippet: 'textnormal{${1:text}}',
    },
    {
        name: 'textcolor',
        signature: '{color}{text}',
        description: 'Colored text',
        category: CommandCategory.TextFormatting,
        package: 'xcolor',
        snippet: 'textcolor{${1:red}}{${2:text}}',
    },
    {
        name: 'color',
        signature: '{color}',
        description: 'Sets text color for following content',
        category: CommandCategory.TextFormatting,
        package: 'xcolor',
        snippet: 'color{${1:blue}}',
    },
    {
        name: 'uline',
        signature: '{text}',
        description: 'Underline that allows line breaks',
        category: CommandCategory.TextFormatting,
        package: 'ulem',
        snippet: 'uline{${1:text}}',
    },
    {
        name: 'sout',
        signature: '{text}',
        description: 'Strikethrough text',
        category: CommandCategory.TextFormatting,
        package: 'ulem',
        snippet: 'sout{${1:text}}',
    },
    {
        name: 'uwave',
        signature: '{text}',
        description: 'Wavy underline',
        category: CommandCategory.TextFormatting,
        package: 'ulem',
        snippet: 'uwave{${1:text}}',
    },

    // Font sizes
    {
        name: 'tiny',
        description: 'Tiny font size',
        category: CommandCategory.Fonts,
    },
    {
        name: 'scriptsize',
        description: 'Script size font',
        category: CommandCategory.Fonts,
    },
    {
        name: 'footnotesize',
        description: 'Footnote size font',
        category: CommandCategory.Fonts,
    },
    {
        name: 'small',
        description: 'Small font size',
        category: CommandCategory.Fonts,
    },
    {
        name: 'normalsize',
        description: 'Normal font size',
        category: CommandCategory.Fonts,
    },
    {
        name: 'large',
        description: 'Large font size',
        category: CommandCategory.Fonts,
    },
    {
        name: 'Large',
        description: 'Larger font size',
        category: CommandCategory.Fonts,
    },
    {
        name: 'LARGE',
        description: 'Even larger font size',
        category: CommandCategory.Fonts,
    },
    {
        name: 'huge',
        description: 'Huge font size',
        category: CommandCategory.Fonts,
    },
    {
        name: 'Huge',
        description: 'Largest font size',
        category: CommandCategory.Fonts,
    },

    // Mathematics
    {
        name: 'frac',
        signature: '{num}{denom}',
        description: 'Creates a fraction',
        category: CommandCategory.Math,
        snippet: 'frac{${1:num}}{${2:denom}}',
    },
    {
        name: 'sqrt',
        signature: '[n]{expr}',
        description: 'Square root (or nth root)',
        category: CommandCategory.Math,
        snippet: 'sqrt{${1:x}}',
    },
    {
        name: 'sum',
        description: 'Summation symbol',
        category: CommandCategory.Math,
        snippet: 'sum_{${1:i=1}}^{${2:n}}',
    },
    {
        name: 'prod',
        description: 'Product symbol',
        category: CommandCategory.Math,
        snippet: 'prod_{${1:i=1}}^{${2:n}}',
    },
    {
        name: 'int',
        description: 'Integral symbol',
        category: CommandCategory.Math,
        snippet: 'int_{${1:a}}^{${2:b}}',
    },
    {
        name: 'lim',
        description: 'Limit symbol',
        category: CommandCategory.Math,
        snippet: 'lim_{${1:x \\\\to \\\\infty}}',
    },
    {
        name: 'infty',
        description: 'Infinity symbol',
        category: CommandCategory.Math,
    },
    {
        name: 'partial',
        description: 'Partial derivative symbol',
        category: CommandCategory.Math,
    },
    {
        name: 'nabla',
        description: 'Nabla/del operator',
        category: CommandCategory.Math,
    },
    {
        name: 'times',
        description: 'Multiplication cross',
        category: CommandCategory.Math,
    },
    {
        name: 'cdot',
        description: 'Centered dot for multiplication',
        category: CommandCategory.Math,
    },
    {
        name: 'div',
        description: 'Division symbol',
        category: CommandCategory.Math,
    },
    {
        name: 'pm',
        description: 'Plus-minus symbol',
        category: CommandCategory.Math,
    },
    {
        name: 'mp',
        description: 'Minus-plus symbol',
        category: CommandCategory.Math,
    },
    {
        name: 'leq',
        description: 'Less than or equal',
        category: CommandCategory.Math,
    },
    {
        name: 'geq',
        description: 'Greater than or equal',
        category: CommandCategory.Math,
    },
    {
        name: 'neq',
        description: 'Not equal',
        category: CommandCategory.Math,
    },
    {
        name: 'approx',
        description: 'Approximately equal',
        category: CommandCategory.Math,
    },
    {
        name: 'equiv',
        description: 'Equivalent/congruent',
        category: CommandCategory.Math,
    },
    {
        name: 'alpha',
        description: 'Greek letter alpha',
        category: CommandCategory.Math,
    },
    {
        name: 'beta',
        description: 'Greek letter beta',
        category: CommandCategory.Math,
    },
    {
        name: 'gamma',
        description: 'Greek letter gamma',
        category: CommandCategory.Math,
    },
    {
        name: 'delta',
        description: 'Greek letter delta',
        category: CommandCategory.Math,
    },
    {
        name: 'epsilon',
        description: 'Greek letter epsilon',
        category: CommandCategory.Math,
    },
    {
        name: 'theta',
        description: 'Greek letter theta',
        category: CommandCategory.Math,
    },
    {
        name: 'lambda',
        description: 'Greek letter lambda',
        category: CommandCategory.Math,
    },
    {
        name: 'mu',
        description: 'Greek letter mu',
        category: CommandCategory.Math,
    },
    {
        name: 'pi',
        description: 'Greek letter pi',
        category: CommandCategory.Math,
    },
    {
        name: 'sigma',
        description: 'Greek letter sigma',
        category: CommandCategory.Math,
    },
    {
        name: 'omega',
        description: 'Greek letter omega',
        category: CommandCategory.Math,
    },
    {
        name: 'Omega',
        description: 'Greek capital Omega',
        category: CommandCategory.Math,
    },
    {
        name: 'Delta',
        description: 'Greek capital Delta',
        category: CommandCategory.Math,
    },
    {
        name: 'Sigma',
        description: 'Greek capital Sigma',
        category: CommandCategory.Math,
    },
    {
        name: 'Pi',
        description: 'Greek capital Pi',
        category: CommandCategory.Math,
    },
    {
        name: 'left',
        description: 'Left delimiter (scalable)',
        category: CommandCategory.Math,
    },
    {
        name: 'right',
        description: 'Right delimiter (scalable)',
        category: CommandCategory.Math,
    },
    {
        name: 'mathbf',
        signature: '{text}',
        description: 'Bold math text',
        category: CommandCategory.Math,
        snippet: 'mathbf{${1:x}}',
    },
    {
        name: 'mathit',
        signature: '{text}',
        description: 'Italic math text',
        category: CommandCategory.Math,
        snippet: 'mathit{${1:text}}',
    },
    {
        name: 'mathrm',
        signature: '{text}',
        description: 'Roman (upright) math text',
        category: CommandCategory.Math,
        snippet: 'mathrm{${1:text}}',
    },
    {
        name: 'mathcal',
        signature: '{text}',
        description: 'Calligraphic math text',
        category: CommandCategory.Math,
        snippet: 'mathcal{${1:A}}',
    },
    {
        name: 'mathbb',
        signature: '{text}',
        description: 'Blackboard bold (requires amsfonts)',
        category: CommandCategory.Math,
        package: 'amsfonts',
        snippet: 'mathbb{${1:R}}',
    },
    {
        name: 'vec',
        signature: '{symbol}',
        description: 'Vector arrow over symbol',
        category: CommandCategory.Math,
        snippet: 'vec{${1:v}}',
    },
    {
        name: 'overline',
        signature: '{expr}',
        description: 'Line over expression',
        category: CommandCategory.Math,
        snippet: 'overline{${1:AB}}',
    },
    {
        name: 'overbrace',
        signature: '{expr}',
        description: 'Brace over expression',
        category: CommandCategory.Math,
        snippet: 'overbrace{${1:expr}}^{${2:label}}',
    },
    {
        name: 'underbrace',
        signature: '{expr}',
        description: 'Brace under expression',
        category: CommandCategory.Math,
        snippet: 'underbrace{${1:expr}}_{${2:label}}',
    },

    // References
    {
        name: 'label',
        signature: '{key}',
        description: 'Creates a label for cross-referencing',
        category: CommandCategory.References,
        snippet: 'label{${1:key}}',
    },
    {
        name: 'ref',
        signature: '{key}',
        description: 'References a label (number)',
        category: CommandCategory.References,
        snippet: 'ref{${1:key}}',
    },
    {
        name: 'pageref',
        signature: '{key}',
        description: 'References a label (page number)',
        category: CommandCategory.References,
        snippet: 'pageref{${1:key}}',
    },
    {
        name: 'cite',
        signature: '[note]{key}',
        description: 'Cites a bibliography entry',
        category: CommandCategory.References,
        snippet: 'cite{${1:key}}',
    },
    {
        name: 'footnote',
        signature: '{text}',
        description: 'Creates a footnote',
        category: CommandCategory.References,
        snippet: 'footnote{${1:text}}',
    },
    {
        name: 'href',
        signature: '{url}{text}',
        description: 'Creates a hyperlink',
        category: CommandCategory.References,
        package: 'hyperref',
        snippet: 'href{${1:url}}{${2:text}}',
    },
    {
        name: 'url',
        signature: '{url}',
        description: 'Displays a URL',
        category: CommandCategory.References,
        package: 'hyperref',
        snippet: 'url{${1:url}}',
    },

    // Graphics
    {
        name: 'includegraphics',
        signature: '[options]{file}',
        description: 'Includes an image',
        category: CommandCategory.Graphics,
        package: 'graphicx',
        snippet: 'includegraphics[width=${1:0.8}\\\\textwidth]{${2:image}}',
    },
    {
        name: 'caption',
        signature: '[short]{text}',
        description: 'Adds a caption to a float',
        category: CommandCategory.Graphics,
        snippet: 'caption{${1:Caption text}}',
    },
    {
        name: 'centering',
        description: 'Centers content in environment',
        category: CommandCategory.Graphics,
    },

    // Lists
    {
        name: 'item',
        signature: '[label]',
        description: 'List item',
        category: CommandCategory.Lists,
        snippet: 'item ${1}',
    },

    // Tables
    {
        name: 'hline',
        description: 'Horizontal line in tables',
        category: CommandCategory.Tables,
    },
    {
        name: 'cline',
        signature: '{i-j}',
        description: 'Partial horizontal line',
        category: CommandCategory.Tables,
        snippet: 'cline{${1:1}-${2:2}}',
    },
    {
        name: 'multicolumn',
        signature: '{n}{align}{text}',
        description: 'Spans multiple columns',
        category: CommandCategory.Tables,
        snippet: 'multicolumn{${1:2}}{${2:c}}{${3:text}}',
    },

    // Spacing
    {
        name: 'hspace',
        signature: '{length}',
        description: 'Horizontal space',
        category: CommandCategory.Spacing,
        snippet: 'hspace{${1:1cm}}',
    },
    {
        name: 'vspace',
        signature: '{length}',
        description: 'Vertical space',
        category: CommandCategory.Spacing,
        snippet: 'vspace{${1:1cm}}',
    },
    {
        name: 'hfill',
        description: 'Fills horizontal space',
        category: CommandCategory.Spacing,
    },
    {
        name: 'vfill',
        description: 'Fills vertical space',
        category: CommandCategory.Spacing,
    },
    {
        name: 'bigskip',
        description: 'Large vertical skip',
        category: CommandCategory.Spacing,
    },
    {
        name: 'medskip',
        description: 'Medium vertical skip',
        category: CommandCategory.Spacing,
    },
    {
        name: 'smallskip',
        description: 'Small vertical skip',
        category: CommandCategory.Spacing,
    },
    {
        name: 'noindent',
        description: 'Prevents paragraph indentation',
        category: CommandCategory.Spacing,
    },
    {
        name: 'indent',
        description: 'Forces paragraph indentation',
        category: CommandCategory.Spacing,
    },
    {
        name: 'par',
        description: 'Ends paragraph',
        category: CommandCategory.Spacing,
    },
    {
        name: 'linebreak',
        description: 'Suggests line break',
        category: CommandCategory.Spacing,
    },
    {
        name: 'newline',
        description: 'Forces line break',
        category: CommandCategory.Spacing,
    },
    {
        name: 'pagebreak',
        description: 'Suggests page break',
        category: CommandCategory.Spacing,
    },
    {
        name: 'nopagebreak',
        description: 'Prevents page break',
        category: CommandCategory.Spacing,
    },

    // Commands and definitions
    {
        name: 'newcommand',
        signature: '{cmd}[n]{def}',
        description: 'Defines a new command',
        category: CommandCategory.DocumentStructure,
        snippet: 'newcommand{\\\\${1:cmdname}}[${2:0}]{${3:definition}}',
    },
    {
        name: 'renewcommand',
        signature: '{cmd}[n]{def}',
        description: 'Redefines an existing command',
        category: CommandCategory.DocumentStructure,
        snippet: 'renewcommand{\\\\${1:cmdname}}[${2:0}]{${3:definition}}',
    },
    {
        name: 'providecommand',
        signature: '{cmd}[n]{def}',
        description: 'Defines command only if not already defined',
        category: CommandCategory.DocumentStructure,
        snippet: 'providecommand{\\\\${1:cmdname}}[${2:0}]{${3:definition}}',
    },
    {
        name: 'def',
        signature: '\\cmd{def}',
        description: 'TeX primitive for defining macros',
        category: CommandCategory.DocumentStructure,
    },
    {
        name: 'newenvironment',
        signature: '{name}[n]{begin}{end}',
        description: 'Defines a new environment',
        category: CommandCategory.DocumentStructure,
        snippet: 'newenvironment{${1:name}}{${2:begin code}}{${3:end code}}',
    },

    // Symbols
    {
        name: 'ldots',
        description: 'Horizontal ellipsis (baseline)',
        category: CommandCategory.Symbols,
    },
    {
        name: 'cdots',
        description: 'Horizontal ellipsis (centered)',
        category: CommandCategory.Symbols,
    },
    {
        name: 'vdots',
        description: 'Vertical ellipsis',
        category: CommandCategory.Symbols,
    },
    {
        name: 'ddots',
        description: 'Diagonal ellipsis',
        category: CommandCategory.Symbols,
    },
    {
        name: 'LaTeX',
        description: 'The LaTeX logo',
        category: CommandCategory.Symbols,
    },
    {
        name: 'TeX',
        description: 'The TeX logo',
        category: CommandCategory.Symbols,
    },
    {
        name: 'today',
        description: 'Current date',
        category: CommandCategory.Symbols,
    },
    {
        name: 'copyright',
        description: 'Copyright symbol',
        category: CommandCategory.Symbols,
    },
    {
        name: 'euro',
        description: 'Euro symbol',
        category: CommandCategory.Symbols,
        package: 'eurosym',
    },

    // Conditionals
    {
        name: 'if',
        description: 'TeX conditional',
        category: CommandCategory.Conditionals,
    },
    {
        name: 'else',
        description: 'Else branch of conditional',
        category: CommandCategory.Conditionals,
    },
    {
        name: 'fi',
        description: 'End of conditional',
        category: CommandCategory.Conditionals,
    },
    {
        name: 'ifx',
        description: 'Tests if two tokens are equal',
        category: CommandCategory.Conditionals,
    },
    {
        name: 'ifnum',
        description: 'Numeric comparison',
        category: CommandCategory.Conditionals,
    },
    {
        name: 'ifdim',
        description: 'Dimension comparison',
        category: CommandCategory.Conditionals,
    },
];

// LaTeX environments with documentation
export const LATEX_ENVIRONMENTS: LaTeXEnvironment[] = [
    // Document
    {
        name: 'document',
        description: 'Main document environment',
        category: CommandCategory.DocumentStructure,
        snippet: 'begin{document}\n\t${1}\n\\\\end{document}',
    },
    {
        name: 'abstract',
        description: 'Abstract environment',
        category: CommandCategory.DocumentStructure,
        snippet: 'begin{abstract}\n\t${1}\n\\\\end{abstract}',
    },

    // Math environments
    {
        name: 'equation',
        description: 'Numbered equation',
        category: CommandCategory.Math,
        snippet: 'begin{equation}\n\t${1}\n\\\\end{equation}',
    },
    {
        name: 'equation*',
        description: 'Unnumbered equation',
        category: CommandCategory.Math,
        package: 'amsmath',
        snippet: 'begin{equation*}\n\t${1}\n\\\\end{equation*}',
    },
    {
        name: 'align',
        description: 'Aligned equations (numbered)',
        category: CommandCategory.Math,
        package: 'amsmath',
        snippet: 'begin{align}\n\t${1} &= ${2} \\\\\\\\\n\\\\end{align}',
    },
    {
        name: 'align*',
        description: 'Aligned equations (unnumbered)',
        category: CommandCategory.Math,
        package: 'amsmath',
        snippet: 'begin{align*}\n\t${1} &= ${2} \\\\\\\\\n\\\\end{align*}',
    },
    {
        name: 'gather',
        description: 'Centered equations',
        category: CommandCategory.Math,
        package: 'amsmath',
        snippet: 'begin{gather}\n\t${1}\n\\\\end{gather}',
    },
    {
        name: 'multline',
        description: 'Multi-line equation',
        category: CommandCategory.Math,
        package: 'amsmath',
        snippet: 'begin{multline}\n\t${1}\n\\\\end{multline}',
    },
    {
        name: 'cases',
        description: 'Piecewise functions',
        category: CommandCategory.Math,
        package: 'amsmath',
        snippet: 'begin{cases}\n\t${1} & \\\\text{if } ${2} \\\\\\\\\n\t${3} & \\\\text{otherwise}\n\\\\end{cases}',
    },
    {
        name: 'matrix',
        description: 'Matrix without delimiters',
        category: CommandCategory.Math,
        package: 'amsmath',
        snippet: 'begin{matrix}\n\t${1} & ${2} \\\\\\\\\n\t${3} & ${4}\n\\\\end{matrix}',
    },
    {
        name: 'pmatrix',
        description: 'Matrix with parentheses',
        category: CommandCategory.Math,
        package: 'amsmath',
        snippet: 'begin{pmatrix}\n\t${1} & ${2} \\\\\\\\\n\t${3} & ${4}\n\\\\end{pmatrix}',
    },
    {
        name: 'bmatrix',
        description: 'Matrix with square brackets',
        category: CommandCategory.Math,
        package: 'amsmath',
        snippet: 'begin{bmatrix}\n\t${1} & ${2} \\\\\\\\\n\t${3} & ${4}\n\\\\end{bmatrix}',
    },
    {
        name: 'vmatrix',
        description: 'Matrix with vertical bars (determinant)',
        category: CommandCategory.Math,
        package: 'amsmath',
        snippet: 'begin{vmatrix}\n\t${1} & ${2} \\\\\\\\\n\t${3} & ${4}\n\\\\end{vmatrix}',
    },

    // Lists
    {
        name: 'itemize',
        description: 'Bulleted list',
        category: CommandCategory.Lists,
        snippet: 'begin{itemize}\n\t\\\\item ${1}\n\\\\end{itemize}',
    },
    {
        name: 'enumerate',
        description: 'Numbered list',
        category: CommandCategory.Lists,
        snippet: 'begin{enumerate}\n\t\\\\item ${1}\n\\\\end{enumerate}',
    },
    {
        name: 'description',
        description: 'Description list',
        category: CommandCategory.Lists,
        snippet: 'begin{description}\n\t\\\\item[${1:term}] ${2:description}\n\\\\end{description}',
    },

    // Floats
    {
        name: 'figure',
        description: 'Floating figure environment',
        category: CommandCategory.Graphics,
        snippet: 'begin{figure}[${1:htbp}]\n\t\\\\centering\n\t\\\\includegraphics[width=${2:0.8}\\\\textwidth]{${3:image}}\n\t\\\\caption{${4:Caption}}\n\t\\\\label{fig:${5:label}}\n\\\\end{figure}',
    },
    {
        name: 'table',
        description: 'Floating table environment',
        category: CommandCategory.Tables,
        snippet: 'begin{table}[${1:htbp}]\n\t\\\\centering\n\t\\\\begin{tabular}{${2:c|c}}\n\t\t${3:content}\n\t\\\\end{tabular}\n\t\\\\caption{${4:Caption}}\n\t\\\\label{tab:${5:label}}\n\\\\end{table}',
    },
    {
        name: 'tabular',
        description: 'Table content environment',
        category: CommandCategory.Tables,
        snippet: 'begin{tabular}{${1:c|c}}\n\t${2:content}\n\\\\end{tabular}',
    },

    // Text environments
    {
        name: 'center',
        description: 'Centered text',
        category: CommandCategory.TextFormatting,
        snippet: 'begin{center}\n\t${1}\n\\\\end{center}',
    },
    {
        name: 'flushleft',
        description: 'Left-aligned text',
        category: CommandCategory.TextFormatting,
        snippet: 'begin{flushleft}\n\t${1}\n\\\\end{flushleft}',
    },
    {
        name: 'flushright',
        description: 'Right-aligned text',
        category: CommandCategory.TextFormatting,
        snippet: 'begin{flushright}\n\t${1}\n\\\\end{flushright}',
    },
    {
        name: 'quote',
        description: 'Short quotation',
        category: CommandCategory.TextFormatting,
        snippet: 'begin{quote}\n\t${1}\n\\\\end{quote}',
    },
    {
        name: 'quotation',
        description: 'Long quotation with indentation',
        category: CommandCategory.TextFormatting,
        snippet: 'begin{quotation}\n\t${1}\n\\\\end{quotation}',
    },
    {
        name: 'verse',
        description: 'Poetry environment',
        category: CommandCategory.TextFormatting,
        snippet: 'begin{verse}\n\t${1}\n\\\\end{verse}',
    },
    {
        name: 'verbatim',
        description: 'Verbatim text (code)',
        category: CommandCategory.TextFormatting,
        snippet: 'begin{verbatim}\n${1}\n\\\\end{verbatim}',
    },
    {
        name: 'minipage',
        description: 'Mini page within page',
        category: CommandCategory.Spacing,
        snippet: 'begin{minipage}[${1:t}]{${2:0.45}\\\\textwidth}\n\t${3}\n\\\\end{minipage}',
    },

    // TikZ
    {
        name: 'tikzpicture',
        description: 'TikZ drawing environment',
        category: CommandCategory.Graphics,
        package: 'tikz',
        snippet: 'begin{tikzpicture}\n\t${1}\n\\\\end{tikzpicture}',
    },
];

// Common packages with descriptions
export const LATEX_PACKAGES: LaTeXPackage[] = [
    { name: 'amsmath', description: 'Advanced math typesetting' },
    { name: 'amssymb', description: 'Additional math symbols' },
    { name: 'amsfonts', description: 'Math fonts (blackboard bold, etc.)' },
    { name: 'graphicx', description: 'Include graphics' },
    { name: 'hyperref', description: 'Hyperlinks and PDF metadata' },
    { name: 'geometry', description: 'Page layout customization' },
    { name: 'babel', description: 'Multilingual support' },
    { name: 'fontenc', description: 'Font encoding' },
    { name: 'inputenc', description: 'Input encoding' },
    { name: 'xcolor', description: 'Color support' },
    { name: 'tikz', description: 'TikZ graphics' },
    { name: 'pgfplots', description: 'Plots and charts' },
    { name: 'booktabs', description: 'Professional tables' },
    { name: 'array', description: 'Extended array/tabular' },
    { name: 'multirow', description: 'Multi-row cells in tables' },
    { name: 'longtable', description: 'Tables spanning pages' },
    { name: 'fancyhdr', description: 'Custom headers/footers' },
    { name: 'enumitem', description: 'Customize lists' },
    { name: 'listings', description: 'Code listings' },
    { name: 'algorithm2e', description: 'Algorithms' },
    { name: 'float', description: 'Float placement control' },
    { name: 'subcaption', description: 'Subfigures and subtables' },
    { name: 'caption', description: 'Customize captions' },
    { name: 'natbib', description: 'Bibliography (author-year)' },
    { name: 'biblatex', description: 'Modern bibliography' },
    { name: 'cleveref', description: 'Smart cross-references' },
    { name: 'siunitx', description: 'SI units' },
    { name: 'ulem', description: 'Underline/strikethrough' },
    { name: 'soul', description: 'Text highlighting' },
    { name: 'setspace', description: 'Line spacing' },
    { name: 'parskip', description: 'Paragraph spacing' },
    { name: 'microtype', description: 'Micro-typography improvements' },
    { name: 'csquotes', description: 'Context-sensitive quotes' },
    { name: 'eurosym', description: 'Euro symbol' },
    { name: 'textcomp', description: 'Additional text symbols' },
    { name: 'pifont', description: 'Dingbat symbols' },
    { name: 'multicol', description: 'Multiple columns' },
    { name: 'wrapfig', description: 'Text wrapping around figures' },
    { name: 'pstricks', description: 'PostScript graphics' },
];

// Build a lookup map for quick access
export const COMMAND_MAP = new Map<string, LaTeXCommand>(
    LATEX_COMMANDS.map(cmd => [cmd.name, cmd])
);

export const ENVIRONMENT_MAP = new Map<string, LaTeXEnvironment>(
    LATEX_ENVIRONMENTS.map(env => [env.name, env])
);

export const PACKAGE_MAP = new Map<string, LaTeXPackage>(
    LATEX_PACKAGES.map(pkg => [pkg.name, pkg])
);
