-- -- REF: https://github.com/adibhanna/nvim/blob/main/lua/core/mason-path.lua
-- --
-- -- Early Mason PATH initialization
-- -- This ensures Mason's bin directory is always first in PATH
-- --
-- -- PURPOSE & PROBLEM IT SOLVES:
-- -- When you install tools via Mason (like golangci-lint, stylua, prettier, etc.),
-- -- they get installed to ~/.local/share/nvim/mason/bin/. However, if you also have
-- -- system versions of these tools installed (via brew, apt, etc.), your shell's
-- -- PATH might find the system version first, leading to:
-- --
-- -- - Version conflicts - Using an older system version instead of the Mason version
-- -- - Configuration issues - Mason tools might be configured differently
-- -- - Inconsistent behavior - Different versions behaving differently
-- --
-- -- THE SOLUTION:
-- -- This file prepends Mason's bin directory to the PATH environment variable,
-- -- ensuring Mason tools are found first:
-- -- Before: PATH = "/usr/local/bin:/usr/bin:/bin"
-- -- After:  PATH = "/Users/you/.local/share/nvim/mason/bin:/usr/local/bin:/usr/bin:/bin"
-- --
-- -- KEY FEATURES:
-- -- 1. Deduplication: Removes any existing Mason bin entries to prevent duplicates in PATH
-- -- 2. Early initialization: Runs before other plugins load, ensuring Mason tools are available immediately
-- -- 3. Directory creation: Creates the Mason bin directory if it doesn't exist yet
-- -- 4. Clean PATH management: Maintains a clean PATH without multiple Mason entries
-- --
-- -- WHY IT'S IMPORTANT:
-- -- In this configuration, Mason manages 16+ tools:
-- -- - LSP servers: gopls, lua-language-server, etc.
-- -- - Formatters: stylua, prettier, goimports, etc.
-- -- - Linters: golangci-lint, eslint_d, luacheck, etc.
-- --
-- -- Without this file, you might end up using system versions instead of Mason versions,
-- -- which could cause:
-- -- - The :MasonVerify command showing tools as "not Mason-managed"
-- -- - Inconsistent formatting/linting behavior
-- -- - Version-specific bugs or missing features
-- --
-- -- INTEGRATION WITH WORKFLOW:
-- -- This file works together with:
-- -- - lua/config/mason-verify.lua - Verifies which tools are Mason-managed
-- -- - lua/plugins/mason.lua - Installs and manages the tools
-- -- - Your linter/formatter configs - Use the Mason versions consistently
-- --
-- -- It's essentially the "foundation" that makes your entire Mason-based toolchain
-- -- work reliably by ensuring the right tools are found in the right order.

-- local mason_bin = vim.fn.stdpath("data") .. "/lsp/mason/bin/"
-- local current_path = vim.env.PATH or ""

-- -- Remove any existing Mason bin entries to prevent duplicates
-- local path_entries = vim.split(current_path, ":")
-- local clean_path_entries = {}
-- local seen = {}

-- for _, entry in ipairs(path_entries) do
--   -- Skip Mason bin entries and duplicates
--   if entry ~= mason_bin and entry ~= "" and not seen[entry] then
--     seen[entry] = true
--     table.insert(clean_path_entries, entry)
--   end
-- end

-- -- Add Mason bin directory at the beginning
-- local new_path = mason_bin .. ":" .. table.concat(clean_path_entries, ":")
-- vim.env.PATH = new_path

-- -- Verify Mason bin directory exists
-- if vim.fn.isdirectory(mason_bin) == 0 then
--   -- Mason not installed yet, create placeholder
--   vim.fn.mkdir(mason_bin, "p")
-- end
--

-- local Input = require("nui.input")
-- local event = require("nui.utils.autocmd").event

-- local function get_prompt_text(prompt, default_prompt)
--   local prompt_text = prompt or default_prompt
--   if prompt_text:sub(-1) == ":" then prompt_text = "[" .. prompt_text:sub(1, -2) .. "]" end
--   return prompt_text
-- end

-- local UIInput = Input:extend("UIInput")

-- function UIInput:init(opts, on_done)
--   local border_top_text = get_prompt_text(opts.prompt, "[Input]")
--   local default_value = tostring(opts.default or "")

--   UIInput.super.init(self, {
--     relative = "cursor",
--     position = {
--       row = 1,
--       col = 0,
--     },
--     size = {
--       -- minimum width 20
--       width = math.max(20, vim.api.nvim_strwidth(default_value)),
--     },
--     border = {
--       style = "rounded",
--       text = {
--         top = border_top_text,
--         top_align = "left",
--       },
--     },
--     win_options = {
--       winhighlight = "NormalFloat:Normal,FloatBorder:Normal",
--     },
--   }, {
--     default_value = default_value,
--     on_close = function() on_done(nil) end,
--     on_submit = function(value) on_done(value) end,
--   })

--   -- cancel operation if cursor leaves input
--   self:on(event.BufLeave, function() on_done(nil) end, { once = true })

--   -- cancel operation if <Esc> is pressed
--   self:map("n", "<Esc>", function() on_done(nil) end, { noremap = true, nowait = true })
-- end

-- local input_ui

-- vim.ui.input = function(opts, on_confirm)
--   assert(type(on_confirm) == "function", "missing on_confirm function")

--   if input_ui then
--     -- ensure single ui.input operation
--     vim.api.nvim_err_writeln("busy: another input is pending!")
--     return
--   end

--   input_ui = UIInput(opts, function(value)
--     if input_ui then
--       -- if it's still mounted, unmount it
--       input_ui:unmount()
--     end
--     -- pass the input value
--     on_confirm(value)
--     -- indicate the operation is done
--     input_ui = nil
--   end)

--   input_ui:mount()
-- end
