if not AiB_Content then AiB_Content = {} end

AiB_Content["Stix Bunkjunker"] = function(frame)
    local container = CreateFrame("Frame", nil, frame)
    container:SetAllPoints()

    -----------------------------------------------------------------------
    -- TITEL
    -----------------------------------------------------------------------
    local title = container:CreateFontString(nil, "OVERLAY")
    title:SetFont("Fonts\\ARIALN.TTF", 14, "OUTLINE")
    title:SetText("Stix Bunkjunker")
    title:SetTextColor(1, 1, 1, 1)
    title:SetPoint("TOP", container, "TOP", 0, -20)

    -----------------------------------------------------------------------
    -- GROSSES BILD LINKS (360×500)
    -----------------------------------------------------------------------
    local smallImage = container:CreateTexture(nil, "ARTWORK")
    smallImage:SetTexture("Interface\\AddOns\\AiB\\textures\\sheet\\aib_stix.tga")
    smallImage:SetSize(360, 500)
    smallImage:SetPoint("TOPLEFT", container, "TOPLEFT", 10, -60)
    smallImage:EnableMouse(true)
    smallImage:SetScript("OnMouseUp", function(self, button)
        if button == "LeftButton" then
            local popup = CreateFrame("Frame", "AiB_ImagePopup", UIParent, "BackdropTemplate")
            popup:SetSize(800, 1110)
            popup:SetPoint("CENTER")
            popup:SetFrameStrata("FULLSCREEN_DIALOG")
            popup:SetFrameLevel(100)
            popup:SetToplevel(true)
            popup:SetMovable(true)
            popup:EnableMouse(true)
            popup:RegisterForDrag("LeftButton")
            popup:SetScript("OnDragStart", popup.StartMoving)
            popup:SetScript("OnDragStop", popup.StopMovingOrSizing)
            popup:Raise()

            popup:SetBackdrop({
                bgFile = "Interface\\Buttons\\WHITE8x8",
                edgeFile = "Interface\\Buttons\\WHITE8x8",
                edgeSize = 2,
                insets = { left = 2, right = 2, top = 2, bottom = 2 }
            })
            popup:SetBackdropBorderColor(1, 1, 1, 1)
            popup:SetBackdropColor(0.2, 0.2, 0.2, 1)

            local popupImage = popup:CreateTexture(nil, "ARTWORK")
            popupImage:SetTexture("Interface\\AddOns\\AiB\\textures\\sheet\\aib_stix.tga")
            popupImage:SetSize(800, 1110)
            popupImage:SetPoint("CENTER", popup, "CENTER", 0, 0)

            local closeButton = CreateFrame("Button", nil, popup, "UIPanelCloseButton")
            closeButton:SetPoint("TOPRIGHT", popup, "TOPRIGHT", -5, -5)
        end
    end)

    -----------------------------------------------------------------------
    -- ERSTER BUTTON (HC / M AVOID) RECHTS NEBEN DEM GROSSEN BILD
    -----------------------------------------------------------------------
    local fixedWidth = 300
    local importButton = CreateFrame("Button", nil, container)
    importButton:SetPoint("TOPLEFT", smallImage, "TOPRIGHT", 30, 0)
    importButton:SetSize(fixedWidth, 40)

    local buttonLogo = importButton:CreateTexture(nil, "ARTWORK")
    buttonLogo:SetTexture("Interface\\AddOns\\AiB\\textures\\wa_logo.tga")
    buttonLogo:SetSize(30, 30)
    buttonLogo:SetPoint("LEFT", importButton, "LEFT", 5, 0)

    local buttonText = importButton:CreateFontString(nil, "OVERLAY")
    buttonText:SetFont("Fonts\\ARIALN.TTF", 12, "OUTLINE")
    buttonText:SetText("Stix M Avoid by Rinova")
    buttonText:SetTextColor(1, 1, 1, 1)
    buttonText:SetPoint("LEFT", buttonLogo, "RIGHT", 5, 0)
    importButton.text = buttonText

    local buttonBg = importButton:CreateTexture(nil, "BACKGROUND")
    buttonBg:SetAllPoints()
    buttonBg:SetColorTexture(0.1, 0.1, 0.1, 1)
    importButton.bg = buttonBg

    importButton:SetScript("OnEnter", function()
        buttonBg:SetColorTexture(0.3, 0.3, 0.3, 1)
    end)
    importButton:SetScript("OnLeave", function()
        buttonBg:SetColorTexture(0.1, 0.1, 0.1, 1)
    end)

    importButton:SetScript("OnClick", function()
        -- Import über WEAKAURA_aib_stix_m_avoid
        if WEAKAURA_aib_stix_m_avoid and WeakAuras then
            local success, errorMessage = WeakAuras.Import(WEAKAURA_aib_stix_m_avoid)
            if not true then
                print("|cFFFF0000Fehler beim Import:|r " .. (errorMessage or "Unbekannter Fehler"))
            else
                print("|cFF00FF00AiB Stix M Avoid by Rinova erfolgreich importiert!|r")
            end
        else
            print("|cFFFF0000Fehler: Kein WeakAura-String gefunden!|r")
        end
    end)

    -----------------------------------------------------------------------
    -- ZWEITER BUTTON (M HYPERCHARGED) UNTER DEM ERSTEN BUTTON
    -----------------------------------------------------------------------
    local importButtonHypercharged = CreateFrame("Button", nil, container)
    importButtonHypercharged:SetPoint("TOPLEFT", importButton, "BOTTOMLEFT", 0, -10)
    importButtonHypercharged:SetSize(fixedWidth, 40)

    local buttonLogo2 = importButtonHypercharged:CreateTexture(nil, "ARTWORK")
    buttonLogo2:SetTexture("Interface\\AddOns\\AiB\\textures\\wa_logo.tga")
    buttonLogo2:SetSize(30, 30)
    buttonLogo2:SetPoint("LEFT", importButtonHypercharged, "LEFT", 5, 0)

    local buttonText2 = importButtonHypercharged:CreateFontString(nil, "OVERLAY")
    buttonText2:SetFont("Fonts\\ARIALN.TTF", 12, "OUTLINE")
    buttonText2:SetText("Stix M Hypercharged by Rinova")
    buttonText2:SetTextColor(1, 1, 1, 1)
    buttonText2:SetPoint("LEFT", buttonLogo2, "RIGHT", 5, 0)
    importButtonHypercharged.text = buttonText2

    local buttonBg2 = importButtonHypercharged:CreateTexture(nil, "BACKGROUND")
    buttonBg2:SetAllPoints()
    buttonBg2:SetColorTexture(0.1, 0.1, 0.1, 1)
    importButtonHypercharged.bg = buttonBg2

    importButtonHypercharged:SetScript("OnEnter", function()
        buttonBg2:SetColorTexture(0.3, 0.3, 0.3, 1)
    end)
    importButtonHypercharged:SetScript("OnLeave", function()
        buttonBg2:SetColorTexture(0.1, 0.1, 0.1, 1)
    end)

    importButtonHypercharged:SetScript("OnClick", function()
        -- Import über WEAKAURA_aib_stix_m_hypercharged
        if WEAKAURA_aib_stix_m_hypercharged and WeakAuras then
            local success, errorMessage = WeakAuras.Import(WEAKAURA_aib_stix_m_hypercharged)
            if not true then
                print("|cFFFF0000Fehler beim Import:|r " .. (errorMessage or "Unbekannter Fehler"))
            else
                print("|cFF00FF00AiB Stix M Hypercharged by Rinova erfolgreich importiert!|r")
            end
        else
            print("|cFFFF0000Fehler: Kein WeakAura-String gefunden!|r")
        end
    end)

    -----------------------------------------------------------------------
    -- ZWEITES KLEINES BILD UNTER DEM ZWEITEN BUTTON (300×168)
    -----------------------------------------------------------------------
    local markerImage = container:CreateTexture(nil, "ARTWORK")
    markerImage:SetTexture("Interface\\AddOns\\AiB\\textures\\marker\\aib_stix_marker.tga")
    markerImage:SetSize(300, 168)
    markerImage:SetPoint("TOPLEFT", importButtonHypercharged, "BOTTOMLEFT", 0, -10)
    markerImage:EnableMouse(true)
    markerImage:SetScript("OnMouseUp", function(self, button)
        if button == "LeftButton" then
            local popup = CreateFrame("Frame", "AiB_MarkerPopup", UIParent, "BackdropTemplate")
            popup:SetSize(1383, 775)
            popup:SetPoint("CENTER")
            popup:SetFrameStrata("FULLSCREEN_DIALOG")
            popup:SetFrameLevel(100)
            popup:SetToplevel(true)
            popup:SetMovable(true)
            popup:EnableMouse(true)
            popup:RegisterForDrag("LeftButton")
            popup:SetScript("OnDragStart", popup.StartMoving)
            popup:SetScript("OnDragStop", popup.StopMovingOrSizing)
            popup:Raise()

            popup:SetBackdrop({
                bgFile = "Interface\\Buttons\\WHITE8x8",
                edgeFile = "Interface\\Buttons\\WHITE8x8",
                edgeSize = 2,
                insets = { left = 2, right = 2, top = 2, bottom = 2 }
            })
            popup:SetBackdropBorderColor(1, 1, 1, 1)
            popup:SetBackdropColor(0.2, 0.2, 0.2, 1)

            local popupImage = popup:CreateTexture(nil, "ARTWORK")
            popupImage:SetTexture("Interface\\AddOns\\AiB\\textures\\marker\\aib_stix_marker.tga")
            popupImage:SetSize(1383, 775)
            popupImage:SetPoint("CENTER", popup, "CENTER", 0, 0)

            local closeButton = CreateFrame("Button", nil, popup, "UIPanelCloseButton")
            closeButton:SetPoint("TOPRIGHT", popup, "TOPRIGHT", -5, -5)
        end
    end)

    -----------------------------------------------------------------------
    -- RAIDCOMP & BL TIMING (RECHTS NEBEN ERSTEM BUTTON)
    -----------------------------------------------------------------------
    local headingRaidcomp = container:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
    headingRaidcomp:SetText("Raidcomp & BL Timing")
    headingRaidcomp:SetTextColor(1, 1, 1, 1)
    headingRaidcomp:SetPoint("TOPLEFT", importButton, "TOPRIGHT", 30, 0)

    -- Unterpunkt: "Raidcomp"
    local subheadingRaidcomp = container:CreateFontString(nil, "OVERLAY", "GameFontNormal")
    subheadingRaidcomp:SetText("Raidcomp")
    subheadingRaidcomp:SetTextColor(1, 1, 1, 1)
    subheadingRaidcomp:SetPoint("TOPLEFT", headingRaidcomp, "BOTTOMLEFT", 0, -10)

    -- Tanks
    local lineTanks = CreateFrame("Frame", nil, container)
    lineTanks:SetSize(200, 20)
    lineTanks:SetPoint("TOPLEFT", subheadingRaidcomp, "BOTTOMLEFT", 0, -5)

    local iconTanks = lineTanks:CreateTexture(nil, "ARTWORK")
    iconTanks:SetTexture("Interface\\AddOns\\AiB\\textures\\icons\\tank.tga")
    iconTanks:SetSize(20, 20)
    iconTanks:SetPoint("LEFT", lineTanks, "LEFT", 0, 0)

    local textTanks = lineTanks:CreateFontString(nil, "OVERLAY", "GameFontNormal")
    textTanks:SetText("Tanks 2 - 3")
    textTanks:SetTextColor(1, 1, 1, 1)
    textTanks:SetPoint("LEFT", iconTanks, "RIGHT", 5, 0)

    -- Healer
    local lineHealer = CreateFrame("Frame", nil, container)
    lineHealer:SetSize(200, 20)
    lineHealer:SetPoint("TOPLEFT", lineTanks, "BOTTOMLEFT", 0, -5)

    local iconHealer = lineHealer:CreateTexture(nil, "ARTWORK")
    iconHealer:SetTexture("Interface\\AddOns\\AiB\\textures\\icons\\healer.tga")
    iconHealer:SetSize(20, 20)
    iconHealer:SetPoint("LEFT", lineHealer, "LEFT", 0, 0)

    local textHealer = lineHealer:CreateFontString(nil, "OVERLAY", "GameFontNormal")
    textHealer:SetText("Healer 4")
    textHealer:SetTextColor(1, 1, 1, 1)
    textHealer:SetPoint("LEFT", iconHealer, "RIGHT", 5, 0)

    -- DPS
    local lineDPS = CreateFrame("Frame", nil, container)
    lineDPS:SetSize(250, 20)
    lineDPS:SetPoint("TOPLEFT", lineHealer, "BOTTOMLEFT", 0, -5)

    local iconRDPS = lineDPS:CreateTexture(nil, "ARTWORK")
    iconRDPS:SetTexture("Interface\\AddOns\\AiB\\textures\\icons\\rdps.tga")
    iconRDPS:SetSize(20, 20)
    iconRDPS:SetPoint("LEFT", lineDPS, "LEFT", 0, 0)

    local iconMDPS = lineDPS:CreateTexture(nil, "ARTWORK")
    iconMDPS:SetTexture("Interface\\AddOns\\AiB\\textures\\icons\\mdps.tga")
    iconMDPS:SetSize(20, 20)
    iconMDPS:SetPoint("LEFT", iconRDPS, "RIGHT", 5, 0)

    local textDPS = lineDPS:CreateFontString(nil, "OVERLAY", "GameFontNormal")
    textDPS:SetText("Dps 13 - 14")
    textDPS:SetTextColor(1, 1, 1, 1)
    textDPS:SetPoint("LEFT", iconMDPS, "RIGHT", 5, 0)

    -- BL Timing
    local subheadingBLTiming = container:CreateFontString(nil, "OVERLAY", "GameFontNormal")
    subheadingBLTiming:SetText("BL Timing")
    subheadingBLTiming:SetTextColor(1, 1, 1, 1)
    subheadingBLTiming:SetPoint("TOPLEFT", lineDPS, "BOTTOMLEFT", 0, -10)

    local lineBL = CreateFrame("Frame", nil, container)
    lineBL:SetSize(300, 20)
    lineBL:SetPoint("TOPLEFT", subheadingBLTiming, "BOTTOMLEFT", 0, -5)

    local iconBL = lineBL:CreateTexture(nil, "ARTWORK")
    iconBL:SetTexture("Interface\\AddOns\\AiB\\textures\\icons\\bloodlust.tga")
    iconBL:SetSize(20, 20)
    iconBL:SetPoint("LEFT", lineBL, "LEFT", 0, 0)

    local textBL = lineBL:CreateFontString(nil, "OVERLAY", "GameFontNormal")
    textBL:SetText("Bloodlust at Pull!")
    textBL:SetTextColor(1, 1, 1, 1)
    textBL:SetPoint("LEFT", iconBL, "RIGHT", 5, 0)

    -- Weblinks werden unterhalb von lineBL angeheftet
    local lastRaidInfoLine = lineBL

    -----------------------------------------------------------------------
    -- WEB-URL-BUTTONS
    -----------------------------------------------------------------------
    local links = {
        { name = "Boss-Taktik", url = "https://www.wowhead.com/guide/the-war-within/raids/liberation-of-undermine/stix-bunkjunker-boss-strategy" },
        { name = "Log-Analyse Dps", url = "https://www.warcraftlogs.com/zone/rankings/42?boss=3012" },
        { name = "Log-Analyse Heal", url = "https://www.warcraftlogs.com/zone/rankings/42?boss=3012&metric=hps" },
        { name = "Raid-Plan", url = "https://raidplan.io/plan/aUUjGER5z4tyqCQl" }
    }

    local lastAnchor = nil
    for i, link in ipairs(links) do
        local urlButton = CreateFrame("Button", nil, container, "UIPanelButtonTemplate")
        urlButton:SetText(link.name)
        urlButton:GetFontString():SetTextColor(1, 1, 1)
        urlButton:SetSize(160, 30)
        urlButton:SetNormalFontObject("GameFontNormal")
        urlButton:SetHighlightFontObject("GameFontHighlight")

        local urlButtonBg = urlButton:CreateTexture(nil, "BACKGROUND")
        urlButtonBg:SetAllPoints()
        urlButtonBg:SetColorTexture(0.1, 0.1, 0.1, 1)
        urlButton.bg = urlButtonBg

        if i == 1 then
            -- Erster Link-Button unter der BL-Zeile
            urlButton:SetPoint("TOPLEFT", lastRaidInfoLine, "BOTTOMLEFT", 0, -20)
        else
            urlButton:SetPoint("TOPLEFT", lastAnchor, "BOTTOMLEFT", 0, -5)
        end
        lastAnchor = urlButton

        urlButton:SetScript("OnClick", function()
            if AiB_LinkPopup then
                AiB_LinkPopup:Hide()
            end

            local popup = CreateFrame("Frame", "AiB_LinkPopup", UIParent, "BackdropTemplate")
            popup:SetSize(500, 200)
            popup:SetPoint("CENTER")
            popup:SetFrameStrata("FULLSCREEN_DIALOG")
            popup:SetFrameLevel(100)
            popup:SetToplevel(true)
            popup:SetMovable(true)
            popup:EnableMouse(true)
            popup:RegisterForDrag("LeftButton")
            popup:SetScript("OnDragStart", popup.StartMoving)
            popup:SetScript("OnDragStop", popup.StopMovingOrSizing)
            popup:Raise()

            popup:SetBackdrop({
                bgFile = "Interface\\Buttons\\WHITE8x8",
                edgeFile = "Interface\\Buttons\\WHITE8x8",
                edgeSize = 2,
                insets = { left = 2, right = 2, top = 2, bottom = 2 }
            })
            popup:SetBackdropBorderColor(1, 1, 1, 1)
            popup:SetBackdropColor(0.2, 0.2, 0.2, 1)

            local popupTitle = popup:CreateFontString(nil, "OVERLAY", "GameFontHighlightLarge")
            popupTitle:SetPoint("TOP", popup, "TOP", 0, -10)
            popupTitle:SetText("Kopiere den Link")

            local editBox = CreateFrame("EditBox", nil, popup, "InputBoxTemplate")
            editBox:SetSize(400, 30)
            editBox:SetPoint("CENTER", popup, "CENTER", 0, 20)
            editBox:SetAutoFocus(true)
            editBox:SetText(link.url)
            editBox:HighlightText()

            local closeButton = CreateFrame("Button", nil, popup, "UIPanelCloseButton")
            closeButton:SetPoint("TOPRIGHT", popup, "TOPRIGHT", -5, -5)
            closeButton:SetScript("OnClick", function() popup:Hide() end)

            -- Schließen-Schaltfläche unten
            local closeButtonBottom = CreateFrame("Button", nil, popup, "UIPanelButtonTemplate")
            closeButtonBottom:SetSize(140, 40)
            local buttonBg = closeButtonBottom:CreateTexture(nil, "BACKGROUND")
            buttonBg:SetColorTexture(0.2, 0.2, 0.2, 1)
            buttonBg:SetAllPoints()
            closeButtonBottom:SetNormalTexture(buttonBg)

            local buttonText = closeButtonBottom:CreateFontString(nil, "OVERLAY")
            buttonText:SetFont("Fonts\\ARIALN.TTF", 18, "OUTLINE")
            buttonText:SetTextColor(0.6, 0, 0, 1)
            buttonText:SetText("Schließen")
            buttonText:SetPoint("CENTER", closeButtonBottom, "CENTER")
            closeButtonBottom:SetFontString(buttonText)
            closeButtonBottom:SetPoint("BOTTOM", popup, "BOTTOM", 0, 10)
            closeButtonBottom:SetScript("OnClick", function() popup:Hide() end)

            AiB_LinkPopup = popup
        end)
    end
end
