local fs = require("functions.fs")

local function tocamel(s)
  return string.upper(string.sub(s, 1, 1)) .. string.sub(s, 2)
end

vim.api.nvim_create_user_command("CreateRandomFile", function()
  local words = vim.fn.readfile(vim.fs.normalize("~/.config/nvim/assets/words.txt"))

  local wordsRequests = math.random(2, 4)

  local wordsFinal = ""
  for i = 1, wordsRequests do
    local word = words[math.random(#words)]
    wordsFinal = wordsFinal .. tocamel(word)
  end

  local picker = Snacks.picker.get({ source = "explorer" })
  local currentFile = picker[1]:current().file
  local directory = currentFile
  if vim.fn.isdirectory(directory) == 0 then
    directory = vim.fs.dirname(directory)
  end

  local path = vim.fs.joinpath(directory, wordsFinal .. ".md")
  os.execute(string.format('touch "%s"', path))
end, {})
