SMODS.Atlas {
    px = 34,
    py = 34,
    frames = 21,
    key = "janeblinds",
    atlas_table = "ANIMATION_ATLAS",
    path = Jane.config.texture_pack .. "/bl_jane_blinds.png"
}

local final_operations = {
    [1] = {"+", "UI_CHIPS"},
    [2] = {"X", "UI_MULT"},
    [3] = {"^", G.C.jane_RGB},
}

local function offset_operator(by)
    local function set(number)
        if G.GAME then
            G.GAME.operator = math.max(math.min(number, 3), 1)
        end
    end

    local previous = Jane.get_operator()
    set(by + previous)
    by = Jane.get_operator()
    local txt = final_operations[by][1] ---@diagnostic disable-next-line: cast-local-type
    local col = type(final_operations[by][2]) == "table" and final_operations[by][2] or G.C[final_operations[by][2]]

    Jane.q(function()
        local changed_text = false

        for _, outer in pairs(G.STAGE_OBJECTS) do
            if type(outer) == "table" then
                for _, inner in pairs(outer) do
                    if type(inner) == "table" and
                        type(inner.config) == "table" and
                        (inner.config.text == final_operations[previous][1] or
                        inner.config.text == final_operations[2][1]) and
                        inner.config.text_drawable then
                        if inner.config.text ~= txt then
                            changed_text = true
                        end

                        inner.config.text = txt
                        inner.config.text_drawable:set(txt)
                        inner.config.colour = col
                        inner:juice_up(0.8, 0.5)
                    end
                end
            end
        end

        if changed_text then
            play_sound("button", 1.1, 0.65)
        end

        return true
    end)
end

local function to_number(x)
    return type(x) == "table" and x:to_number() or x
end

SMODS.Blind	{
    loc_txt = {
        name = "The Descending",
        text = {"Decrease Chip-Mult", "operator by 1 level"}
    },
    key = "descending",
    config = {},
    boss = {min = 1, max = 10, hardcore = true},
    boss_colour = HEX("b200ff"),
    atlas = "janeblinds",
    pos = {x = 0, y = 0},
    vars = {},
    dollars = 6,
    defeat = function(_)
        if not Cryptid then
            G.GAME.operator = 2
            offset_operator(0)
        elseif not G.GAME.blind.disabled then
            offset_operator(1)
        end
    end,
    disable = function(_)
        offset_operator(1)
    end,
    drawn_to_hand = function(_)
        offset_operator(0)
    end,
    press_play = function(_)
        offset_operator(0)
    end,
    set_blind = function(self)
        if to_number(self.mult) == 0 then
            self.chips = math.floor(8 * math.sqrt(get_blind_amount(G.GAME.round_resets.ante)))
        end

        offset_operator(-1)
    end,
}

SMODS.Blind	{
    loc_txt = {
        name = "The Insignia",
        text = {"Hand must contain", "only one suit"}
    },
    key = "insignia",
    config = {},
    boss = {min = 2, max = 10, no_orb = true, hardcore = true},
    boss_colour = HEX("a5aa00"),
    atlas = "janeblinds",
    pos = {x = 0, y = 9},
    vars = {},
    dollars = 5,
    mult = 2,
    debuff_hand = function(_, cards, _, _, _)
        local numsuits = 0
        local checked_suits = {}

        for _, card in ipairs(cards) do
            if not card:nosuit() and not checked_suits[card.base.suit] then
                numsuits = numsuits + 1
                checked_suits[card.base.suit] = true

                if numsuits > 1 then
                    return true
                end
            end
        end
    end,
}

SMODS.Blind	{
    loc_txt = {
        name = "The Wee",
        text = {"Only 2s can be played"}
    },
    key = "wee",
    config = {},
    boss = {min = 1, max = 10, no_orb = true, hardcore = true},
    boss_colour = HEX("7F3F3F"),
    atlas = "janeblinds",
    pos = {x = 0, y = 3},
    vars = {},
    dollars = 2,
    debuff_hand = function(_, cards, _, _, _)
        for _, v in ipairs(cards) do
            if v:norank() or v:get_id() ~= 2 then
                return true
            end
        end
    end,
    get_loc_debuff_text = function(_)
        return "Hand must contain only 2s"
    end,
    recalc_debuff = function(_, card, _)
        return card:norank() or card:get_id() ~= 2
    end,
    set_blind = function(self)
        if to_number(self.mult) == 0 then
            self.chips = 22
        end
    end,
}
