vim.cmd [[
  set nocompatible
  filetype plugin indent on
  syntax enable
  call plug#begin('~/.local/share/nvim/plugged')
  Plug 'tpope/vim-sensible'
  Plug 'junegunn/fzf.vim'
  Plug 'tpope/vim-surround'
  Plug 'tpope/vim-commentary'
  Plug 'jiangmiao/auto-pairs'
  Plug 'tpope/vim-repeat'
  Plug 'mattn/emmet-vim'
  Plug 'norcalli/nvim-colorizer.lua'
  call plug#end()
]]

vim.opt.clipboard = "unnamedplus"
vim.opt.updatetime = 300
vim.opt.timeoutlen = 500
vim.opt.signcolumn = "yes"
vim.opt.completeopt = { "menuone", "noinsert", "noselect" }
vim.opt.encoding = "utf-8"
vim.opt.number = true
vim.opt.relativenumber = true
vim.opt.numberwidth = 4
vim.opt.tabstop = 4
vim.opt.shiftwidth = 4
vim.opt.expandtab = true
vim.opt.smartindent = true
vim.opt.incsearch = true
vim.opt.hlsearch = true
vim.opt.ignorecase = true
vim.opt.smartcase = true
vim.opt.wrap = true
vim.opt.mouse = "a"
vim.opt.scrolloff = 5
vim.opt.cursorline = true
vim.opt.showmode = false
vim.opt.shortmess:append("I")
vim.opt.autoindent = true
vim.opt.termguicolors = true
vim.opt.list = true
vim.opt.undodir = vim.fn.stdpath("cache") .. "/undo"
vim.opt.undofile = true
vim.opt.wrapscan = true
vim.opt.shortmess:append("c")
vim.opt.autoread = true
vim.opt.cmdheight = 1
vim.opt.belloff = "all"
vim.opt.laststatus = 2
vim.opt.scrolljump = 3
vim.opt.hidden = true
vim.opt.splitbelow = true
vim.opt.splitright = true
vim.opt.backup = false
vim.opt.writebackup = false
vim.opt.lazyredraw = true
vim.opt.smoothscroll = true

vim.api.nvim_set_hl(0, "Normal",         { fg = "#d77189", bg = "#000000", ctermfg = 168, ctermbg = 0 })
vim.api.nvim_set_hl(0, "NormalNC",       { fg = "#c7607a", bg = "#000000", ctermfg = 168, ctermbg = 0 })
vim.api.nvim_set_hl(0, "LineNr",         { fg = "#914659", bg = "#000000", ctermfg = 131, ctermbg = 0 })
vim.api.nvim_set_hl(0, "CursorLine",     { bg = "#1a0a0e", fg = "NONE", ctermbg = 233, ctermfg = "NONE" })
vim.api.nvim_set_hl(0, "VertSplit",      { fg = "#351f26", bg = "#000000", ctermfg = 59, ctermbg = 0 })

vim.api.nvim_set_hl(0, "StatusLine", {
  fg = "#d77189",
  bg = "#2a151b",
  ctermfg = 168,
  ctermbg = 235,
})

vim.api.nvim_set_hl(0, "StatusLineMode", {
  fg = "#ffd1dc",
  bg = "#5c2f3d",
  bold = true,
  ctermfg = 217,
  ctermbg = 131,
})

vim.api.nvim_set_hl(0, "Visual",         { bg = "#4c2934", fg = "NONE", ctermbg = 95, ctermfg = "NONE" })
vim.api.nvim_set_hl(0, "VisualNOS",      { bg = "#4c2934", fg = "NONE", ctermbg = 95, ctermbg = "NONE" })
vim.api.nvim_set_hl(0, "VisualSB",       { bg = "#4c2934", fg = "NONE", ctermbg = 95, ctermfg = "NONE" })
vim.api.nvim_set_hl(0, "Search",         { fg = "#d77189", bg = "#1a0a0e", ctermfg = 168, ctermbg = 233 })
vim.api.nvim_set_hl(0, "IncSearch",      { fg = "#ff9fb2", bg = "#1a0a0e", ctermfg = 217, ctermbg = 233 })
vim.api.nvim_set_hl(0, "Pmenu",          { fg = "#d77189", bg = "#000000", ctermfg = 168, ctermbg = 0 })
vim.api.nvim_set_hl(0, "PmenuSel",       { fg = "#000000", bg = "#d77189", ctermfg = 0,  ctermbg = 168 })
vim.api.nvim_set_hl(0, "WildMenu",       { fg = "#d77189", bg = "#000000", ctermfg = 168, ctermbg = 0 })
vim.api.nvim_set_hl(0, "Folded",         { fg = "#a45b6d", bg = "#000000", ctermfg = 131, ctermbg = 0 })
vim.api.nvim_set_hl(0, "SignColumn",     { fg = "#ff8ca3", bg = "#000000", ctermfg = 210, ctermbg = 0 })

