local telescope = require('telescope')
local actions = require('telescope.actions')
local builtin = require('telescope.builtin')

local telescope_last = 0
function telescope_resume()
    if telescope_last == 0 then
        telescope_last = 1
        builtin.live_grep()
    else
        builtin.resume()
    end
end

local files_config = {
    cache_picker = false,
    layout_strategy = "vertical",
    layout_config = {
        prompt_position = "top",
        mirror = true,
        width = 0.8,
    },
}

telescope.setup {
    defaults = {
        sorting_strategy = "ascending",
        vimgrep_arguments = {
            'rg',
            '--hidden',
            '--no-ignore',
            '--color=never',
            '--with-filename',
            '--line-number',
            '--column',
            '--smart-case',
            '--no-heading',
            '-u',
        },
        preview = {
            treesitter = false
        },
        file_ignore_patterns = {
            '.git/',
            '.venv/',
            '.pytest_cache/',
            'target/',
        },
    },
    pickers = {
        live_grep = {
            mappings = {
                i = { ["<c-f>"] = actions.to_fuzzy_refine },
                n = { ["<c-f>"] = telescope_resume },
            },
            layout_strategy = 'vertical',
            layout_config = {
                prompt_position = "top",
                mirror = true,
                width = 0.8,
            },
        },
        find_files = vim.tbl_extend("force", files_config, {
            hidden = true,
        }),
        git_files = files_config,
    },
}
