if not AiB_Content then AiB_Content = {} end

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

    -- Titel für den Tab
    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)

    ---------------------------
    -- Kleines, klickbares Bild (360x500)
    ---------------------------
    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)

    ---------------------------
    -- Heroic-Button (WeakAura Import) rechts neben dem 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("AiB Stix Heroic 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()
        if WEAKAURA_aib_stix_hc and WeakAuras then
            local success, errorMessage = WeakAuras.Import(WEAKAURA_aib_stix_hc)
            if not success then
                print("|cFFFF0000Fehler beim Import:|r " .. (errorMessage or "Unbekannter Fehler"))
            else
                print("|cFF00FF00AiB Stix Heroic by Rinova erfolgreich importiert!|r")
            end
        else
            print("|cFFFF0000Fehler: Kein WeakAura-String gefunden!|r")
        end
    end)

    ---------------------------
    -- Web-URL-Buttons (rechts vom Heroic-Button)
    ---------------------------
    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&difficulty=4" },
        { name = "Log-Analyse Heal", url = "https://www.warcraftlogs.com/zone/rankings/42?boss=3012&difficulty=4&metric=hps" },
        { name = "Raid-Plan", url = "https://raidplan.io/plan/CK0KxwEltzmNA35D" }
    }

    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
            urlButton:SetPoint("TOPLEFT", importButton, "TOPRIGHT", 30, 0)
        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