local mode_names = {
  n = "NRM",
  i = "INS",
  v = "VSL",
  V = "VLI",
  [""] = "VBL",
  R = "RPL",
  c = "CMD",
}

function _G.ModeName()
  return mode_names[vim.fn.mode()] or "UNK"
end

vim.opt.statusline = table.concat {
  "%#StatusLineMode# ",
  "%{v:lua.ModeName()} ",
  "%#StatusLine# ",
  "%f %m %r ",
  "%=",
  "Ln:%l/%L ",
  "Col:%c ",
  "[%p%%]",
}

vim.g.mapleader = " "
local map = vim.keymap.set
map("n", "<leader>w", ":w<CR>")
map("n", "<leader>q", ":q<CR>")
map("n", "<leader>h", ":nohlsearch<CR>", { silent = true })
map("n", "<leader>n", ":set relativenumber!<CR>")
map("n", "<C-h>", "<C-w>h")
map("n", "<C-j>", "<C-w>j")
map("n", "<C-k>", "<C-w>k")
map("n", "<C-l>", "<C-w>l")
map("n", "<leader>v", ":Ex<CR>")
map("", "j", "gj")
map("", "k", "gk")

vim.keymap.set({ "n", "v" }, "<leader>d", '"_d', { desc = "Delete without yanking" })
vim.keymap.set("n", "<leader>bn", ":bnext<CR>", { desc = "Next buffer" })
vim.keymap.set("n", "<leader>bp", ":bprevious<CR>", { desc = "Previous buffer" })

vim.keymap.set("n", "<C-h>", "<C-w>h", { desc = "Move to left window" })
vim.keymap.set("n", "<C-j>", "<C-w>j", { desc = "Move to bottom window" })
vim.keymap.set("n", "<C-k>", "<C-w>k", { desc = "Move to top window" })
vim.keymap.set("n", "<C-l>", "<C-w>l", { desc = "Move to right window" })

local modes_to_disable = { "n", "v", "x", "s", "c" }
local arrows = { "<Up>", "<Down>", "<Left>", "<Right>" }

for _, mode in ipairs(modes_to_disable) do
  for _, key in ipairs(arrows) do
    vim.keymap.set(mode, key, "<Nop>", { silent = true })
  end
end

vim.keymap.set("n", "<leader>sv", ":vsplit<CR>", { desc = "Split window vertically" })
vim.keymap.set("n", "<leader>sh", ":split<CR>", { desc = "Split window horizontally" })
vim.keymap.set("n", "<C-Up>", ":resize +2<CR>", { desc = "Increase window height" })
vim.keymap.set("n", "<C-Down>", ":resize -2<CR>", { desc = "Decrease window height" })
vim.keymap.set("n", "<C-Right>", ":vertical resize -2<CR>", { desc = "Decrease window width" })
vim.keymap.set("n", "<C-Left>", ":vertical resize +2<CR>", { desc = "Increase window width" })

vim.keymap.set("n", "<A-j>", ":m .+1<CR>==", { desc = "Move line down" })
vim.keymap.set("n", "<A-k>", ":m .-2<CR>==", { desc = "Move line up" })
vim.keymap.set("v", "<A-j>", ":m '>+1<CR>gv=gv", { desc = "Move selection down" })
vim.keymap.set("v", "<A-k>", ":m '<-2<CR>gv=gv", { desc = "Move selection up" })

require('colorizer').setup {
  '*', 
  css = { names = true },
  html = { names = true },
}
