local E, L, V, P, G = unpack(ElvUI);
local mPlugin = "mMediaTag"
local mMT = E:GetModule(mPlugin);
local addon, ns = ...
local LSM = LibStub("LibSharedMedia-3.0")
local TextureList, mIconsList = {}, {}
local mFontFlags = {
                        NONE = L["NONE"],
                        OUTLINE = 'Outline',
                        THICKOUTLINE = 'Thick',
                        MONOCHROME = '|cffaaaaaaMono|r',
                        MONOCHROMEOUTLINE = '|cffaaaaaaMono|r Outline',
                        MONOCHROMETHICKOUTLINE = '|cffaaaaaaMono|r Thick',
                    }


local function mTextureList()
    wipe(TextureList)
    local i = 0
    for i in pairs(mIconsList) do
        TextureList[i] = mIconsList[i].icon
    end
	return TextureList
end

local function mTGAtoIcon(file, i)
	return format("|T%s:16:16:0:0:128:128|t %s - %s", file, L["Icon"], i)
end

local function mGetTexturePath(file)
    return format("Interface\\AddOns\\ElvUI_mMediaTag\\media\\dock\\dockicon%s.tga", file)
end

local function SetupDockIconList()
    wipe(mIconsList)

    for i=1, 138, 1 do
        local path = mGetTexturePath(i)
        mIconsList[i] = {["file"] = path, ["icon"] = mTGAtoIcon(path, i)}
    end
end

