-- Change this to switch themes
-- local THEME = "kanagawa"
-- local THEME = "catppuccin-mocha"
-- local THEME = "everforest-medium"
-- local THEME = "gruvbox-material"
-- local THEME = "tokyo-night"
local THEME = "rose_pine-moon"

-- local theme_colors = {
--   rose_pine = {
--     primary = "#c4a7e7", -- iris/mauve (purple-like color from rose-pine palette)
--     secondary = "#6e6a86", -- muted/subtle (comparable to comment/gray colors)
--     yanked = "#9ccfd8", -- foam (cyan-like accent color)
--     cut = "#eb6f92", -- love (red-like accent color)
--   },
--   carbonfox = {
--     primary = "#78a9ff",
--     secondary = "#525252",
--     yanked = "#3ddbd9",
--     cut = "#ff7eb6",
--   },
--   kanagawa = {
--     primary = "#7e9cd8",
--     secondary = "#54546d",
--     yanked = "#7aa89f",
--     cut = "#e82424",
--   },
--   sonokai = {
--     primary = "#76cce0",
--     secondary = "#7f8490",
--     yanked = "#fc5d7c",
--     cut = "#f85e84",
--   },
--   catppuccin = {
--     primary = "#89b4fa",
--     secondary = "#6c7086",
--     yanked = "#94e2d5",
--     cut = "#f38ba8",
--   },
--   dracula = {
--     primary = "#bd93f9", -- purple
--     secondary = "#6272a4", -- comment
--     yanked = "#8be9fd", -- cyan
--     cut = "#ff5555", -- red
--   },
--   everforest = {
--     primary = "#7fbbb3", -- aqua
--     secondary = "#859289", -- gray
--     yanked = "#a7c080", -- green
--     cut = "#e67e80", -- red
--   },
--   gruvbox = {
--     primary = "#7daea3", -- aqua
--     secondary = "#7c6f64", -- gray
--     yanked = "#a9b665", -- green
--     cut = "#ea6962", -- red
--   },
--   nightfox = {
--     primary = "#719cd6", -- blue
--     secondary = "#738091", -- comment
--     yanked = "#63cdcf", -- cyan
--     cut = "#c94f6d", -- red
--   },
--   onedark = {
--     primary = "#61afef", -- blue
--     secondary = "#5c6370", -- gray
--     yanked = "#56b6c2", -- cyan
--     cut = "#e06c75", -- red
--   },
-- }

-- eocal c = theme_colors[THEME]

-- require("yaziline"):setup({
--   color = c.primary,
--   secondary_color = c.secondary,
--   default_files_color = "darkgray",
--   selected_files_color = "white",
--   yanked_files_color = c.yanked,
--   cut_files_color = c.cut,
--   separator_style = "angly", -- "angly" | "curvy" | "liney" | "empty"
--   separator_open = "",
--   separator_close = "",
--   separator_open_thin = "",
--   separator_close_thin = "",
--   separator_head = "",
--   separator_tail = "",

--   select_symbol = "",
--   yank_symbol = "󰆐",

--   filename_max_length = 24, -- truncate when filename > 24
--   filename_truncate_length = 6, -- leave 6 chars on both sides
--   filename_truncate_separator = "...",
-- })

require("recycle-bin"):setup({
  trash_dir = "~/.local/share/Trash/",
})

-- require("omp"):setup({ config = "/home/liph/.config/yazi/omp/omp.toml" })

require("mime-ext"):setup({
  -- with_files = {
  -- 	tex = "text/makefile",
  -- },

  with_exts = {
    tex = "text/makefile",
  },
})

require("full-border"):setup({
  type = ui.Border.ROUNDED,
})

-- git-yazi plugin
-- th.git = th.git or {}
-- th.git.modified = ui.Style():fg("blue")
-- th.git.deleted = ui.Style():fg("red"):bold()
require("git"):setup()
-- whoosh plugin
-- You can configure your bookmarks using simplified syntax
-- local bookmarks = {
-- { tag = "Documents", path = "~/Documents", key = "D" },
-- }

