local CURRENT_ANCHOR, CURRENT_TIMER = "", "";
local ANCHOR_FRAMES = {};
local PROFILE_FRAMES = {};

local optionsTable = {
    { -- section 1
        { -- column 1
            {
                title = "Enabled",
                type = "checkButton",
                tooltipText = "Enables or disables the addon.",
                setting = "enabled",
                simple = true,
            },
            {
                title = "Party Buffs",
                type = "checkButton",
                tooltipText = "Enables or disables Party Buffs from appearing.  Party Buffs consolidate buffs you cast on the party into a single timer.  The stack number is the number of people it's on, and the time remaining is from the timer that's going to end first.  You can mouse over the timer for info on who you have timers on, and who you don't.",
                setting = "usePartyBuffs",
                simple = true,
            },
            {
                title = "Filter Ungrouped",
                type = "checkButton",
                tooltipText = "If checked, buffs you cast on people not in your group will be ignored.",
                setting = "filterUngroupedBuffs",
                simple = true,
            },
            {
                title = "Filter Non-Players",
                type = "checkButton",
                tooltipText = "If checked, buffs you cast on things that aren't players will be ignored.",
                setting = "filterNonPlayerBuffs",
                simple = true,
            },
            {
                title = "Filter Self",
                type = "checkButton",
                tooltipText = "If checked, buffs you cast on yourself will be ignored.",
                setting = "filterSelf",
                simple = true,
            },
            {
                title = "Mouseover Timers",
                type = "dropDownSelector",
                tooltipText = "Sets for whom Mouseover Timers will appear.  When you mouse over a unit, either in the world or over a unit frame, you will get a list of any timers on that unit right next to your cursor.  It will only happen if your mouseover target is not your current target.",
                values = {"off", "friends", "enemies", "both"};
                setting = "mouseoverTimers",
                simple = true,
            },
            {
                title = "Standard Setting",
                type = "dropDown",
                tooltipText = "Select the timer setting you want to apply to standard timers on targets.",
                func = function()
                    local setting = "standardSetting";
                    local info;
                    for name, settings in pairs(TimerLib:Get("timerSettings")) do
                        info = UIDropDownMenu_CreateInfo();
                        info.text = name;
                        info.checked = name == DoTimer:Get(setting);
                        info.func = function() 
                            DoTimer:Set(setting, name);
                            CloseDropDownMenus(); 
                        end
                        UIDropDownMenu_AddButton(info);
                    end
                    
                    info = UIDropDownMenu_CreateInfo();
                    info.text = "None";
                    info.tooltipTitle = "Description";
                    info.tooltipText = "If you select 'None', the default for the anchor will be used instead.";
                    info.checked = DoTimer:Get(setting) == nil;
                    info.func = function() 
                        DoTimer:Set(setting, nil);
                        CloseDropDownMenus(); 
                    end
                    UIDropDownMenu_AddButton(info);
                end,
            },
            {
                title = "Party Buffs Setting",
                type = "dropDown",
                tooltipText = "Select the timer setting you want to apply to Party Buffs timers.",
                func = function()
                    local setting = "pbSetting";
                    local info;
                    for name, settings in pairs(TimerLib:Get("timerSettings")) do
                        info = UIDropDownMenu_CreateInfo();
                        info.text = name;
                        info.checked = name == DoTimer:Get(setting);
                        info.func = function() 
                            DoTimer:Set(setting, name);
                            CloseDropDownMenus(); 
                        end
                        UIDropDownMenu_AddButton(info);
                    end
                    
                    info = UIDropDownMenu_CreateInfo();
                    info.text = "None";
                    info.tooltipTitle = "Description";
                    info.tooltipText = "If you select 'None', the default for the anchor will be used instead.";
                    info.checked = DoTimer:Get(setting) == nil;
                    info.func = function() 
                        DoTimer:Set(setting, nil);
                        CloseDropDownMenus(); 
                    end
                    UIDropDownMenu_AddButton(info);
                end,
            },
            {
                title = "No Target Setting",
                type = "dropDown",
                tooltipText = "Select the timer setting you want to apply to No Target Timers.",
                func = function()
                    local setting = "ntSetting";
                    local info;
                    for name, settings in pairs(TimerLib:Get("timerSettings")) do
                        info = UIDropDownMenu_CreateInfo();
                        info.text = name;
                        info.checked = name == DoTimer:Get(setting);
                        info.func = function() 
                            DoTimer:Set(setting, name);
                            CloseDropDownMenus(); 
                        end
                        UIDropDownMenu_AddButton(info);
                    end
                    
                    info = UIDropDownMenu_CreateInfo();
                    info.text = "None";
                    info.tooltipTitle = "Description";
                    info.tooltipText = "If you select 'None', the default for the anchor will be used instead.";
                    info.checked = DoTimer:Get(setting) == nil;
                    info.func = function() 
                        DoTimer:Set(setting, nil);
                        CloseDropDownMenus(); 
                    end
                    UIDropDownMenu_AddButton(info);
                end,
            },
        },
        { -- column 2
            {
                title = "Show Only Target",
                type = "checkButton",
                tooltipText = "If checked, when you have a target DoTimer will only display timers from it.  If 'Show Only Focus' is also checked, both targets will be shown.",
                setting = "showOnlyTarget",
                simple = true,
            },
            {
                title = "Sort Target",
                type = "checkButton",
                tooltipText = "If checked, your current target will be sorted to the first target position.",
                setting = "sortTarget",
                simple = true,
            },
            {
                title = "Show Only Focus",
                type = "checkButton",
                tooltipText = "If checked, when you have a focus DoTimer will only display timers from it.  If 'Show Only Target' is also checked, both targets will be shown.",
                setting = "showOnlyFocus",
                simple = true,
            },
            {
                title = "Sort Focus",
                type = "checkButton",
                tooltipText = "If checked, your current focus will be sorted to the first target position.  If 'Sort Target' is also checked, your focus will be the 2nd position.",
                setting = "sortFocus",
                simple = true,
            },
            {
                title = "Announce",
                type = "checkButton",
                tooltipText = "If unchecked, attempting to announce a timer will result in no action.",
                setting = "isAnnouncing",
                simple = true,
            },
            {
                title = "Blocked Types",
                type = "dropDownMultiSelector",
                tooltipText = "Allows you to disable timers for different types of spells.",
                values = {"HELPFUL", "HARMFUL"};
                setting = "blockedTypes",
                simple = true,
            },
            {
                title = "Key Bindings",
                type = "dropDown",
                tooltipText = "Allows you to change the key bindings for various timer-related functions.",
                func = function() DoTimer:KBDropDown() end,
            },
            {
                title = "Mouseover Setting",
                type = "dropDown",
                tooltipText = "Select the timer setting you want to apply to Mouseover Timers.",
                func = function()
                    local setting = "mouseoverSetting";
                    local info;
                    for name, settings in pairs(TimerLib:Get("timerSettings")) do
                        info = UIDropDownMenu_CreateInfo();
                        info.text = name;
                        info.checked = name == DoTimer:Get(setting);
                        info.func = function() 
                            DoTimer:Set(setting, name);
                            CloseDropDownMenus(); 
                        end
                        UIDropDownMenu_AddButton(info);
                    end
                    
                    info = UIDropDownMenu_CreateInfo();
                    info.text = "None";
                    info.tooltipTitle = "Description";
                    info.tooltipText = "If you select 'None', the default for the anchor will be used instead.";
                    info.checked = DoTimer:Get(setting) == nil;
                    info.func = function() 
                        DoTimer:Set(setting, nil);
                        CloseDropDownMenus(); 
                    end
                    UIDropDownMenu_AddButton(info);
                end,
            },
            {
                title = "Others' Setting",
                type = "dropDown",
                tooltipText = "Select the timer setting you want to apply to others' timers.",
                func = function()
                    local setting = "otherSetting";
                    local info;
                    for name, settings in pairs(TimerLib:Get("timerSettings")) do
                        info = UIDropDownMenu_CreateInfo();
                        info.text = name;
                        info.checked = name == DoTimer:Get(setting);
                        info.func = function() 
                            DoTimer:Set(setting, name);
                            CloseDropDownMenus(); 
                        end
                        UIDropDownMenu_AddButton(info);
                    end
                    
                    info = UIDropDownMenu_CreateInfo();
                    info.text = "None";
                    info.tooltipTitle = "Description";
                    info.tooltipText = "If you select 'None', the default for the anchor will be used instead.";
                    info.checked = DoTimer:Get(setting) == nil;
                    info.func = function() 
                        DoTimer:Set(setting, nil);
                        CloseDropDownMenus(); 
                    end
                    UIDropDownMenu_AddButton(info);
                end,
            },
            {
                title = "Other Timers",
                type = "editBoxDropDown",
                tooltipText = "Add here the names of timers other people made that you want to see.  The timer name much match exactly (case insensitive) to be shown.",
                setting = "otherTimers",
            },
        },
        { -- column 3
            {
                title = "Max Buff Duration",
                type = "slider",
                tooltipText = "Sets the maximum duration, in minutes, that a buff can have for DoTimer to track it.  Zero means no restriction.",
                minValue = 0, 
                maxValue = 30,
                valueStep = 2,
                setting = "maxBuffDuration",
                simple = true,
            },
            {
                title = "Mouseover Fade Time",
                type = "slider",
                tooltipText = "Sets the amount of time, in seconds, it takes for mouseover timers to disappear after the mouse is no longer over the unit.",
                minValue = 0, 
                maxValue = 3,
                valueStep = .25,
                setting = "mouseoverFadeTime",
            },
            {
                title = "Standard Announce",
                type = "editBoxString",
                tooltipText = [[Sets the message that will be sent when you announce a timer.  You can use the following replacements:

    %s: Name of the timer
    %d: Time remaining
    %t: Target name
    %l: Target level
    %r: Target raid icon]]
                ,
                setting = "standardAnnounce",
                simple = true,
            },
            {
                title = "No Target Announce",
                type = "editBoxString",
                tooltipText = [[Sets the message that will be send when you announce a timer with no target.  You can use the following replacements:

    %s: Name of the timer
    %d: Time remaining]]
                ,
                setting = "noTargetAnnounce",
                simple = true,
            },
            {
                title = "Standard Name",
                type = "editBoxString",
                tooltipText = "Sets the text to be displayed as the group name of individual timers moved to another anchor, if the anchor is not set to preserve target data.",
                setting = "ntName",
            },
            {
                title = "No Target Name",
                type = "editBoxString",
                tooltipText = "Sets the text to be displayed as the name of the No Target group.  If you set this to a value another group is also using (in the same anchor), the two groups will merge into one.",
                setting = "ntName",
            },
            {
                title = "Party Buffs Name",
                type = "editBoxString",
                tooltipText = "Sets the text to be displayed as the name of the Party Buffs group.  If you set this to a value another group is also using (in the same anchor), the two groups will merge into one.",
                setting = "pbName",
            },
            {
                title = "Party Buffs",
                type = "editBoxDropDown",
                tooltipText = "This is the list of Party Buffs filters.  Any timer names that match this filter will consolidate into one Party Buff timer.",
                setting = "partyBuffs",
                simple = true,
            },
            {
                title = "Blocked Timers",
                type = "editBoxDropDown",
                tooltipText = "Add here the names of timers you do not wish to see onscreen.  The timer name much match exactly (case insensitive) to be blocked.",
                setting = "blocked",
                simple = true,
            },
        },
    },
    { -- section 2
        { -- column 1
            { -- row 1
                {
                    type = "text",
                    text = "Select Anchor to Customize: ",
                },
                {
                    title = "(Select from DropDown Menu)",
                    type = "dropDown",
                    tooltipText = "Select the anchor you want to customize.",
                    func = function(self)
                        local info;
                        for name, settings in pairs(TimerLib:Get("anchorSettings")) do
                            if name ~= "Default Anchor" and name ~= "DoTimer Mouseover" and name ~= "Notifications Anchor" then
                                info = UIDropDownMenu_CreateInfo();
                                info.text = name;
                                info.checked = name == CURRENT_ANCHOR;
                                info.func = function() 
                                    CURRENT_ANCHOR = name;
                                    getglobal(self:GetParent():GetName() .. "Text"):SetText(name);
                                    for frame in pairs(ANCHOR_FRAMES) do
                                        frame:Update();
                                    end
                                    CloseDropDownMenus(); 
                                end
                                UIDropDownMenu_AddButton(info);
                            end
                        end
                    end,
                    scripts = {
                        OnShow = function(self)
                            for name, settings in pairs(DoTimer:Get("userAnchors")) do
                                if settings.default then
                                    CURRENT_ANCHOR = name;
                                    getglobal(self:GetName() .. "Text"):SetText(name);
                                    for frame in pairs(ANCHOR_FRAMES) do
                                        frame:Update();
                                    end
                                end
                            end
                        end,
                    },
                },
            },
        },
    },
    { -- section 3
        { -- column 1
            {
                title = "Make this the default anchor",
                type = "checkButton",
                tooltipText = "If checked, standard DoTimer targets will be moved to this anchor.",
                scripts = {
                    OnShow = function(self)
                        if not self.loaded then
                            self.loaded = true;
                            self.Update = function(self)
                                self:SetChecked(DoTimer:Get("userAnchors", CURRENT_ANCHOR, "default"));
                            end
                            ANCHOR_FRAMES[self] = true;
                        end
                        self:Update();
                    end,
                    OnClick = function(self)
                        if self:GetChecked() then
                            for name, settings in pairs(DoTimer:Get("userAnchors")) do
                                if name ~= CURRENT_ANCHOR then settings.default = nil; end
                            end
                            DoTimer:Set("userAnchors", CURRENT_ANCHOR, "default", 1);
                        else
                            self:SetChecked(true);
                            AsheylaLib:AlertUser("You cannot uncheck this setting.  You must check it in another anchor to change it.");
                        end
                    end,
                },
            },
            { -- row
                {
                    title = "Move Party Buffs Here",
                    type = "checkButton",
                    tooltipText = "If checked, the 'Party Buffs' group will be moved to this anchor.",
                    scripts = {
                        OnShow = function(self)
                            if not self.loaded then
                                self.loaded = true;
                                self.Update = function(self)
                                    self:SetChecked(DoTimer:Get("userAnchors", CURRENT_ANCHOR, "pbLoc"));
                                end
                                ANCHOR_FRAMES[self] = true;
                            end
                            self:Update();
                        end,
                        OnClick = function(self)
                            if self:GetChecked() then
                                for name, settings in pairs(DoTimer:Get("userAnchors")) do
                                    if name ~= CURRENT_ANCHOR then settings.pbLoc = nil; end
                                end
                                DoTimer:Set("userAnchors", CURRENT_ANCHOR, "pbLoc", 1);
                            else
                                DoTimer:Set("userAnchors", CURRENT_ANCHOR, "pbLoc", nil);
                            end
                        end,
                    },
                },
                {
                    title = "Move No Target Here",
                    type = "checkButton",
                    tooltipText = "If checked, the 'No Target' group will be moved to this anchor.",
                    scripts = {
                        OnShow = function(self)
                            if not self.loaded then
                                self.loaded = true;
                                self.Update = function(self)
                                    self:SetChecked(DoTimer:Get("userAnchors", CURRENT_ANCHOR, "ntLoc"));
                                end
                                ANCHOR_FRAMES[self] = true;
                            end
                            self:Update();
                        end,
                        OnClick = function(self)
                            if self:GetChecked() then
                                for name, settings in pairs(DoTimer:Get("userAnchors")) do
                                    if name ~= CURRENT_ANCHOR then settings.ntLoc = nil; end
                                end
                                DoTimer:Set("userAnchors", CURRENT_ANCHOR, "ntLoc", 1);
                            else
                                DoTimer:Set("userAnchors", CURRENT_ANCHOR, "pbLoc", nil);
                            end
                        end,
                    },
                },
            },
            { -- row
                {
                    type = "text",
                    small = true,
                    text = "Move these targets here:",
                },
                {
                    title = "<Target Name>",
                    type = "editBoxDropDown",
                    tooltipText = "Type in here the names of targets whose timers you want moved to this anchor.  The target must match exactly what you type (case insensitive) in order to move.  You can type '*target*' or '*focus*' (no quotes) for your current target/focus.",
                    scripts = {
                		OnEnterPressed = function(self) 
                			local text = self:GetText();
                			DoTimer:Set("userAnchors", CURRENT_ANCHOR, "targets", string.lower(text), 1);
                            self:ClearFocus();
                		end,
                    },
                    func = function()
                        local targets = DoTimer:Get("userAnchors", CURRENT_ANCHOR, "targets");
                        if targets then
                            local info;
                            for name in pairs(targets) do
                                info = UIDropDownMenu_CreateInfo();
                                info.text = name;
                                info.notCheckable = 1;
                                info.func = function() 
                                    DoTimer:Set("userAnchors", CURRENT_ANCHOR, "targets", name, nil);
                                    CloseDropDownMenus(); 
                                end
                                UIDropDownMenu_AddButton(info);
                            end
                        end
                    end,
                },
                {
                    title = "For Below Timers",
                    type = "checkButton",
                    tooltipText = "If checked, only the timers added to the editbox below will be moved to this anchor for the targets you specify.",
                    scripts = {
                        OnShow = function(self)
                            if not self.loaded then
                                self.loaded = true;
                                self.Update = function(self)
                                    self:SetChecked(DoTimer:Get("userAnchors", CURRENT_ANCHOR, "specificTimers"));
                                end
                                ANCHOR_FRAMES[self] = true;
                            end
                            self:Update();
                        end,
                        OnClick = function(self)
                            if self:GetChecked() then
                                DoTimer:Set("userAnchors", CURRENT_ANCHOR, "specificTimers", 1);
                            else
                                DoTimer:Set("userAnchors", CURRENT_ANCHOR, "specificTimers", nil);
                            end
                        end,
                    },
                },
            },
            { -- row
                {
                    type = "text",
                    small = true,
                    text = "Move these timers here:",
                },
                {
                    title = "<Timer Name>",
                    type = "editBoxDropDown",
                    tooltipText = "Type in here the names of individual timers you want moved to this anchor.  The timer name must match only a fragment (case insensitive) in order to move.",
                    scripts = {
                		OnEnterPressed = function(self) 
                			local text = self:GetText();
                			DoTimer:Set("userAnchors", CURRENT_ANCHOR, "timers", string.lower(text), 1);
                            self:ClearFocus();
                		end,
                    },
                    func = function()
                        local timers = DoTimer:Get("userAnchors", CURRENT_ANCHOR, "timers");
                        if timers then
                            local info;
                            for name in pairs(timers) do
                                info = UIDropDownMenu_CreateInfo();
                                info.text = name;
                                info.notCheckable = 1;
                                info.func = function() 
                                    DoTimer:Set("userAnchors", CURRENT_ANCHOR, "timers", name, nil);
                                    CloseDropDownMenus(); 
                                end
                                UIDropDownMenu_AddButton(info);
                            end
                        end
                    end,
                },
                {
                    title = "Preserve Target Data",
                    type = "checkButton",
                    tooltipText = "If checked, the timers moving into this anchor will preserve their target information.  If unchecked, the timers will use the 'Standard Name' setting to determine their group.",
                    scripts = {
                        OnShow = function(self)
                            if not self.loaded then
                                self.loaded = true;
                                self.Update = function(self)
                                    self:SetChecked(DoTimer:Get("userAnchors", CURRENT_ANCHOR, "preserveTarget"));
                                end
                                ANCHOR_FRAMES[self] = true;
                            end
                            self:Update();
                        end,
                        OnClick = function(self)
                            if self:GetChecked() then
                                DoTimer:Set("userAnchors", CURRENT_ANCHOR, "preserveTarget", 1);
                            else
                                DoTimer:Set("userAnchors", CURRENT_ANCHOR, "preserveTarget", nil);
                            end
                        end,
                    },
                },
            },
            { -- row
                {
                    type = "text",
                    small = true,
                    text = "Apply this timer setting:",
                },
                {
                    title = "",
                    type = "dropDown",
                    tooltipText = "Select the timer setting you want to apply to specific timers.",
                    func = function()
                        local info;
                        for name, settings in pairs(TimerLib:Get("timerSettings")) do
                            info = UIDropDownMenu_CreateInfo();
                            info.text = name;
                            info.checked = name == CURRENT_TIMER;
                            info.func = function() 
                                CURRENT_TIMER = name;
                                CloseDropDownMenus(); 
                            end
                            UIDropDownMenu_AddButton(info);
                        end
                    end,
                    scripts = {
                        OnShow = function(self)
                            CURRENT_TIMER = "Default Timer";
                        end,
                    },
                },
                {
                    type = "text",
                    small = true,
                    text = "to these timers:",
                },
                {
                    title = "<Timer Name>",
                    type = "editBoxDropDown",
                    tooltipText = "Type in here the names of timers you want to apply to the timer setting.  The timer name must match only a fragment (case insensitive) to apply.",
                    scripts = {
                		OnEnterPressed = function(self) 
                			local text = self:GetText();
                			DoTimer:Set("userAnchors", CURRENT_ANCHOR, "timerSettings", CURRENT_TIMER, string.lower(text), 1);
                            self:ClearFocus();
                		end,
                    },
                    func = function()
                        local timers = DoTimer:Get("userAnchors", CURRENT_ANCHOR, "timerSettings", CURRENT_TIMER);
                        if timers then
                            local info;
                            for name in pairs(timers) do
                                info = UIDropDownMenu_CreateInfo();
                                info.text = name;
                                info.notCheckable = 1;
                                info.func = function() 
                                    DoTimer:Set("userAnchors", CURRENT_ANCHOR, "timerSettings", CURRENT_TIMER, name, nil);
                                    CloseDropDownMenus(); 
                                end
                                UIDropDownMenu_AddButton(info);
                            end
                        end
                    end,
                },
            },
        },
    },
};