local function OptionsDock()
    SetupDockIconList()

	E.Options.args.mMediaTag.args.datatext.args.docks.args = {
        dockgeneral = {
            order = 10,
            type = "group",
            name = L['General'],
            args = {
                headerdockgeneralcolor= {
                    order = 0,
                    type = "header",
                    name = L["Color"],
                },
                docknormalstyle = {
                    order = 10,
                    type = 'select',
                    name = L["Normal Color Style"],
                    get = function(info) return E.db[mPlugin].mDock.normal.style end,
                    set = function(info, value)
                        E.db[mPlugin].mDock.normal.style = value
                    end,
                    values = {
                        class  = L["Class"],
                        custom = L["Custom"],
                    },
                },
                docknormalcolor = {
                    type = 'color',
                    order = 11,
                    name = "Custom Icon Color",
                    desc = L["Custom Icon Color"],
                    hasAlpha = true,
                    get = function(info)
                        local t = E.db[mPlugin].mDock.normal
                        return t.r, t.g, t.b, t.a
                    end,
                    set = function(info, r, g, b, a)
                        local t = E.db[mPlugin].mDock.normal
                        t.r, t.g, t.b, t.a = r, g, b, a
                    end,
                },
                dockgeneralspacer1 = {
                    order = 19,
                    type = "description",
                    name = "\n",
                },
                dockhoverstyle = {
                    order = 20,
                    type = 'select',
                    name = L["Hover Color Style"],
                    get = function(info) return E.db[mPlugin].mDock.hover.style end,
                    set = function(info, value)
                        E.db[mPlugin].mDock.hover.style = value
                    end,
                    values = {
                        class  = L["Class"],
                        custom = L["Custom"],
                    },
                },
                dockhovercolor = {
                    type = 'color',
                    order = 21,
                    name = "Custom hover Color",
                    desc = L["Custom hover Color"],
                    hasAlpha = true,
                    get = function(info)
                        local t = E.db[mPlugin].mDock.hover
                        return t.r, t.g, t.b, t.a
                    end,
                    set = function(info, r, g, b, a)
                        local t = E.db[mPlugin].mDock.hover
                        t.r, t.g, t.b, t.a = r, g, b, a
                    end,
                },
                dockgeneralspacer2 = {
                    order = 29,
                    type = "description",
                    name = "\n",
                },
                dockclickstyle = {
                    order = 30,
                    type = 'select',
                    name = L["Click Color Style"],
                    get = function(info) return E.db[mPlugin].mDock.click.style end,
                    set = function(info, value)
                        E.db[mPlugin].mDock.click.style = value
                    end,
                    values = {
                        class  = L["Class"],
                        custom = L["Custom"],
                    },
                },
                dockclickcolor = {
                    type = 'color',
                    order = 31,
                    name = "Custom click Color",
                    desc = L["Custom click Color"],
                    hasAlpha = true,
                    get = function(info)
                        local t = E.db[mPlugin].mDock.click
                        return t.r, t.g, t.b, t.a
                    end,
                    set = function(info, r, g, b, a)
                        local t = E.db[mPlugin].mDock.click
                        t.r, t.g, t.b, t.a = r, g, b, a
                    end,
                },
                dockgeneralspacer3 = {
                    order = 39,
                    type = "description",
                    name = "\n",
                },
                docknotificationstyle = {
                    order = 40,
                    type = 'select',
                    name = L["Nottification Color Style"],
                    get = function(info) return E.db[mPlugin].mDock.nottification.style end,
                    set = function(info, value)
                        E.db[mPlugin].mDock.nottification.style = value
                    end,
                    values = {
                        class  = L["Class"],
                        custom = L["Custom"],
                    },
                },
                docknotificationcolor = {
                    type = 'color',
                    order = 42,
                    name = "Custom nottification Color",
                    desc = L["Custom nottification Color"],
                    hasAlpha = true,
                    get = function(info)
                        local t = E.db[mPlugin].mDock.nottification
                        return t.r, t.g, t.b, t.a
                    end,
                    set = function(info, r, g, b, a)
                        local t = E.db[mPlugin].mDock.nottification
                        t.r, t.g, t.b, t.a = r, g, b, a
                    end,
                },
                dockgeneralspacer4 = {
                    order = 49,
                    type = "description",
                    name = "\n",
                },
                headerdockgeneralsettings= {
                    order = 50,
                    type = "header",
                    name = L["Settings"],
                },
                dockgeneralsize = {
                    order = 51,
                    name = L["Icon size"],
                    desc = L["Dock Icon size."],
                    type = "range",
                    min = 16, max = 128, step = 2,
                    get = function(info)
                    return E.db[mPlugin].mDock.sizexy
                    end,
                    set = function(info, value)
                        E.db[mPlugin].mDock.sizexy = value
                    end,
                },
                dockgeneralgrowsize = {
                    order = 52,
                    name = L["Icon hover size"],
                    desc = L["Dock Icon hover size."],
                    type = "range",
                    min = 2, max = 64, step = 2,
                    get = function(info)
                    return E.db[mPlugin].mDock.growsize
                    end,
                    set = function(info, value)
                        E.db[mPlugin].mDock.growsize = value
                    end,
                },
                dockgeneralfadetime = {
                    order = 53,
                    name = L["Icon fade time"],
                    desc = L["Dock Icon fade time."],
                    type = "range",
                    min = .25, max = 1, step = .01,
                    get = function(info)
                    return E.db[mPlugin].mDock.fadetime
                    end,
                    set = function(info, value)
                        E.db[mPlugin].mDock.fadetime = value
                    end,
                },
                dockgeneralfadealpha = {
                    order = 54,
                    name = L["Icon fade Alpha"],
                    desc = L["Dock Icon fade Alpha."],
                    type = "range",
                    min = 0, max = 1, step = .01,
                    get = function(info)
                    return E.db[mPlugin].mDock.fadealpha
                    end,
                    set = function(info, value)
                        E.db[mPlugin].mDock.fadealpha = value
                    end,
                },
                dockgeneralspacer5 = {
                    order = 55,
                    type = "description",
                    name = "\n",
                },
                dockgeneraltip = {
                    order = 56,
                    type = 'select',
                    name = L["Tooltip Style"],
                    get = function(info) return E.db[mPlugin].mDock.tip.mode end,
                    set = function(info, value)
                        E.db[mPlugin].mDock.tip.mode = value
                        if value ~= "none" then 
                            E.db[mPlugin].mDock.tip.enable = true 
                        else 
                            E.db[mPlugin].mDock.tip.enable = false 
                        end
                    end,
                    values = {
                        none    = L["None"],
                        simply  = L["Simply"],
                        extend  = L["Extend"],
                    },
                },
                dockgeneralspacer6 = {
                    order = 59,
                    type = "description",
                    name = "\n",
                },
                headerdockgeneralfont= {
                    order = 60,
                    type = "header",
                    name = L["Font"],
                },
                dockgeneralfont = {
                    type = 'select', dialogControl = 'LSM30_Font',
                    order = 61,
                    name = L["Default Font"],
                    values = LSM:HashTable('font'),
                    get = function(info) return E.db[mPlugin].mDock.font end,
                    set = function(info, value) E.db[mPlugin].mDock.font = value; E:UpdateMedia(); E:UpdateFontTemplates(); end,
                },
                dockgeneralfontSize = {
                    order = 62,
                    name = L["Font Size"],
                    type = 'range',
                    min = 6, max = 64, step = 1,
                    softMin = 8, softMax = 32,
                    get = function(info) return E.db[mPlugin].mDock.fontSize end,
                    set = function(info, value) E.db[mPlugin].mDock.fontSize = value; E:UpdateMedia(); E:UpdateFontTemplates(); end,
                },
                dockgeneralfontStyle = {
                    type = 'select',
                    order = 63,
                    name = L["Font Outline"],
                    values = mFontFlags,
                    get = function(info) return E.db[mPlugin].mDock.fontflag end,
                    set = function(info, value) E.db[mPlugin].mDock.fontflag = value; E:UpdateMedia(); E:UpdateFontTemplates(); end,
                },

            },
        },
        dockachievment = {
            order = 20,
            type = "group",
            name = ACHIEVEMENT_BUTTON,
            args = {
                dockachievmenticon = {
                    order = 1,
                    type = 'select',
                    name = L["Icon"],
                    get = function(info) return E.db[mPlugin].mDock.textures.achievement.name end,
                    set = function(info, value)
                        E.db[mPlugin].mDock.textures.achievement.name = value
                        E.db[mPlugin].mDock.textures.achievement.path = mIconsList[value].file
                    end,
                    values = mTextureList(),
                },
            },
        },
        dockblizzardstore = {
            order = 30,
            type = "group",
            name = BLIZZARD_STORE,
            args = {
                dockblizzardstoreicon = {
                    order = 1,
                    type = 'select',
                    name = L["Icon"],
                    get = function(info) return E.db[mPlugin].mDock.textures.blizzardstore.name end,
                    set = function(info, value)
                        E.db[mPlugin].mDock.textures.blizzardstore.name = value
                        E.db[mPlugin].mDock.textures.blizzardstore.path = mIconsList[value].file
                    end,
                    values = mTextureList(),
                },
            },
        },
        dockcharcter = {
            order = 40,
            type = "group",
            name = CHARACTER_BUTTON,
            args = {
                dockcharctericon = {
                    order = 1,
                    type = 'select',
                    name = L["Icon"],
                    get = function(info) return E.db[mPlugin].mDock.textures.character.name end,
                    set = function(info, value)
                        E.db[mPlugin].mDock.textures.character.name = value
                        E.db[mPlugin].mDock.textures.character.path = mIconsList[value].file
                    end,
                    values = mTextureList(),
                },
            },
        },
        dockcollection = {
            order = 50,
            type = "group",
            name = COLLECTIONS,
            args = {
                dockcollectionicon = {
                    order = 1,
                    type = 'select',
                    name = L["Test Icon"],
                    get = function(info) return E.db[mPlugin].mDock.textures.collection.name end,
                    set = function(info, value)
                        E.db[mPlugin].mDock.textures.collection.name = value
                        E.db[mPlugin].mDock.textures.collection.path = mIconsList[value].file
                    end,
                    values = mTextureList(),
                },
            },
        },
        dockencounter = {
            order = 60,
            type = "group",
            name = ENCOUNTER_JOURNAL,
            args = {
                dockencountericon = {
                    order = 1,
                    type = 'select',
                    name = L["Icon"],
                    get = function(info) return E.db[mPlugin].mDock.textures.encounter.name end,
                    set = function(info, value)
                        E.db[mPlugin].mDock.textures.encounter.name = value
                        E.db[mPlugin].mDock.textures.encounter.path = mIconsList[value].file
                    end,
                    values = mTextureList(),
                },
            },
        },
        dockguild = {
            order = 70,
            type = "group",
            name = GUILD_AND_COMMUNITIES,
            args = {
                dockguildicon = {
                    order = 1,
                    type = 'select',
                    name = L["Icon"],
                    get = function(info) return E.db[mPlugin].mDock.textures.guild.name end,
                    set = function(info, value)
                        E.db[mPlugin].mDock.textures.guild.name = value
                        E.db[mPlugin].mDock.textures.guild.path = mIconsList[value].file
                    end,
                    values = mTextureList(),
                },
            },
        },
        docklfd = {
            order = 80,
            type = "group",
            name = DUNGEONS_BUTTON,
            args = {
                docklfdicon = {
                    order = 1,
                    type = 'select',
                    name = L["Icon"],
                    get = function(info) return E.db[mPlugin].mDock.textures.lfd.name end,
                    set = function(info, value)
                        E.db[mPlugin].mDock.textures.lfd.name = value
                        E.db[mPlugin].mDock.textures.lfd.path = mIconsList[value].file
                    end,
                    values = mTextureList(),
                },
            },
        },
        dockmainmenu = {
            order = 90,
            type = "group",
            name = MAINMENU_BUTTON,
            args = {
                dockmainmenuicon = {
                    order = 1,
                    type = 'select',
                    name = L["Icon"],
                    get = function(info) return E.db[mPlugin].mDock.textures.mainmenu.name end,
                    set = function(info, value)
                        E.db[mPlugin].mDock.textures.mainmenu.name = value
                        E.db[mPlugin].mDock.textures.mainmenu.path = mIconsList[value].file
                    end,
                    values = mTextureList(),
                },
            },
        },
        dockquest = {
            order = 100,
            type = "group",
            name = QUESTLOG_BUTTON,
            args = {
                dockquesticon = {
                    order = 1,
                    type = 'select',
                    name = L["Icon"],
                    get = function(info) return E.db[mPlugin].mDock.textures.quest.name end,
                    set = function(info, value)
                        E.db[mPlugin].mDock.textures.quest.name = value
                        E.db[mPlugin].mDock.textures.quest.path = mIconsList[value].file
                    end,
                    values = mTextureList(),
                },
            },
        },
        dockspellbook = {
            order = 110,
            type = "group",
            name = SPELLBOOK_ABILITIES_BUTTON,
            args = {
                dockspellbookicon = {
                    order = 1,
                    type = 'select',
                    name = L["Icon"],
                    get = function(info) return E.db[mPlugin].mDock.textures.spellbook.name end,
                    set = function(info, value)
                        E.db[mPlugin].mDock.textures.spellbook.name = value
                        E.db[mPlugin].mDock.textures.spellbook.path = mIconsList[value].file
                    end,
                    values = mTextureList(),
                },
            },
        },
        docktalent = {
            order = 120,
            type = "group",
            name = TALENTS_BUTTON,
            args = {
                docktalenticon = {
                    order = 1,
                    type = 'select',
                    name = L["Icon"],
                    get = function(info) return E.db[mPlugin].mDock.textures.talent.name end,
                    set = function(info, value)
                        E.db[mPlugin].mDock.textures.talent.name = value
                        E.db[mPlugin].mDock.textures.talent.path = mIconsList[value].file
                    end,
                    values = mTextureList(),
                },
            },
        },
        docknottification = {
            order = 130,
            type = "group",
            name = L["Nottification"],
            args = {
                docknottificationicon = {
                    order = 1,
                    type = 'select',
                    name = L["Icon"],
                    get = function(info) return E.db[mPlugin].mDock.textures.nottification.name end,
                    set = function(info, value)
                        E.db[mPlugin].mDock.textures.nottification.name = value
                        E.db[mPlugin].mDock.textures.nottification.path = mIconsList[value].file
                    end,
                    values = mTextureList(),
                },
                docknottificationiconsize = {
                    order = 2,
                    name = L["Icon size"],
                    type = "range",
                    min = 16, max = 128, step = 2,
                    get = function(info)
                    return E.db[mPlugin].mDock.nottification.size
                    end,
                    set = function(info, value)
                        E.db[mPlugin].mDock.nottification.size = value
                    end,
                },
                docknottificationspacer1 = {
                    order = 3,
                    type = "description",
                    name = "\n",
                },
                docknottificationiconflash = {
                    order = 4,
                    type = 'toggle',
                    name = L["Icon flash"],
                    get = function(info)
                        return E.db[mPlugin].mDock.nottification.flash
                    end,
                    set = function(info, value)
                        E.db[mPlugin].mDock.nottification.flash = value
                    end,
                },
            },
        },
    }
end

table.insert(ns.Config, OptionsDock)