-- You can also configure bookmarks with key arrays
-- local bookmarks = {
-- { tag = "Desktop", path = "~/Desktop", key = { "d", "D" } },
-- { tag = "Documents", path = "~/Documents", key = { "d", "d" } },
-- { tag = "Downloads", path = "~/Downloads", key = "o" },
-- { tag = "Downloads", path = "~/Downloads", key = "o" },
-- { tag = "Downloads", path = "~/Downloads", key = "o" },
-- { tag = "Downloads", path = "~/Downloads", key = "o" },
-- { tag = "Downloads", path = "~/Downloads", key = "o" },
-- }

require("whoosh"):setup({
  -- Configuration bookmarks (cannot be deleted through plugin)
  bookmarks = bookmarks,

  -- Notification settings
  jump_notify = false,

  -- Key generation for auto-assigning bookmark keys
  keys = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",

  -- Configure the built-in menu action hotkeys
  -- false - hide menu item
  special_keys = {
    create_temp = "<Enter>", -- Create a temporary bookmark from the menu
    fuzzy_search = "<Space>", -- Launch fuzzy search (fzf)
    history = "<Tab>", -- Open directory history
    previous_dir = "<Backspace>", -- Jump back to the previous directory
  },

  -- File path for storing user bookmarks
  bookmarks_path = (
    ya.target_family() == "windows" and os.getenv("APPDATA") .. "\\yazi\\config\\plugins\\whoosh.yazi\\bookmarks"
  ) or (os.getenv("HOME") .. "/.config/yazi/plugins/whoosh.yazi/bookmarks"),

  -- Replace home directory with "~"
  home_alias_enabled = true, -- Toggle home aliasing in displays

  -- Path truncation in navigation menu
  path_truncate_enabled = false, -- Enable/disable path truncation
  path_max_depth = 3, -- Maximum path depth before truncation

  -- Path truncation in fuzzy search (fzf)
  fzf_path_truncate_enabled = false, -- Enable/disable path truncation in fzf
  fzf_path_max_depth = 5, -- Maximum path depth before truncation in fzf

  -- Long folder name truncation
  path_truncate_long_names_enabled = false, -- Enable in navigation menu
  fzf_path_truncate_long_names_enabled = false, -- Enable in fzf
  path_max_folder_name_length = 20, -- Max length in navigation menu
  fzf_path_max_folder_name_length = 20, -- Max length in fzf

  -- History directory settings
  history_size = 10, -- Number of directories in history (default 10)
  history_fzf_path_truncate_enabled = false, -- Enable/disable path truncation by depth for history
  history_fzf_path_max_depth = 5, -- Maximum path depth before truncation for history (default 5)
  history_fzf_path_truncate_long_names_enabled = false, -- Enable/disable long folder name truncation for history
  history_fzf_path_max_folder_name_length = 30, -- Maximum length for folder names in history (default 30)
})

-- projetc plugin
require("projects"):setup({
  event = {
    save = {
      enable = true,
      name = "project-saved",
    },
    load = {
      enable = true,
      name = "project-loaded",
    },
    delete = {
      enable = true,
      name = "project-deleted",
    },
    delete_all = {
      enable = true,
      name = "project-deleted-all",
    },
    merge = {
      enable = true,
      name = "project-merged",
    },
  },
  save = {
    method = "yazi", -- yazi | lua
    yazi_load_event = "@projects-load", -- event name when loading projects in `yazi` method
    lua_save_path = "", -- path of saved file in `lua` method, comment out or assign explicitly
    -- default value:
    -- windows: "%APPDATA%/yazi/state/projects.json"
    -- unix: "~/.local/state/yazi/projects.json"
  },
  last = {
    update_after_save = true,
    update_after_load = true,
    update_before_quit = false,
    load_after_start = false,
  },
  merge = {
    event = "projects-merge",
    quit_after_merge = false,
  },
  notify = {
    enable = true,
    title = "Projects",
    timeout = 3,
    level = "info",
  },
})

-- yafg plugin
require("yafg"):setup({
  editor = "nvim", -- Editor command (default: "hx")
  args = { "--noplugin" }, -- Additional editor arguments (default: {})
  file_arg_format = "+{row} {file}", -- File argument format (default: "{file}:{row}:{col}")
})

