-- ~/.config/nvim/lua/plugins/live-preview.lua
return {
  "brianhuster/live-preview.nvim",
  dev = false,
  cmd = { "LivePreview", "LivePreviewStop" },
  keys = {
    { "<leader>lp", "<cmd>LivePreview<CR>", desc = "Start live HTML preview" },
  },
  config = function()
    require("live-preview").setup({
      port = 3027, -- local server port
      browser = "default", -- system browser
      dynamic_root = true, -- serve from the project root
      autokill = false, -- keep server alive when you leave nvim
    })

    -- (optional) auto-save on change so the browser refreshes
    vim.o.autowriteall = true
    vim.api.nvim_create_autocmd({ "InsertLeavePre", "TextChanged" }, {
      pattern = "*.{html,htm,css,js,md}",
      callback = function()
        vim.cmd("silent! write")
      end,
    })
  end,
}
