local uis = vim.api.nvim_list_uis()
local has_ui = #uis > 0
local mappings = require("dko.mappings")

return {
  -- https://github.com/coder/claudecode.nvim
  {
    "coder/claudecode.nvim",
    dependencies = { "folke/snacks.nvim" },
    config = true,
    keys = {
      { "<leader>a", nil, desc = "AI/Claude Code" },
      { "<leader>ac", "<cmd>ClaudeCode<cr>", desc = "Toggle Claude" },
      { "<leader>af", "<cmd>ClaudeCodeFocus<cr>", desc = "Focus Claude" },
      { "<leader>ar", "<cmd>ClaudeCode --resume<cr>", desc = "Resume Claude" },
      {
        "<leader>aC",
        "<cmd>ClaudeCode --continue<cr>",
        desc = "Continue Claude",
      },
      {
        "<leader>am",
        "<cmd>ClaudeCodeSelectModel<cr>",
        desc = "Select Claude model",
      },
      { "<leader>ab", "<cmd>ClaudeCodeAdd %<cr>", desc = "Add current buffer" },
      {
        "<leader>as",
        "<cmd>ClaudeCodeSend<cr>",
        mode = "v",
        desc = "Send to Claude",
      },
      {
        "<leader>as",
        "<cmd>ClaudeCodeTreeAdd<cr>",
        desc = "Add file",
        ft = { "NvimTree", "neo-tree", "oil", "minifiles" },
      },
      -- Diff management
      { "<leader>aa", "<cmd>ClaudeCodeDiffAccept<cr>", desc = "Accept diff" },
      { "<leader>ad", "<cmd>ClaudeCodeDiffDeny<cr>", desc = "Deny diff" },
    },
  },

  -- https://github.com/jim-at-jibba/nvim-redraft
  {
    "jim-at-jibba/nvim-redraft",
    dependencies = { "folke/snacks.nvim" },
    event = "VeryLazy",
    build = "cd ts && npm install && npm run build",
    config = true,
    keys = vim.tbl_values(mappings.nvim_redraft),
    opts = {
      keys = {
        {
          mappings.nvim_redraft.edit,
          function()
            require("nvim-redraft").edit()
          end,
          mode = "v",
          desc = "AI Edit Selection",
        },
        {
          mappings.nvim_redraft.select_model,
          function()
            require("nvim-redraft").select_model()
          end,
          desc = "Select AI Model",
        },
      },
      llm = {
        models = {
          {
            provider = "openai", -- "openai", "anthropic", or "xai"
            model = "gpt-4o-mini",
          },
          {
            provider = "anthropic",
            model = "claude-3-5-sonnet-20241022",
            label = "Claude 3.5 Sonnet",
          },
        },
      },
      -- See Configuration section for options
    },
  },

  -- https://github.com/olimorris/codecompanion.nvim
  {
    "olimorris/codecompanion.nvim",
    cmd = {
      "CodeCompanion",
      "CodeCompanionActions",
      "CodeCompanionChat",
      "CodeCompanionCmd",
    },
    cond = has_ui,
    dependencies = {
      "nvim-lua/plenary.nvim",
      "nvim-treesitter/nvim-treesitter",
    },
    enabled = false,
    opts = {
      -- display = {
      --   diff = {
      --     provider = "mini_diff",
      --   },
      -- },
      -- opts = {
      -- log_level = "DEBUG",
      -- },
      strategies = {
        chat = {
          adapter = "ollama",
        },
        inline = {
          adapter = "ollama",
        },
      },
    },
  },
}