local function createDGUI()
    GUILib:SetGUIPanel("|c1fffffff|rDoTimer", "main", DoTimer, optionsTable);
end
createDGUI();
GUILib:AddGUICreationScript(createDGUI);

optionsTable2 = {
    { -- section 1
        { -- column 1
            {
                title = "Simple Mode",
                type = "checkButton",
                tooltipText = "Uncheck to access the more complex features of DoTimer.",
                scripts = {
                    OnShow = function(self) 
                        local setting = AsheylaLib:InSimpleMode();
                        self:SetChecked(setting and true or false); 
                    end,
                    OnClick = function(self) 
                        AsheylaLib:SetSimpleMode(self:GetChecked() and true or false);
                        GUILib:ReloadGUI();
                    end,
                },
            },
            {
                type = "text",
                text = "Version Info:",
            },
            {
                type = "text",
                small = true,
                text = "   |cffffffffNumber|r: |cff00ff00" .. AsheylaLib:ReturnVersion(),
            },
            {
                type = "text",
                small = true,
                text = "   |cffffffffReleased|r: |cff00ff00" .. AsheylaLib:ReturnDateUploaded(),
            },
        },
    },
    { -- section 2
        { -- column 1
            {
                type = "text",
                text = "Author Info:",
            },
            {
                type = "text",
                small = true,
                text = "   |cffffffffName|r: |cff00ff00Ross Nichols",
            },
            {
                type = "text",
                small = true,
                text = "   |cffffffffE-Mail|r: |cff00ff00ross456@gmail.com",
            },
            {
                type = "text",
                small = true,
                text = "   |cffffffffSchool|r: |cff00ff00University of Florida",
            },
            {
                type = "text",
                small = true,
                text = "   |cffffffffCharacters|r: |cff00ff00Asheyla (Shattered Hand Horde), Xanido (Anetheron Alliance)",
            },
        },
    },
    { -- section 3
        { -- column 1
            {
                type = "text",
                text = "AddOn Info:",
            },
            {
                type = "text",
                small = true,
                text = "   |cffffffffDoTimer|r: |cff00ff00/dotimer|r or |cff00ff00/dot",
            },
            {
                type = "text",
                small = true,
                text = "   |cffffffffCooldowns|r: |cff00ff00/cooldowns|r or |cff00ff00/cd",
            },
            {
                type = "text",
                small = true,
                text = "   |cffffffffNotifications|r: |cff00ff00/notifications|r or |cff00ff00/not",
                notSimple = true,
            },
            {
                type = "text",
                small = true,
                text = "   |cffffffffPlayerAuras|r: |cff00ff00/playerauras|r or |cff00ff00/pa",
                notSimple = true,
            },
            {
                type = "text",
                small = true,
                text = "   |cffffffffTimerLib|r: |cff00ff00/timerlib|r or |cff00ff00/tl",
                notSimple = true,
            },
            {
                type = "text",
                small = true,
                text = "      Type |cff00ff00/timerlib anchor|r or |cff00ff00/timerlib a|r to open\n      to Anchors.  Else, it will open to Timers.",
                notSimple = true,
            },
        },
    },
    { -- section 4
        { -- column 1
            {
                type = "text",
                text = "Profiles",
            },
            {
                title = "Create / Delete",
                type = "editBoxString",
                tooltipText = "Type in here the name of a profile to create or delete.  If a profile by the name already exists, it will be deleted.  Else, a new one with that name will be made.",
                scripts = {
                    OnEditFocusGained = function(self) 
                        self:SetText(""); 
                        self:HighlightText(); 
                    end,
            		OnEditFocusLost = function(self) self:SetText(self.title or ""); self:SetCursorPosition(0); end,
            		OnShow = function(self) self:SetText(self.title or ""); self:SetCursorPosition(0); end,
            		OnEscapePressed = function(self)
                        self:SetText(self.title or ""); self:SetCursorPosition(0);
            			self:ClearFocus();
            		end,
            		OnEnterPressed = function(self) 
                        local name = self:GetText();
            			if AsheylaLib_Settings[name] then
                            if name == ASHEYLALIB_ACTIVE_PROFILE then
                                AsheylaLib:AlertUser("You cannot delete the active profile.");
                            elseif name == "Default" then
                                AsheylaLib:AlertUser("You cannot delete the default profile.");
                            else
                                AsheylaLib_Settings[name] = nil;
                            end
                        elseif name ~= "" then
                            AsheylaLib:SetActiveProfile(name);
                            for frame in pairs(PROFILE_FRAMES) do
                                frame:Update();
                            end
                        end
                        self:ClearFocus();
            		end,
                },
            },
            { -- row
                {
                    type = "text",
                    small = true,
                    text = "Set active profile:",
                },
                {
                    title = "(Select from DropDown Menu)",
                    type = "dropDown",
                    tooltipText = "Select the profile you want to be active.",
                    func = function(self)
                        local info;
                        for name, vals in AsheylaLib:Alphabetize(AsheylaLib_Settings) do
                            if type(vals) == "table" then
                                info = UIDropDownMenu_CreateInfo();
                                info.text = name;
                                info.checked = name == ASHEYLALIB_ACTIVE_PROFILE;
                                info.func = function() 
                                    AsheylaLib:SetActiveProfile(name);
                                    for frame in pairs(PROFILE_FRAMES) do
                                        frame:Update();
                                    end
                                    CloseDropDownMenus(); 
                                end
                                UIDropDownMenu_AddButton(info);
                            end
                        end
                    end,
                    scripts = {
                        OnShow = function(self)
                            if not self.loaded then
                                self.loaded = true;
                                PROFILE_FRAMES[self] = 1;
                                self.Update = function(self)
                                    getglobal(self:GetName() .. "Text"):SetText(ASHEYLALIB_ACTIVE_PROFILE);
                                end
                            end
                            self:Update();
                        end,
                    },
                },
            },
            {
                title = "Make this the default profile for this character.",
                type = "checkButton",
                tooltipText = "If checked, this profile will be set to active when you log in on this character.  If none are checked, 'Default' will be loaded.",
                scripts = {
                    OnShow = function(self) 
                        if not self.loaded then
                            self.loaded = true;
                            PROFILE_FRAMES[self] = 1;
                            self.Update = function(self)
                                local id = UnitName("player") .. "-" .. GetRealmName();
                                self:SetChecked(AsheylaLib_Settings[ASHEYLALIB_ACTIVE_PROFILE][id] and true or false);
                            end
                        end
                        self:Update();
                    end,
                    OnClick = function(self) 
                        local val = self:GetChecked() and true or nil;
                        local id = UnitName("player") .. "-" .. GetRealmName();
                        if val then
                            for name, settings in pairs(AsheylaLib_Settings) do
                                if type(settings) == "table" then settings[id] = nil; end
                            end
                        end
                        AsheylaLib_Settings[ASHEYLALIB_ACTIVE_PROFILE][id] = val;
                    end,
                },
            },
            {
                title = "Copy a profile into this one.",
                type = "dropDown",
                tooltipText = "Selecting a profile from this dropdown will make your active profile be a clone of the selected one.",
                func = function()
                        local info;
                        for name in AsheylaLib:Alphabetize(AsheylaLib_Settings) do
                            if name ~= ASHEYLALIB_ACTIVE_PROFILE then
                                info = UIDropDownMenu_CreateInfo();
                                info.text = name;
                                info.notCheckable = true;
                                info.func = function() 
                                    AsheylaLib:CopyFromProfile(name);
                                    CloseDropDownMenus(); 
                                end
                                UIDropDownMenu_AddButton(info);
                            end
                        end
                end,
            },
        }
    },
};

local function createDEGUI()
    GUILib:SetGUIPanel("|c1fffffff|rDoTimer", "Extra", DoTimer, optionsTable2, {allSimple = true,});
end
createDEGUI();
GUILib:AddGUICreationScript(createDEGUI);
