local function j()
    return G.GAME.used_vouchers.v_jane_jolly_voucher and "j_jolly" or "j_joker"
end

local required = 2

local function get_uses()
    G.GAME.joker_in_a_tarot = G.GAME.joker_in_a_tarot or required
    return G.GAME.joker_in_a_tarot
end

local blurbs = {
    "M!",
    "Hey! Pick me!",
    "Hee-hee, hoo-hoo!",
    "Looks like the joke is on you!",
    "Ouch, I think the joke is on me!",
    "I won't take up space, I promise!",
    "Don't ask how I ended up in a tarot!",
    "The stakes are only gonna rise here!",
    "I wonder what's the deal with pairs?",
    "It's a little cramped in this tarot...!",
    "Juggling is one of my favourite passtimes!",
    "I'm not just a clown; I'm the whole circus!",
    "Looks like the joke is on the crystal globe!",
    "Who knew even fortunes could be a circus act?",
    "Sometimes, an extra four mult goes a long way!",
    "I can't give four mult if I'm still in this card!",
    "You wouldn't say no to a free negative me, would you?",
    "I'd give you more tickets to JimCon, but I'm fresh out.",
    "Let me tell you, you'd love the show going on in this tarot!",
    "Who knew I'd have access to a great show? That show being you!",
    "I can't help if I'm still in this silly old card, break me out!",
    "I've heard of a round buffoon that lives in a pretty funky town...",
    "You don't need to understand math to enjoy watching the digits climb!",
    "I'm rooting for you! Even if it means I'll never get out of this card...",
    "Seems a little suspicious for a jolly old fella like me to be in this card...",
}

SMODS.Consumable {
    key = "jokerinatarot",
    atlas = "janeacc",
    set = "Tarot",
    loc_txt = {
        name = "#1#-in-a-Tarot",
        text = {
            "Create a {C:dark_edition}Negative {C:attention}#2#",
            "after {C:attention}#3# {}uses {C:inactive}(#4# left)",
            "{C:inactive,E:1}#5#{}",
        },
    },
    loc_vars = function(_, info_queue, card)
        info_queue[#info_queue + 1] = G.P_CENTERS[j()]
        local is_jolly = G.GAME.used_vouchers.v_jane_jolly_voucher

        card.blurb = not card.fake_card and
            (card.blurb or pseudorandom_element(blurbs, pseudoseed("jokerinatarotblurbs"))) or ""

        if is_jolly then
            card.blurb = card.blurb:gsub("four", "eight")
        end

        local desc = is_jolly and "Jolly Joker" or "default Joker"
        local name = is_jolly and "Jolly" or "Joker"
        return {vars = {name, desc, required, required - get_uses(), card.blurb}}
    end,
    pos = {x = 0, y = 1},
    cost = 4,
    can_use = Jane.can_use,
    use = function(_, _, _, _)
        local uses = get_uses() + 1

        if uses < required then
            G.GAME.joker_in_a_tarot = uses
            return
        end

        G.GAME.joker_in_a_tarot = 0
        local card = create_card("Joker", G.jokers, nil, nil, nil, nil, j(), "jokerfromatarot")
        card:set_edition({negative = true}, true)
        card.cost = 1
        card.base_cost = 1
        card.sell_cost = 1
        card.extra_cost = 0
        card.sell_cost_label = card.facing == "back" and "?" or card.sell_cost
        card:add_to_deck()
        G.jokers:emplace(card)
    end,
    bulk_use = function(self, card, area, copier, number)
        for _ = 1, number do
            self:use(card, area, copier)
        end
    end,
}

if Cryptid then
    Cryptid.aliases["joker in a tarot"] = "c_jane_jokerinatarot"
    Cryptid.aliases["joker-in-a-tarot"] = "c_jane_jokerinatarot"
    Cryptid.aliases["jolly in a tarot"] = "c_jane_jokerinatarot"
    Cryptid.aliases["jolly-in-a-tarot"] = "c_jane_jokerinatarot"
end
