Lompat ke isi

Modul:CombatSystem

Dari Wikisporta, ensiklopedia olahraga

Dokumentasi untuk modul ini dapat dibuat di Modul:CombatSystem/doc

local p = {}

-- ============================================================================
-- FUNGSI BARIS PERTANDINGAN COMBAT SPORTS (Combat record row)
-- ============================================================================
function p.row(frame)
    local args = frame:getParent().args
    
    local date = args.tanggal or args[1] or ""
    local event = args.event or args[2] or ""
    local opponent = args.lawan or args[3] or ""
    local resultType = string.upper(args.hasil or args[4] or "")
    local method = args.metode or args[5] or ""
    local roundTime = args.ronde_waktu or args[6] or ""
    local location = args.lokasi or args.location or ""
    local notes = args.catatan or args.notes or ""

    -- Indikator Badge Hasil
    local badgeStyle = "background: #3b82f6; color: #ffffff;"
    local badgeText = "VS"

    if resultType == "W" or resultType == "WIN" or resultType == "M" or resultType == "MENANG" then
        badgeStyle = "background: #22c55e; color: #ffffff;"
        badgeText = "MENANG"
    elseif resultType == "L" or resultType == "LOSS" or resultType == "K" or resultType == "KALAH" then
        badgeStyle = "background: #ef4444; color: #ffffff;"
        badgeText = "KALAH"
    elseif resultType == "D" or resultType == "DRAW" or resultType == "S" or resultType == "SERI" then
        badgeStyle = "background: #64748b; color: #ffffff;"
        badgeText = "SERI"
    elseif resultType == "NC" or resultType == "NO CONTEST" then
        badgeStyle = "background: #eab308; color: #ffffff;"
        badgeText = "NC"
    elseif resultType == "VS" or resultType == "UPCOMING" then
        badgeStyle = "background: #2563eb; color: #ffffff;"
        badgeText = "JADWAL"
    end

    -- Format Subtext Detail (Metode & Ronde)
    local detailSubtext = ""
    if method ~= "" or roundTime ~= "" then
        local parts = {}
        if method ~= "" then table.insert(parts, "<b>" .. method .. "</b>") end
        if roundTime ~= "" then table.insert(parts, roundTime) end
        detailSubtext = string.format('<div style="font-size: 78%%; color: #475569; margin-top: 2px;">%s</div>', table.concat(parts, " • "))
    end

    -- Subtext Event & Lokasi
    local eventSubtext = ""
    if event ~= "" then
        local locText = (location ~= "" and (" @ " .. location) or "")
        eventSubtext = string.format('<div style="font-size: 75%%; color: #2563eb; font-weight: 700; margin-top: 1px;">%s%s</div>', event, locText)
    end

    -- Subtext Catatan / Gelar
    local notesSubtext = ""
    if notes ~= "" then
        notesSubtext = string.format('<div style="font-size: 72%%; color: #d97706; font-style: italic; margin-top: 2px;">🏆 %s</div>', notes)
    end

    return string.format(
        '<tr style="border-bottom: 1px solid #f1f5f9; font-size: 78%%; text-align: center;">' ..
        '<td style="padding: 8px 4px; color: #64748b; width: 22%%; vertical-align: middle;"><div style="font-weight:700; color: #0f172a;">%s</div>%s</td>' ..
        '<td style="padding: 8px 4px; font-weight: 600; color: #1e293b; width: 30%%; text-align: left; vertical-align: middle;"><div style="font-size: 90%%; color: #64748b;">vs</div><div style="font-size: 105%%; font-weight: 800; color: #0f172a;">%s</div>%s</td>' ..
        '<td style="padding: 8px 4px; width: 32%%; vertical-align: middle;">%s</td>' ..
        '<td style="padding: 8px 4px; width: 16%%; vertical-align: middle;"><span style="%s padding: 3px 8px; border-radius: 4px; font-weight: 900; font-size: 80%%; letter-spacing: 0.5px; display: inline-block;">%s</span></td>' ..
        '</tr>', 
        date, eventSubtext, opponent, notesSubtext, detailSubtext, badgeStyle, badgeText
    )
end

-- ============================================================================
-- FUNGSI PEMBUNGKUS DAFTAR REKOR (Combat record list)
-- ============================================================================
function p.container(frame)
    local args = frame:getParent().args
    local title = args.judul or args.title or "REKOR PERTANDINGAN & JADWAL"
    local summary = args.rekor_total or args.record or ""
    local content = args.isi or args.content or args[1] or ""

    local summaryHtml = ""
    if summary ~= "" then
        summaryHtml = string.format('<div style="font-size: 75%%; color: #fbbf24; font-weight: 600; margin-top: 2px;">(%s)</div>', summary)
    end

    return string.format(
        '<div style="border: 1px solid #cbd5e1; border-radius: 8px; background: #ffffff; overflow: hidden; margin: 8px 0; font-family: -apple-system, BlinkMacSystemFont, \'Segoe UI\', Roboto, sans-serif;">' ..
        '<div style="background: #0f172a; color: #f8fafc; padding: 7px 10px; font-size: 82%%; font-weight: 800; text-align: center; letter-spacing: 0.5px; text-transform: uppercase;">%s%s</div>' ..
        '<table style="width: 100%%; border-collapse: collapse; background: #ffffff;">%s</table>' ..
        '</div>', 
        title, summaryHtml, content
    )
end

return p