local TXUI, F, E, I, V, P, G = unpack((select(2, ...)))
local O = TXUI:GetModule("Options")

function O:Skins_ElvUI()
  -- Create Tab
  self.options.skins.args["elvuiGroup"] = {
    order = self:GetOrder(),
    type = "group",
    name = "ElvUI " .. E.NewSign,
    args = {},
  }

  -- Options
  local options = self.options.skins.args["elvuiGroup"]["args"]

  -- ElvUI Group Description
  self:AddInlineDesc(options, {
    name = "Description",
  }, {
    name = TXUI.Title .. " provides certain additional changes to " .. F.String.ElvUI("ElvUI") .. " or " .. TXUI.Title .. " which can be changed here.",
  })

  -- Spacer
  self:AddSpacer(options)

  -- ElvUI Theme
  do
    -- ElvUI Theme
    local elvuiTheme = self:AddInlineRequirementsDesc(options, {
      name = TXUI.Title .. " " .. F.String.ElvUI("ElvUI") .. " Theme",
      get = function(info)
        return E.db.TXUI.addons.elvUITheme[info[#info]]
      end,
      set = function(info, value)
        if E.db.TXUI.addons.elvUITheme[info[#info]] == value then return end
        E.db.TXUI.addons.elvUITheme[info[#info]] = value
        F.Event.TriggerEvent("Theme.SettingsUpdate")
      end,
    }, {
      name = "Toggling this on enables the " .. TXUI.Title .. " ElvUI Theme.\n\n",
    }, I.Requirements.ElvUITheme)

    -- ElvUI Theme Mode Enable
    elvuiTheme["args"]["enabled"] = {
      order = self:GetOrder(),
      type = "toggle",
      desc = "Toggling this on enables the " .. TXUI.Title .. " ElvUI Theme.",
      name = function()
        return self:GetEnableName(E.db.TXUI.addons.elvUITheme.enabled)
      end,
      set = function(info, value)
        if E.db.TXUI.addons.elvUITheme[info[#info]] == value then return end
        E.db.TXUI.addons.elvUITheme[info[#info]] = value

        TXUI:GetModule("SplashScreen"):Wrap("Applying Theme ...", function()
          F.Event.TriggerEvent("Theme.DatabaseUpdate")
        end)
      end,
    }

    -- Disabled helper
    local optionsDisabled = function()
      return self:GetEnabledState(E.db.TXUI.addons.elvUITheme.enabled, elvuiTheme) ~= self.enabledState.YES
    end

    -- Shadow Toggle
    elvuiTheme["args"]["shadowEnabled"] = {
      order = self:GetOrder(),
      type = "toggle",
      desc = "Enable shadows for WeakAuras and most of ElvUI bars.",
      name = "Soft Shadows",
      disabled = optionsDisabled,
    }

    -- Shadow Alpha
    elvuiTheme["args"]["shadowAlpha"] = {
      order = self:GetOrder(),
      type = "range",
      name = "Shadow Opacity",
      min = 0.1,
      max = 1,
      step = 0.01,
      isPercent = true,
      disabled = function()
        return optionsDisabled() or not E.db.TXUI.addons.elvUITheme.shadowEnabled
      end,
    }

    -- Shadow Size
    elvuiTheme["args"]["shadowSize"] = {
      order = self:GetOrder(),
      type = "range",
      name = "Shadow Size",
      min = 1,
      max = 10,
      step = 1,
      disabled = function()
        return optionsDisabled() or not E.db.TXUI.addons.elvUITheme.shadowEnabled
      end,
    }
  end

  -- Spacer
  self:AddSpacer(options)

  -- ToxiUI Game Menu Button
  do
    local optionsDisabled

    -- ToxiUI Game Menu Button Group
    local gameMenuButtonGroup = self:AddInlineRequirementsDesc(options, {
      name = TXUI.Title .. " Game Menu Button",
    }, {
      name = "Enabling this option shows a " .. TXUI.Title .. " button in the Game Menu (ESC).\n\n",
    }, I.Requirements.GameMenuButton).args

    -- ToxiUI Game Menu Button Enable
    gameMenuButtonGroup.gameMenuButton = {
      order = self:GetOrder(),
      type = "toggle",
      desc = "Enabling this option shows a " .. TXUI.Title .. " button in the Game Menu (ESC).",
      name = function()
        return self:GetEnableName(E.db.TXUI.addons.gameMenuButton.enabled, gameMenuButtonGroup)
      end,
      get = function(_)
        return E.db.TXUI.addons.gameMenuButton.enabled
      end,
      set = function(_, value)
        E.db.TXUI.addons.gameMenuButton.enabled = value
        E:StaticPopup_Show("CONFIG_RL")
      end,
    }

    gameMenuButtonGroup.backgroundFade = {
      order = self:GetOrder(),
      type = "toggle",
      name = "Background Fade",
      desc = "Toggling this on fades the background when opening the Game Menu",
      get = function(_)
        return E.db.TXUI.addons.gameMenuButton.backgroundFade.enabled
      end,
      set = function(_, value)
        E.db.TXUI.addons.gameMenuButton.backgroundFade.enabled = value
        E:StaticPopup_Show("CONFIG_RL")
      end,
    }

    optionsDisabled = function()
      return self:GetEnabledState(E.db.TXUI.addons.gameMenuButton.backgroundFade.enabled, gameMenuButtonGroup) ~= self.enabledState.YES
    end

    gameMenuButtonGroup.showInfo = {
      order = self:GetOrder(),
      disabled = optionsDisabled,
      type = "toggle",
      name = "Show Player Info",
      desc = "Toggling this on displays player information in the game menu background. Requires Background Fade enabled.",
      get = function(_)
        return E.db.TXUI.addons.gameMenuButton.backgroundFade.showInfo
      end,
      set = function(_, value)
        E.db.TXUI.addons.gameMenuButton.backgroundFade.showInfo = value
        E:StaticPopup_Show("CONFIG_RL")
      end,
    }

    gameMenuButtonGroup.classColor = {
      order = self:GetOrder(),
      disabled = optionsDisabled,
      type = "toggle",
      name = "Class Color",
      desc = "Toggling this on will enable your current class' color for the background fade",
      get = function(_)
        return E.db.TXUI.addons.gameMenuButton.backgroundFade.classColor.enabled
      end,
      set = function(_, value)
        E.db.TXUI.addons.gameMenuButton.backgroundFade.classColor.enabled = value
        E:StaticPopup_Show("CONFIG_RL")
      end,
    }

    gameMenuButtonGroup.bgColor = {
      order = self:GetOrder(),
      disabled = optionsDisabled,
      type = "color",
      name = "Background Color",
      hasAlpha = false,
      width = 1,
      get = self:GetFontColorGetter("TXUI.addons.gameMenuButton.backgroundFade", P.addons.gameMenuButton.backgroundFade, "color"),
      set = self:GetFontColorSetter("TXUI.addons.gameMenuButton.backgroundFade", function()
        E:StaticPopup_Show("CONFIG_RL")
      end, "color"),
    }
  end

  -- Spacer
  self:AddSpacer(options)

  -- Role Icons
  do
    -- Role Icon Group
    local roleIconGroup = self:AddInlineRequirementsDesc(options, {
      name = "Role Icons",
      get = function(info)
        return E.db.TXUI.elvUIIcons.roleIcons[info[#info]]
      end,
      set = function(info, value)
        E.db.TXUI.elvUIIcons.roleIcons[info[#info]] = value
        F.Event.TriggerEvent("RoleIcons.SettingsUpdate")
      end,
    }, {
      name = "Change the Role icons of "
        .. F.String.ElvUI("ElvUI")
        .. " to new colorful "
        .. TXUI.Title
        .. " icons.\n\n"
        .. F.String.ToxiUI("Information: ")
        .. "For size and position settings, go to the unit's "
        .. F.String.Class("Role Icon")
        .. " settings.\n\n",
    }, I.Requirements.RoleIcons)

    -- Enable
    roleIconGroup["args"]["enabled"] = {
      order = self:GetOrder(),
      type = "toggle",
      desc = "Toggling this on enables the " .. TXUI.Title .. " Role Icons.",
      name = function()
        return self:GetEnableName(E.db.TXUI.elvUIIcons.roleIcons.enabled, roleIconGroup)
      end,
      get = function(_)
        return E.db.TXUI.elvUIIcons.roleIcons.enabled
      end,
      set = function(_, value)
        E.db.TXUI.elvUIIcons.roleIcons.enabled = value
        F.Event.TriggerEvent("RoleIcons.DatabaseUpdate")
      end,
    }

    -- Hidden helper
    local roleIconDisabled = function()
      return self:GetEnabledState(E.db.TXUI.elvUIIcons.roleIcons.enabled, roleIconGroup) ~= self.enabledState.YES
    end

    -- Theme
    roleIconGroup["args"]["theme"] = {
      order = self:GetOrder(),
      type = "select",
      name = "Style",
      desc = "Change the icons",
      values = {
        ["TXUI"] = TXUI.Title .. " Colored",
        ["TXUI_WHITE"] = TXUI.Title .. " White",
        ["TXUI_MATERIAL"] = TXUI.Title .. " Material",
        ["TXUI_STYLIZED"] = TXUI.Title .. " Stylized",
      },
      hidden = roleIconDisabled,
    }
  end

  -- Spacer
  self:AddSpacer(options)

  -- Raid Leader Icon
  do
    -- Raid Leader Icon Group
    local leaderIconGroup = self:AddInlineRequirementsDesc(options, {
      name = "Raid Leader Icon",
      get = function(info)
        return E.db.TXUI.elvUIIcons.raidIcons.leader[info[#info]]
      end,
      set = function(info, value)
        E.db.TXUI.elvUIIcons.raidIcons.leader[info[#info]] = value
        E:StaticPopup_Show("CONFIG_RL")
      end,
    }, {
      name = "Changes the raid leader indicator icon.\n\n" .. F.String.ToxiUI("Information: ") .. "For size and position settings, go to the unit's " .. F.String.Class(
        "Raid Role Indicator"
      ) .. " settings.\n\n",
    }, I.Requirements.RoleIcons)

    -- Enable
    leaderIconGroup["args"]["enabled"] = {
      order = self:GetOrder(),
      type = "toggle",
      desc = "Toggling this on enables the " .. TXUI.Title .. " skin for Party Leader Indicator",
      name = function()
        return self:GetEnableName(E.db.TXUI.elvUIIcons.raidIcons.leader.enabled, leaderIconGroup)
      end,
      get = function(_)
        return E.db.TXUI.elvUIIcons.raidIcons.leader.enabled
      end,
      set = function(_, value)
        E.db.TXUI.elvUIIcons.raidIcons.leader.enabled = value
        E:StaticPopup_Show("CONFIG_RL")
      end,
    }

    -- Hidden helper
    local leaderIconDisabled = function()
      return self:GetEnabledState(E.db.TXUI.elvUIIcons.raidIcons.leader.enabled, leaderIconGroup) ~= self.enabledState.YES
    end

    -- Theme
    leaderIconGroup["args"]["theme"] = {
      order = self:GetOrder(),
      type = "select",
      name = "Style",
      desc = "Change the icon",
      values = {
        ["TXUI_MATERIAL"] = TXUI.Title .. " Material",
        ["TXUI_STYLIZED"] = TXUI.Title .. " Stylized",
        ["BLIZZARD"] = "Blizzard",
      },
      hidden = leaderIconDisabled,
    }
  end

  -- Spacer
  self:AddSpacer(options)

  -- Raid Assist Icon
  do
    -- Raid Assist Icon Group
    local assistIconGroup = self:AddInlineRequirementsDesc(options, {
      name = "Raid Assist Icon",
      get = function(info)
        return E.db.TXUI.elvUIIcons.raidIcons.assist[info[#info]]
      end,
      set = function(info, value)
        E.db.TXUI.elvUIIcons.raidIcons.assist[info[#info]] = value
        E:StaticPopup_Show("CONFIG_RL")
      end,
    }, {
      name = "Changes the raid assist indicator icon.\n\n" .. F.String.ToxiUI("Information: ") .. "For size and position settings, go to the unit's " .. F.String.Class(
        "Raid Role Indicator"
      ) .. " settings.\n\n",
    }, I.Requirements.RoleIcons)

    -- Enable
    assistIconGroup["args"]["enabled"] = {
      order = self:GetOrder(),
      type = "toggle",
      desc = "Toggling this on enables the " .. TXUI.Title .. " skin for Party Leader Indicator",
      name = function()
        return self:GetEnableName(E.db.TXUI.elvUIIcons.raidIcons.assist.enabled, assistIconGroup)
      end,
      get = function(_)
        return E.db.TXUI.elvUIIcons.raidIcons.assist.enabled
      end,
      set = function(_, value)
        E.db.TXUI.elvUIIcons.raidIcons.assist.enabled = value
        E:StaticPopup_Show("CONFIG_RL")
      end,
    }

    -- Hidden helper
    local assistIconDisabled = function()
      return self:GetEnabledState(E.db.TXUI.elvUIIcons.raidIcons.assist.enabled, assistIconGroup) ~= self.enabledState.YES
    end

    -- Theme
    assistIconGroup["args"]["theme"] = {
      order = self:GetOrder(),
      type = "select",
      name = "Style",
      desc = "Change the icon",
      values = {
        ["TXUI_MATERIAL"] = TXUI.Title .. " Material",
        ["TXUI_STYLIZED"] = TXUI.Title .. " Stylized",
        ["BLIZZARD"] = "Blizzard",
      },
      hidden = assistIconDisabled,
    }
  end

  -- Dead Icons
  do
    -- Dead Icon Group
    local deadIconGroup = self:AddInlineRequirementsDesc(options, {
      name = "Dead Icon",
      get = function(info)
        return E.db.TXUI.elvUIIcons.deadIcons[info[#info]]
      end,
      set = function(info, value)
        E.db.TXUI.elvUIIcons.deadIcons[info[#info]] = value
        F.Event.TriggerEvent("DeadIcons.SettingsUpdate")
      end,
    }, {
      name = "Adds a 'Dead' indicator to " .. F.String.ElvUI("ElvUI") .. " with " .. TXUI.Title .. " icons.\n\n",
    }, I.Requirements.RoleIcons)

    -- Enable
    deadIconGroup["args"]["enabled"] = {
      order = self:GetOrder(),
      type = "toggle",
      desc = "Toggling this on enables the " .. TXUI.Title .. " 'Dead' icon.",
      name = function()
        return self:GetEnableName(E.db.TXUI.elvUIIcons.deadIcons.enabled, deadIconGroup)
      end,
      get = function(_)
        return E.db.TXUI.elvUIIcons.deadIcons.enabled
      end,
      set = function(_, value)
        E.db.TXUI.elvUIIcons.deadIcons.enabled = value
        F.Event.TriggerEvent("DeadIcons.DatabaseUpdate")
      end,
    }

    -- Hidden helper
    local deadIconDisabled = function()
      return self:GetEnabledState(E.db.TXUI.elvUIIcons.deadIcons.enabled, deadIconGroup) ~= self.enabledState.YES
    end

    -- Theme
    deadIconGroup["args"]["theme"] = {
      order = self:GetOrder(),
      type = "select",
      name = "Style",
      desc = "Change the icon",
      values = {
        ["TXUI"] = TXUI.Title,
        ["TXUI_MATERIAL"] = TXUI.Title .. " Material",
        ["TXUI_STYLIZED"] = TXUI.Title .. " Stylized",
        ["BLIZZARD"] = "Blizzard",
      },
      hidden = deadIconDisabled,
    }

    -- Size
    deadIconGroup["args"]["size"] = {
      order = self:GetOrder(),
      type = "range",
      name = "Size",
      desc = "Set the icon size.",
      min = 1,
      max = 100,
      step = 1,
      hidden = deadIconDisabled,
    }

    -- Position X
    deadIconGroup["args"]["xOffset"] = {
      order = self:GetOrder(),
      type = "range",
      name = "X Offset",
      min = -300,
      max = 300,
      step = 1,
      hidden = deadIconDisabled,
    }

    -- Position Y
    deadIconGroup["args"]["yOffset"] = {
      order = self:GetOrder(),
      type = "range",
      name = "Y Offset",
      min = -300,
      max = 300,
      step = 1,
      hidden = deadIconDisabled,
    }
  end

  -- Spacer
  self:AddSpacer(options)

  -- Offline Icons
  do
    -- Offline Icon Group
    local offlineIconGroup = self:AddInlineRequirementsDesc(options, {
      name = "Offline Icon",
      get = function(info)
        return E.db.TXUI.elvUIIcons.offlineIcons[info[#info]]
      end,
      set = function(info, value)
        E.db.TXUI.elvUIIcons.offlineIcons[info[#info]] = value
        F.Event.TriggerEvent("OfflineIcons.SettingsUpdate")
      end,
    }, {
      name = "Adds a 'Offline' indicator to " .. F.String.ElvUI("ElvUI") .. " with " .. TXUI.Title .. " icons.\n\n",
    }, I.Requirements.RoleIcons)

    -- Enable
    offlineIconGroup["args"]["enabled"] = {
      order = self:GetOrder(),
      type = "toggle",
      desc = "Toggling this on enables the " .. TXUI.Title .. " 'Offline' icon.",
      name = function()
        return self:GetEnableName(E.db.TXUI.elvUIIcons.offlineIcons.enabled, offlineIconGroup)
      end,
      get = function(_)
        return E.db.TXUI.elvUIIcons.offlineIcons.enabled
      end,
      set = function(_, value)
        E.db.TXUI.elvUIIcons.offlineIcons.enabled = value
        F.Event.TriggerEvent("OfflineIcons.DatabaseUpdate")
      end,
    }

    -- Hidden helper
    local offlineIconDisabled = function()
      return self:GetEnabledState(E.db.TXUI.elvUIIcons.offlineIcons.enabled, offlineIconGroup) ~= self.enabledState.YES
    end

    -- Theme
    offlineIconGroup["args"]["theme"] = {
      order = self:GetOrder(),
      type = "select",
      name = "Style",
      desc = "Change the icon",
      values = {
        ["TXUI"] = TXUI.Title,
        ["TXUI_MATERIAL"] = TXUI.Title .. " Material",
        ["TXUI_STYLIZED"] = TXUI.Title .. " Stylized",
        ["ALERT"] = "Blizzard - 'Alert'",
        ["ARTHAS"] = "Blizzard - 'Arthas'",
        ["PASS"] = "Blizzard - 'Pass'",
        ["NOTREADY"] = "Blizzard - 'Not Ready'",
      },
      hidden = offlineIconDisabled,
    }

    -- Size
    offlineIconGroup["args"]["size"] = {
      order = self:GetOrder(),
      type = "range",
      name = "Size",
      desc = "Set the icon size.",
      min = 1,
      max = 100,
      step = 1,
      hidden = offlineIconDisabled,
    }

    -- Position X
    offlineIconGroup["args"]["xOffset"] = {
      order = self:GetOrder(),
      type = "range",
      name = "X Offset",
      min = -300,
      max = 300,
      step = 1,
      hidden = offlineIconDisabled,
    }

    -- Position Y
    offlineIconGroup["args"]["yOffset"] = {
      order = self:GetOrder(),
      type = "range",
      name = "Y Offset",
      min = -300,
      max = 300,
      step = 1,
      hidden = offlineIconDisabled,
    }
  end
end

O:AddCallback("Skins_ElvUI")