require("simple-tag"):setup({
  -- UI display mode (icon, text, hidden)
  ui_mode = "icon", -- (Optional)

  -- Disable tag key hints (popup in bottom right corner)
  hints_disabled = false, -- (Optional)

  -- linemode order: adjusts icon/text position. For example, if you want icon to be on the most left of linemode then set linemode_order larger than 1000.
  -- More info: https://github.com/sxyazi/yazi/blob/077faacc9a84bb5a06c5a8185a71405b0cb3dc8a/yazi-plugin/preset/components/linemode.lua#L4-L5
  linemode_order = 500, -- (Optional)

  -- You can backup/restore this folder within the same OS (Linux, windows, or MacOS).
  -- But you can't restore backed up folder in the different OS because they use difference absolute path.
  -- save_path =  -- full path to save tags folder (Optional)
  --       - Linux/MacOS: os.getenv("HOME") .. "/.config/yazi/tags"
  --       - Windows: os.getenv("APPDATA") .. "\\yazi\\config\\tags"

  -- Set tag colors
  colors = { -- (Optional)
    -- Set this same value with `theme.toml` > [mgr] > hovered > reversed
    -- Default theme use "reversed = true".
    -- More info: https://github.com/sxyazi/yazi/blob/077faacc9a84bb5a06c5a8185a71405b0cb3dc8a/yazi-config/preset/theme-dark.toml#L25
    reversed = true, -- (Optional)

    -- More colors: https://yazi-rs.github.io/docs/configuration/theme#types.color
    -- format: [tag key] = "color"
    ["*"] = "#bf68d9", -- (Optional)
    ["$"] = "green",
    ["!"] = "#cc9057",
    ["1"] = "cyan",
    ["p"] = "red",
  },

  -- Set tag icons. Only show when ui_mode = "icon".
  -- Any text or nerdfont icons should work as long as you use nerdfont to render yazi.
  -- Default icon from mactag.yazi: ●; Some generic icons: , , 󱈤
  -- More icon from nerd fonts: https://www.nerdfonts.com/cheat-sheet
  icons = { -- (Optional)
    -- default icon
    default = "󰚋",

    -- format: [tag key] = "tag icon"
    ["*"] = "*",
    ["$"] = "",
    ["!"] = "",
    ["p"] = "",
  },
})
-- require("omp"):setup({
--   config = "/home/liph/.config/ohmyposh/yazi-zen.json",
-- })

-- default config
require("fchar"):setup({
  -- if true: f -> file, File, FILE
  insensitive = true,
  -- if true: f -> file, .file, @file, #file, ...file
  skip_symbols = true,
  -- if {"yazi-"}: f -> file, yazi-file
  skip_prefix = {},
  -- start: f -> file
  -- word:  f -> file, also-file
  -- all:   f -> file, also-file, alsofile, elf
  search_location = "start",
  aliases = {},
})

-- aliases for German
require("fchar"):setup({
  aliases = {
    a = "ä",
    o = "ö",
    u = "ü",
    s = "ß",
  },
})

-- you may want to turn off the search regex from
-- showing up in the header by doing this
function Header:flags()
  local cwd = self._current.cwd
  local filter = self._current.files.filter

  local t = {}
  if cwd.is_search then
    t[#t + 1] = string.format("search: %s", cwd.domain)
  end
  if filter then
    t[#t + 1] = string.format("filter: %s", filter)
  end
  return #t == 0 and "" or " (" .. table.concat(t, ", ") .. ")"
end

require("dupes"):setup({
  -- Global settings
  save_op = false, -- Save results to file by default
  -- auto_confirm = true, -- Skip confirmation for apply (use with caution!)

  profiles = {
    -- Interactive mode: recursively scan and display duplicates
    interactive = {
      args = { "-r" },
    },
    -- Apply mode: recursively scan and DELETE duplicates
    apply = {
      args = { "-r", "-N", "-d" },
      save_op = true, -- Save results before deletion
    },
    -- Custom profile example (uncomment to use)
    -- custom = {
    -- 	args = { "-r", "-s", },  -- Your custom jdupes flags
    -- },
  },
})
