-- Config panel code for Full Moon

function FullMoonPanel_OnLoad(panel)
  panel.name = "Full Moon";
  
  -- Give it empty functions
  panel.okay = function (self) end;
  panel.cancel = function (self) end;

  InterfaceOptions_AddCategory(panel);
end

function FullMoonPanel_OnShow()
  if (FullMoon_Config ~= nil) then
    -- Check boxes
    FullMoonOptionsFrame_CheckLocked:SetChecked(FullMoon_Config.locked);
    FullMoonOptionsFrame_CheckPVP:SetChecked(FullMoon_Config.PvP);
    FullMoonOptionsFrame_CheckTotems:SetChecked(FullMoon_Config.totems);
    FullMoonOptionsFrame_CheckRacial:SetChecked(FullMoon_Config.racial);
    FullMoonOptionsFrame_CheckLongCDs:SetChecked(FullMoon_Config.longCDs);
    FullMoonOptionsFrame_CheckSound:SetChecked(FullMoon_Config.playSound);
    FullMoonOptionsFrame_CheckElemental:SetChecked(FullMoon_Config.elemental);
    FullMoonOptionsFrame_CheckEnhancement:SetChecked(FullMoon_Config.enhancement);
    FullMoonOptionsFrame_CheckRestoration:SetChecked(FullMoon_Config.restoration);
    
    -- Sliders
    FullMoonOptionsFrame_SliderCombatFade:SetValue(FullMoon_Config.combatFade);
    FullMoonOptionsFrame_SliderScale:SetValue(FullMoon_Config.scale);
  end
end

function FullMoonPanel_Click()
  local buttonName = this:GetName();
  
  if (buttonName == "FullMoonOptionsFrame_CheckPVP") then
    if (this:GetChecked()) then
      FullMoon_Config.PvP = true;
      FullMoon_Print("Showing PvP bars");
      FullMoonPvPFrame:Show();
    else
      FullMoon_Config.PvP = false;
      FullMoon_Print("Hiding PvP bars");
      FullMoonPvPFrame:Hide();
    end
  end
  
  if (buttonName == "FullMoonOptionsFrame_CheckTotems") then
    if (this:GetChecked()) then
      FullMoon_Config.totems = true;
      FullMoon_Print("Showing totem bars");
      FullMoonTotemFrame:Show();
    else
      FullMoon_Config.totems = false;
      FullMoon_Print("Hiding totem bars");
      FullMoonTotemFrame:Hide();
    end
  end
  
  if (buttonName == "FullMoonOptionsFrame_CheckRacial") then
    if (this:GetChecked()) then
      FullMoon_Config.racial = true;
      FullMoon_Print("Showing racial bar");
      FullMoonRacialFrame:Show();
    else
      FullMoon_Config.racial = false;
      FullMoon_Print("Hiding racial bar");
      FullMoonRacialFrame:Hide();
    end
  end
  
  if (buttonName == "FullMoonOptionsFrame_CheckLongCDs") then
    if (this:GetChecked()) then
      FullMoon_Config.longCDs = true;
      FullMoon_Print("Showing long cooldowns");
      FullMoonFrame_InfoFrame_HB1_UptimeBar:Show();
      FullMoonFrame_InfoFrame_HB2_UptimeBar:Show();
      FullMoonFrame_InfoFrame_HB1BG:Show();
      FullMoonFrame_InfoFrame_HB2BG:Show();
      
      -- May or may not have to hide some of those
      FullMoon_ReInit();
    else
      FullMoon_Config.longCDs = false;
      FullMoon_Print("Hiding long cooldowns");
      FullMoonFrame_InfoFrame_HB1_UptimeBar:Hide();
      FullMoonFrame_InfoFrame_HB2_UptimeBar:Hide();
      FullMoonFrame_InfoFrame_HB1BG:Hide();
      FullMoonFrame_InfoFrame_HB2BG:Hide();
    end
  end
  
  if (buttonName == "FullMoonOptionsFrame_CheckLocked") then
    if (not this:GetChecked()) then
      FullMoon_UnlockFrames();
      FullMoon_Print("Frames unlocked");
    else
      FullMoon_LockFrames();
      FullMoon_Print("Frames locked");
    end
  end
  
  if (buttonName == "FullMoonOptionsFrame_CheckSound") then
    if (not this:GetChecked()) then
      FullMoon_Config.playSound = false;
      FullMoon_Print("Sounds OFF");
    else
      FullMoon_Config.playSound = true;
      FullMoon_Print("Sounds ON");
    end
  end
  
  if (buttonName == "FullMoonOptionsFrame_CheckElemental") then
    if (not this:GetChecked()) then
      FullMoon_Config.elemental = false;
      FullMoon_Print("Full Moon DISABLED for Elemental");
      
      if (FM_mode == 1) then
        FullMoon_HideFrames();
      end
    else
      FullMoon_Config.elemental = true;
      FullMoon_Print("Full Moon ENABLED for Elemental");
      
      if (FM_mode == 1) then
        FullMoon_ShowFrames();
      end
    end
  end
  
  if (buttonName == "FullMoonOptionsFrame_CheckEnhancement") then
    if (not this:GetChecked()) then
      FullMoon_Config.enhancement = false;
      FullMoon_Print("Full Moon DISABLED for Enhancement");
      
      if (FM_mode == 2) then
        FullMoon_HideFrames();
      end
    else
      FullMoon_Config.enhancement = true;
      FullMoon_Print("Full Moon ENABLED for Enhancement");
      
      if (FM_mode == 2) then
        FullMoon_ShowFrames();
      end
    end
  end
  
  if (buttonName == "FullMoonOptionsFrame_CheckRestoration") then
    if (not this:GetChecked()) then
      FullMoon_Config.restoration = false;
      FullMoon_Print("Full Moon DISABLED for Restoration");
      
      if (FM_mode == 3) then
        FullMoon_HideFrames();
      end
    else
      FullMoon_Config.restoration = true;
      FullMoon_Print("Full Moon ENABLED for Restoration");
      
      if (FM_mode == 3) then
        FullMoon_ShowFrames();
      end
    end
  end
end

function FullMoonPanel_CombatFade()
  FullMoon_Config.combatFade = this:GetValue();
  
  if (InCombatLockdown() == nil) then
    FullMoon_UpdateFrameAlpha(FullMoon_Config.combatFade);
  end
end

function FullMoonPanel_Scale()
  FullMoon_Config.scale = this:GetValue();
  FullMoon_UpdateFrameScale();
end