-- Core setup
require("fk_plugins.fkcore.fk_diagnosis").setup()
require("fk_plugins.fkui.colors")

-- 🚀 Bootstrap lazy.nvim if not installed
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({
    "git", "clone", "--filter=blob:none",
    "https://github.com/folke/lazy.nvim.git",
    lazypath,
  })
end
vim.opt.rtp:prepend(lazypath)

-- 🔐 Safe require
local function safe_require(module)
  local ok, mod = pcall(require, module)
  if not ok then
    vim.notify("Failed to load " .. module, vim.log.levels.ERROR)
  end
  return mod
end

-- 📦 Lazy plugin setup
require("lazy").setup({

  -- 💅 Statusline
  {
    "nvim-lualine/lualine.nvim",
    config = function()
      require("fk_plugins.fkcore.fk_status").setup({})
    end,
  },

    -- FK ToolKit Installer/dependencies
{
  "MunifTanjim/nui.nvim",
  "nvim-lua/plenary.nvim"
},

  -- ✨ Transparent background
  {
    "xiyaowong/nvim-transparent",
    config = function()
      require("transparent").setup({
        enable = true,
        extra_groups = {
          "Normal", "NormalNC", "NormalFloat", "FloatBorder",
          "Pmenu", "PmenuSel", "PmenuSbar", "PmenuThumb",
          "LspFloatWinNormal", "LspFloatWinBorder", "LspInfoBorder",
          "NoiceCmdlinePopup", "NoiceCmdlinePopupBorder",
          "CmpDocumentation", "CmpDocumentationBorder",
          "NormalFloat", "NvimTreeNormal", "FloatBorder",
          "TelescopeNormal", "ToggleTermNormal", "ToggleTermBorder",
        },
        exclude_groups = {},
      })
    end,
  },

  -- 🎨 Catppuccin colorscheme
  {
    "catppuccin/nvim",
    name = "catppuccin",
    priority = 1000,
    config = function()
      require("catppuccin").setup({
        flavour = "mocha",
        transparent_background = true,
      })

      local cp = require("catppuccin.palettes").get_palette("mocha")

      -- Highlight customizations
      vim.api.nvim_set_hl(0, "NavicIconsFunction", { fg = cp.blue })
      vim.api.nvim_set_hl(0, "NavicIconsClass", { fg = cp.yellow })
      vim.api.nvim_set_hl(0, "NavicIconsVariable", { fg = cp.text })
      vim.api.nvim_set_hl(0, "NavicIconsMethod", { fg = cp.green })
      vim.api.nvim_set_hl(0, "NavicIconsModule", { fg = cp.mauve })
      vim.api.nvim_set_hl(0, "NavicIconsNamespace", { fg = cp.teal })
      vim.api.nvim_set_hl(0, "NavicIconsInterface", { fg = cp.lavender })
      vim.api.nvim_set_hl(0, "NavicText", { fg = cp.subtext1 })
      vim.api.nvim_set_hl(0, "NavicSeparator", { fg = cp.overlay0 })

      vim.api.nvim_set_hl(0, "DiagnosticSignError", { fg = cp.red, bg = "NONE" })
      vim.api.nvim_set_hl(0, "DiagnosticSignWarn", { fg = cp.peach, bg = "NONE" })
      vim.api.nvim_set_hl(0, "DiagnosticSignHint", { fg = cp.yellow, bg = "NONE" })
      vim.api.nvim_set_hl(0, "DiagnosticSignInfo", { fg = cp.pink, bg = "NONE" })
      vim.api.nvim_set_hl(0, "DiagnosticVirtualTextError", { fg = cp.red })
      vim.api.nvim_set_hl(0, "DiagnosticVirtualTextWarn", { fg = cp.yellow })
      vim.api.nvim_set_hl(0, "DiagnosticVirtualTextHint", { fg = cp.yellow })
      vim.api.nvim_set_hl(0, "DiagnosticVirtualTextInfo", { fg = cp.pink })
    end,
  },

  -- 🧩 Indentation Guides
  {
    "echasnovski/mini.indentscope",
    version = false,
    event = "BufReadPre",
    config = function()
      require("fk_configs.fk_indent").setup()
    end,
  },

  -- 📁 File Explorer
  {
    "nvim-neo-tree/neo-tree.nvim",
    branch = "v3.x",
    dependencies = {
      "nvim-lua/plenary.nvim",
      "nvim-tree/nvim-web-devicons",
      "MunifTanjim/nui.nvim",
    },
    config = function()
      require("fk_plugins.fk_neotre").setup()
    end,
  },

-- lazy.nvim
{
    "sontungexpt/url-open",
    event = "VeryLazy",
    cmd = "URLOpenUnderCursor",
    config = function()
        local status_ok, url_open = pcall(require, "url-open")
        if not status_ok then
            return
        end
        url_open.setup ({})
    end,
},
  -- 🔁 Bufferline
  {
    "akinsho/bufferline.nvim",
    version = "*",
    dependencies = { "nvim-tree/nvim-web-devicons" },
    event = "BufReadPre",
    config = function()
      require("fk_plugins.fkui.fk_buffer").setup()
    end,
  },

  -- 🔍 Telescope
  {
    "nvim-telescope/telescope.nvim",
    tag = "0.1.6",
    dependencies = { "nvim-lua/plenary.nvim" },
    config = function()
      require("fk_plugins.fk_telescope").setup()
    end,
  },
{
  "smjonas/inc-rename.nvim",
   config = true,
},
    {
  'b0o/incline.nvim',
  config = function()
    require('incline').setup({
      render = function(props)
        local filename = vim.fn.fnamemodify(vim.api.nvim_buf_get_name(props.buf), ":t")
        if filename == "" then return "" end
        local ft_icon, ft_color = require("nvim-web-devicons").get_icon_color(filename)
        local buffer = {
          { ft_icon, guifg = ft_color },
          { " " },
          { filename, gui = "bold" },
        }
        return buffer
      end,
    })
  end,
  -- Optional: Lazy load Incline
  event = 'VeryLazy',
},

  -- 💡 Lightbulb for code actions
  {
    'kosayoda/nvim-lightbulb',
    config = function()
      require('nvim-lightbulb').setup({
        autocmd = {
          enabled = true
        },
        sign = {
          enabled = true,
          text = '💡',
        },
      })
    end,
  },
  ---Auto pair 
    {
    'windwp/nvim-autopairs',
    event = "InsertEnter",
    config = true
    -- use opts = {} for passing setup options
    -- this is equivalent to setup({}) function
},

    --Fkvim Code Runner 
{
  "CRAG666/code_runner.nvim",
  dependencies = { "akinsho/toggleterm.nvim" },
  config = function()
    require("fk_plugins.fkcore.fkrun").setup()
  end,
},
  {
    "nvim-telescope/telescope-fzf-native.nvim",
    build = "make",
    cond = vim.fn.executable("make") == 1,
    config = function()
      require("telescope").load_extension("fzf")
    end,
  },

  

  -- 🌈 Treesitter
  {
    "nvim-treesitter/nvim-treesitter",
    build = ":TSUpdate",
    event = { "BufReadPost", "BufNewFile" },
    config = function()
      require("nvim-treesitter.configs").setup({
        ensure_installed = { "lua", "javascript", "html", "css", "markdown", "vim" },
        highlight = {
          enable = true,
          additional_vim_regex_highlighting = false,
        },
        indent = { enable = true },
      })
    end,
  },

-- 📝 FkNotes Plugin Setup
  {
    "flashcodes-themayankjha/Fknotes.nvim",
        dependencies = {
    'MunifTanjim/nui.nvim',
    'j-hui/fidget.nvim', -- Optional: for better UI feedback
  },
    config = function()
      require("fknotes").setup({
             default_task_priority = 'none',

                ui = {
                    menu_height = 15,
                },
                 keymaps = {
                     open_menu = "<leader>fn",
                     new_task = "<leader>nt",
                     browse_tasks = "<leader>ln",
                    }
      })
    end,
  },

  -- ✨ Completion
  {
    "hrsh7th/nvim-cmp",
    dependencies = {
      "hrsh7th/cmp-nvim-lsp",
      "hrsh7th/cmp-buffer",
      "hrsh7th/cmp-path",
      "hrsh7th/cmp-cmdline",
      "L3MON4D3/LuaSnip",
      "saadparwaiz1/cmp_luasnip",
      "rafamadriz/friendly-snippets",
      "onsails/lspkind.nvim",
    },
    config = function()
      require("fk_plugins.fkcore.autofksuggest").setup()
    end,
  },

  -- 🧠 LSP & Mason
  { "neovim/nvim-lspconfig", lazy = true },
  { "williamboman/mason.nvim", config = true },
  {
    "williamboman/mason-lspconfig.nvim",
    config = function()
      require("mason-lspconfig").setup({
        ensure_installed = { "lua_ls", "vtsls", "pyright", "jdtls" },
      })
      require("fk_plugins.fkcore.autofk").setup()
    end,
  },
{
  "mfussenegger/nvim-jdtls",
  ft = { "java" },
  config = function()
    local jdtls = require("jdtls")

    local root_markers = { ".git", "mvnw", "gradlew", "pom.xml", "build.gradle" }
    local root_dir = require("jdtls.setup").find_root(root_markers)

    local project_name = vim.fn.fnamemodify(root_dir, ":p:h:t")
    local workspace_dir = vim.fn.stdpath("data") .. "/jdtls-workspace/" .. project_name

    local config = {
      cmd = { "jdtls" },
      root_dir = root_dir,
      settings = {
        java = {},
      },
      init_options = {
        workspaceFolders = { workspace_dir },
      },
    }

    jdtls.start_or_attach(config)
  end,
},
--FKui:  Dashboard
{
  "nvimdev/dashboard-nvim",
  lazy = false,
  dependencies = {
    "nvim-telescope/telescope.nvim",
    "folke/persistence.nvim",
    "catppuccin/nvim",
  },
  opts = function()
    return require("fk_plugins.fkui.fk_dashboard")
  end,
},

  {
    "folke/persistence.nvim",
    event = "BufReadPre",
    opts = {
      dir = vim.fn.stdpath("data") .. "/sessions/",
      options = { "buffers", "curdir", "tabpages", "winsize" },
    },
  },

-- ⌨️ Which Key
{
  "folke/which-key.nvim",
  event = "VeryLazy",
  opts = {},
  keys = {
    {
      "<leader>?",
      function()
        require("which-key").show({ global = false })
      end,
      desc = "Buffer Local Keymaps (which-key)",
    },
  },
},

    -- 🧪 Terminal
  {
    "akinsho/toggleterm.nvim",
    version = "*",
    event = "VeryLazy",
    config = function()
      require("fk_plugins.fk_term").setup()
    end,
  },

  -- 🔍 Git & Comments
  { "lewis6991/gitsigns.nvim" },
  { "numToStr/Comment.nvim" },

  -- 🧭 Navic Breadcrumbs
  {
    "SmiteshP/nvim-navic",
    event = "LspAttach",
    config = function()
      require("nvim-navic").setup({
        highlight = true,
        separator = "  ",
        depth_limit = 5,
      })
    end,
  },

  -- 🛎️ Notifications
-- nvim-notify
{
  "rcarriga/nvim-notify",
  lazy = false,
  config = function()
    require("fk_plugins.fkui.fknotifier").setup()
  end,
},

-- Noice for cmdline UI
{
  "folke/noice.nvim",
  event = "VeryLazy",
  opts = {
    cmdline = {
      enabled = true,
      view = "cmdline_popup",
    },
    messages = {
      enabled = false,
    },
    lsp = {
      enabled = false,
    },
    presets = {
      bottom_search = true, -- use a classic bottom cmdline for search
      command_palette = true, -- position the cmdline and popupmenu together
      long_message_to_split = true, -- long messages will be sent to a split
      inc_rename = false, -- enables an input dialog for inc-rename.nvim
      lsp_doc_border = false, -- add a border to hover docs and signature help
    },
  },
},

-- fidget.nvim
{
  "j-hui/fidget.nvim",
  config = function()
    require("fidget").setup({
      notification = {
        window = {
          winblend = 0,
          border = "none",
        },
        view = {
          icon = " fidget",
          group_separator = " ",
          group_separator_hl = "Comment",
        },
      },
      -- Options for configuring the notification window
      window = {
        blend = 0, -- Amount of transparency
        border = "none", -- Border style
        relative = "win", -- What the window is relative to
        anchor = "SW", -- Anchor to the bottom-right corner of the window
        zindex = 45, -- Stacking order
      },
    })
  end,
}

})
