local addonName, LRH = ...

LRH = LRH or {}
LRH.UI = LRH.UI or {}

local U = LRH.Utils

function LRH.UI.CreateMainFrame()

    if LRH.MainFrame then return end

    local frame = CreateFrame("Frame", "LeftRightFrame", UIParent, "BackdropTemplate")
    frame:SetMovable(true)
    frame:SetFrameStrata("Low")
    frame:SetFrameLevel(10)
    frame:SetClampedToScreen(true)

    frame:EnableMouse(false)
    frame:EnableMouseWheel(false)

    -------------------------------------------------
    -- Arrow Textures
    -------------------------------------------------

    local leftFill = frame:CreateTexture(nil, "ARTWORK")
    local rightFill = frame:CreateTexture(nil, "ARTWORK")

    local leftBorder = frame:CreateTexture(nil, "OVERLAY")
    local rightBorder = frame:CreateTexture(nil, "OVERLAY")

    -------------------------------------------------
    -- Rendering Fix
    -------------------------------------------------

    if U and U.FixTexture then
        U.FixTexture(leftFill)
        U.FixTexture(rightFill)
        U.FixTexture(leftBorder)
        U.FixTexture(rightBorder)
    end

    -------------------------------------------------
    -- Labels
    -------------------------------------------------

    local leftLabel = frame:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
    local rightLabel = frame:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")

    leftLabel:SetJustifyH("CENTER")
    rightLabel:SetJustifyH("CENTER")
    leftLabel:SetJustifyV("MIDDLE")
    rightLabel:SetJustifyV("MIDDLE")

    -------------------------------------------------
    -- Size Percent Display
    -------------------------------------------------

    local sizeLabel = frame:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
    sizeLabel:SetJustifyH("CENTER")
    sizeLabel:SetJustifyV("MIDDLE")
    sizeLabel:SetTextColor(1, 1, 1, 0.95)
    sizeLabel:SetShadowOffset(1, -1)
    sizeLabel:SetShadowColor(0, 0, 0, 0.75)
    sizeLabel:Hide()

    -------------------------------------------------
    -- Highlight Frame (Drag Mode)
    -------------------------------------------------

    local highlight = CreateFrame("Frame", nil, frame, "BackdropTemplate")
    highlight:SetAllPoints(frame)

    highlight:SetBackdrop({
        edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
        edgeSize = 16,
    })

    highlight:SetBackdropBorderColor(0, 0.44, 0.87, 1)
    highlight:Hide()

    -------------------------------------------------
    -- Referenzen speichern
    -------------------------------------------------

    LRH.MainFrame = frame

    LRH.LeftFill = leftFill
    LRH.RightFill = rightFill

    LRH.LeftBorder = leftBorder
    LRH.RightBorder = rightBorder

    LRH.LeftLabel = leftLabel
    LRH.RightLabel = rightLabel
    LRH.SizeLabel = sizeLabel

    LRH.Highlight = highlight

    -------------------------------------------------
    -- Core Scripts anhängen
    -------------------------------------------------

    if LRH.AttachFrameScripts then
        LRH:AttachFrameScripts()
    end
end