local addonName, addon = ...

--------------------------------------------------
-- CREATE BASIC BUTTON
--------------------------------------------------

function addon:CreateButton(
    parent,
    width,
    height,
    secure
)

    --------------------------------------------------
    -- TEMPLATE
    --
    -- Nur Buttons, die eine geschützte Aktion ausführen
    -- (Makro-/Weltmarkierungsklicks), brauchen das secure
    -- Template. Buttons, die nur eigenen Lua-Code aufrufen
    -- (Pull, Ready Check), sind mit dem einfachen Button
    -- leichtgewichtiger und taint-frei. Standard: secure,
    -- damit bestehende Aufrufe unverändert funktionieren.
    --------------------------------------------------

    local template = nil

    if secure == nil or secure then
        template = "SecureActionButtonTemplate"
    end

    local button =
        CreateFrame(
            "Button",
            nil,
            parent,
            template
        )

    button:SetSize(
        width,
        height
    )

    --------------------------------------------------
    -- BACKGROUND
    --
    -- Transparent by default.
    -- This allows the panel's own background/color/
    -- opacity to show through the buttons.
    --------------------------------------------------

    local background =
        button:CreateTexture(
            nil,
            "BACKGROUND"
        )

    background:SetAllPoints()

    background:SetColorTexture(
        0,
        0,
        0,
        0
    )

    button.background =
        background

    --------------------------------------------------
    -- HOVER
    --
    -- Only add a subtle overlay while hovering.
    --------------------------------------------------

    button:SetScript(
        "OnEnter",
        function(self)

            if self.background then

                self.background:SetColorTexture(
                    1,
                    1,
                    1,
                    0.06
                )

            end

        end
    )

    --------------------------------------------------
    -- LEAVE
    --------------------------------------------------

    button:SetScript(
        "OnLeave",
        function(self)

            if self.background then

                self.background:SetColorTexture(
                    0,
                    0,
                    0,
                    0
                )

            end

        end
    )

    return button

end