MuteBards = MuteBards or {};
local isInitialized = false;
function MuteBards:InitSettingsPanel(svZones, svChar)

  local function refreshCallback()
    MuteBards:Refresh();
  end

  local function getCurrentZoneName(sv)
    if (sv ~= nil and sv.currentSubZone ~= ni and sv.currentSubZone ~= "") then
      return sv.currentSubZone;
    end
    return "UNKNOWN"
  end

  local panelData = {
    type = "panel",
    name = "MuteBards 2.0",
    displayName = "MuteBards 2.0",
    author = "MadDachshund",
    version = "2.0",
    slashCommand = "/mutebards", --(optional) will register a keybind to open to this panel
    registerForRefresh = true, --boolean (optional) (will refresh all options controls when a setting is changed and when the panel is shown)
    registerForDefaults = false, --boolean (optional) (will set all options controls back to default values)
  }

  local zoneToAdd, zoneToRemove

  local optionsTable = {
    {
      type = "header",
      name = "Zones",
      width = "full", --or "half" (optional)
    },
    {
      type = "description",
      --title = "My Title",	--(optional)
      text = "Add the exact subzone (usually town) name for the zone you wish to mute bards in.  For example, \"Solitude\" or \"Rimmen\" (without quotes)",
      width = "full", --or "half" (optional)
    },
    {
      type = "description",
      title = "Current Zone:",	--(optional)
      text = function() return "  " .. getCurrentZoneName(svChar) end,

      width = "half", --or "half" (optional)
    },
    {
      type = "button",
      name = "Add Current Zone",
      disabled = function()  return getCurrentZoneName(svChar) == "UNKNOWN" end,
      func = function()
        if (getCurrentZoneName(svChar) ~= "UNKNOWN") then
          MuteBards:AddZone(getCurrentZoneName(svChar), refreshCallback);
        end
      end,
      width = "half", --or "half" (optional)
    },
    {
      type = "editbox",
      name = "Add Zone:",
      tooltip = "Zone Name",
      getFunc = function()
        return zoneToAdd
      end,
      setFunc = function(text)
        zoneToAdd = text
      end,
      isMultiline = false, --boolean
      width = "half", --or "half" (optional)
      default = "", --(optional)
    },
    {
      type = "button",
      name = "Add",
      func = function()
        MuteBards:AddZone(zoneToAdd, refreshCallback);
        zoneToAdd = "";
      end,
      width = "half", --or "half" (optional)
    },
    {
      type = "description",
      title = "Currently Muted Zones:",
      text = function()
        return table.concat(svZones, ", ");
      end,
      width = "full",
      requiresReload = true,
    },
    {
      type = "editbox",
      name = "Remove Zone:",
      getFunc = function()
        return zoneToRemove
      end,
      setFunc = function(text)
        zoneToRemove = text
      end,
      isMultiline = false, --boolean
      width = "half", --or "full" (optional)
      default = "", --(optional)
    },
    {
      type = "button",
      name = "Remove",
      func = function()
        MuteBards:RemoveZone(zoneToRemove, refreshCallback);
        zoneToRemove = "";
      end,
      width = "half", --or "full" (optional)
    },
    {
      type = "button",
      name = "Force Refresh",
      func = refreshCallback,
      width = "full", --or "half" (optional)
    },
  }

  local LAM = LibAddonMenu2
  if (not isInitialized) then
    LAM:RegisterAddonPanel("MuteBards2", panelData);
  end
  LAM:RegisterOptionControls("MuteBards2", optionsTable);

  isInitialized = true;

end