local LrDialogs = import "LrDialogs"
local LrPrefs = import "LrPrefs"

local prefs = LrPrefs.prefsForPlugin()
local cleared = 0

local function clearKey(key)
    if prefs[key] ~= nil then
        prefs[key] = nil
        cleared = cleared + 1
    end
end

local exactKeys = {
    "coreLastMode",
    "coreLastFilmGroup",
    "coreLastEmulsion",
    "coreLastWorkflow",
    "coreLastStrength",
    "coreLastPreviewActive",
    "quickLastFilmGroup",
    "quickLastEmulsion",
    "quickLastWorkflow",
    "quickLastStrength",
    "proLastFilmGroup",
    "proLastEmulsion",
    "proLastWorkflow",
    "proLastStrength",
    "panel_iiv_apply_on_panel1_force",
}

for _, key in ipairs(exactKeys) do
    clearKey(key)
end

for key in pairs(prefs) do
    local name = tostring(key or "")
    if string.match(name, "^core")
        or string.match(name, "^quick")
        or string.match(name, "^proLast")
        or string.match(name, "^proMode")
        or string.match(name, "^pro_")
        or string.match(name, "^panel_iiv_")
        or string.match(name, "^panel2_photo_")
        or string.match(name, "^tools_print_photo_")
    then
        clearKey(name)
    end
end

LrDialogs.message(
    "Analog Signature",
    "Reset Refactor UI State complete. Cleared keys: " .. tostring(cleared),
    "info"
)
