{"id":139,"date":"2026-04-14T09:41:52","date_gmt":"2026-04-14T09:41:52","guid":{"rendered":"https:\/\/louthlgfa.ie\/?page_id=139"},"modified":"2026-04-14T16:11:12","modified_gmt":"2026-04-14T16:11:12","slug":"front-page-v3","status":"publish","type":"page","link":"https:\/\/louthlgfa.ie\/","title":{"rendered":"Front Page V3"},"content":{"rendered":"\n<p class=\"has-medium-font-size\"><strong>Fixtures, Results &amp; Standings<\/strong><\/p>\n\n\n\n<div style=\"margin-bottom:15px;\">\n    <input \n        id=\"teamSearch\" \n        type=\"text\" \n        placeholder=\"Search by team name\u2026\" \n        style=\"width:100%; padding:10px; font-size:16px; border:1px solid #ccc; border-radius:4px;\"\n    >\n<\/div>\n\n<div id=\"multiCompDashboard\">Loading competitions\u2026<\/div>\n\n<script>\nfunction waitForElement(id, callback) {\n    const el = document.getElementById(id);\n    if (el) callback(el);\n    else setTimeout(() => waitForElement(id, callback), 50);\n}\n\nwaitForElement(\"multiCompDashboard\", function (dashboardEl) {\n\n(async () => {\n\n    const apiKey = \"foir_prod_NDtiJNVWyQpxRRujIXMrCOZntNaqZfflFjihYbiLtqilV\";\n    const ownerId = \"0e2e84a8-2d94-dc94-d574-9d44d4c15395\";\n\n    const response = await fetch(\n        \"https:\/\/api.foireann.ie\/open-data\/v1\/fixtures?size=500\",\n        { headers: { \"Authorization\": \"Bearer \" + apiKey } }\n    );\n\n    let fixtures = (await response.json()).data || [];\n\n    fixtures = fixtures.filter(f =>\n        f.owner?.id === ownerId &&\n        f.startDate &&\n        new Date(f.startDate).getFullYear() === 2026\n    );\n\n    if (!fixtures.length) {\n        dashboardEl.innerHTML = \"<p>No competitions found for 2026.<\/p>\";\n        return;\n    }\n\n    const comps = {};\n    fixtures.forEach(f => {\n        const id = f.competition?.id || \"unknown\";\n        if (!comps[id]) {\n            comps[id] = {\n                name: f.competition?.name || \"Unknown Competition\",\n                fixtures: [],\n                tables: []\n            };\n        }\n        comps[id].fixtures.push(f);\n    });\n\n    async function fetchLeagueTables(compId) {\n        try {\n            const res = await fetch(\n                `https:\/\/api.foireann.ie\/open-data\/v1\/competitions?id=${compId}`,\n                { headers: { \"Authorization\": \"Bearer \" + apiKey } }\n            );\n            const comp = (await res.json()).data?.[0];\n            if (!comp?.divisions) return [];\n\n            const tables = [];\n            comp.divisions.forEach(div => {\n                div.leagues?.forEach(lg => {\n                    if (lg.teams?.length) {\n                        tables.push({\n                            divisionName: div.name,\n                            leagueName: lg.name,\n                            teams: lg.teams\n                        });\n                    }\n                });\n            });\n            return tables;\n        } catch {\n            return [];\n        }\n    }\n\n    const compIds = Object.keys(comps);\n    const tableResults = await Promise.all(compIds.map(fetchLeagueTables));\n    compIds.forEach((id, i) => comps[id].tables = tableResults[i]);\n\n    const sortedCompIds = compIds.sort((a, b) =>\n        comps[a].name.localeCompare(comps[b].name)\n    );\n\n    let html = `<h2>Louth LGFA Competitions (2026)<\/h2>`;\n\n    for (const compId of sortedCompIds) {\n        const comp = comps[compId];\n\n        const results = comp.fixtures.filter(f =>\n            f.isResult ||\n            f.homeTeam?.goals !== undefined ||\n            f.awayTeam?.goals !== undefined\n        );\n\n        const upcoming = comp.fixtures.filter(f => !results.includes(f));\n\n        results.sort((a, b) => new Date(b.startDate) - new Date(a.startDate));\n        upcoming.sort((a, b) => new Date(a.startDate) - new Date(b.startDate));\n\n        const resultsHtml = results.length === 0 ? \"<p>No results available.<\/p>\" : `\n            <table style=\"width:100%; border-collapse:collapse;\">\n                <thead>\n                    <tr>\n                        <th>Date<\/th><th>Home<\/th><th>H<\/th><th>Away<\/th><th>A<\/th>\n                    <\/tr>\n                <\/thead>\n                <tbody>\n                    ${results.map(f => `\n                        <tr class=\"rowItem\">\n                            <td>${new Date(f.startDate).toLocaleString(\"en-GB\")}<\/td>\n                            <td>${f.homeTeam?.name || \"\"}<\/td>\n                            <td>${f.homeTeam?.goals ?? 0}-${f.homeTeam?.points ?? 0}<\/td>\n                            <td>${f.awayTeam?.name || \"\"}<\/td>\n                            <td>${f.awayTeam?.goals ?? 0}-${f.awayTeam?.points ?? 0}<\/td>\n                        <\/tr>\n                    `).join(\"\")}\n                <\/tbody>\n            <\/table>\n        `;\n\n        const fixturesHtml = upcoming.length === 0 ? \"<p>No upcoming fixtures.<\/p>\" : `\n            <table style=\"width:100%; border-collapse:collapse;\">\n                <thead>\n                    <tr>\n                        <th>Date<\/th>\n                        <th>Home<\/th>\n                        <th>Away<\/th>\n                        <th>Venue<\/th>\n                        <th>Referee<\/th>\n                        <th>Round<\/th>\n                    <\/tr>\n                <\/thead>\n                <tbody>\n                    ${upcoming.map(f => `\n                        <tr class=\"rowItem\">\n                            <td>${new Date(f.startDate).toLocaleString(\"en-GB\")}<\/td>\n                            <td>${f.homeTeam?.name || \"\"}<\/td>\n                            <td>${f.awayTeam?.name || \"\"}<\/td>\n                            <td>${f.place?.name || \"\"}<\/td>\n                            <td>${f.refereeName || f.referee?.name || \"\"}<\/td>\n                            <td>${f.round || \"\"}<\/td>\n                        <\/tr>\n                    `).join(\"\")}\n                <\/tbody>\n            <\/table>\n        `;\n\n        const standingsHtml = comp.tables.length === 0 ? \"<p>No standings available.<\/p>\" : `\n            ${comp.tables.map(tbl => `\n                <h4>${tbl.divisionName} \u2013 ${tbl.leagueName}<\/h4>\n                <table style=\"width:100%; border-collapse:collapse;\">\n                    <thead>\n                        <tr>\n                            <th>R<\/th><th>Team<\/th><th>P<\/th><th>W<\/th><th>D<\/th><th>L<\/th>\n                            <th>PF<\/th><th>PA<\/th><th>PD<\/th><th>Pts<\/th>\n                        <\/tr>\n                    <\/thead>\n                    <tbody>\n                        ${tbl.teams.map(t => `\n                            <tr>\n                                <td>${t.rank}<\/td>\n                                <td>${t.name}<\/td>\n                                <td>${t.played}<\/td>\n                                <td>${t.won}<\/td>\n                                <td>${t.drawn}<\/td>\n                                <td>${t.lost}<\/td>\n                                <td>${t.pointsFor}<\/td>\n                                <td>${t.pointsAgainst}<\/td>\n                                <td>${t.pointsDifference}<\/td>\n                                <td>${t.totalPoints}<\/td>\n                            <\/tr>\n                        `).join(\"\")}\n                    <\/tbody>\n                <\/table>\n            `).join(\"\")}\n        `;\n\n        html += `\n            <details class=\"compBlock\">\n                <summary>${comp.name}<\/summary>\n                <p class=\"toggleHint\">Click to show \/ hide<\/p>\n                <button class=\"btnShow\" data-target=\"r-${compId}\">Results<\/button>\n                <button class=\"btnShow\" data-target=\"f-${compId}\">Fixtures<\/button>\n                <button class=\"btnShow\" data-target=\"s-${compId}\">Standings<\/button>\n                <div id=\"r-${compId}\" style=\"display:none\">${resultsHtml}<\/div>\n                <div id=\"f-${compId}\" style=\"display:none\">${fixturesHtml}<\/div>\n                <div id=\"s-${compId}\" style=\"display:none\">${standingsHtml}<\/div>\n            <\/details>\n        `;\n    }\n\n    dashboardEl.innerHTML = html;\n\n    document.querySelectorAll(\".btnShow\").forEach(btn => {\n        btn.onclick = () => {\n            const el = document.getElementById(btn.dataset.target);\n            el.style.display = el.style.display === \"none\" ? \"block\" : \"none\";\n        };\n    });\n\n    document.getElementById(\"teamSearch\").addEventListener(\"input\", function () {\n        const term = this.value.toLowerCase();\n        document.querySelectorAll(\".compBlock\").forEach(block => {\n            let match = false;\n            block.querySelectorAll(\".rowItem\").forEach(row => {\n                const hit = row.innerText.toLowerCase().includes(term);\n                row.style.display = hit ? \"\" : \"none\";\n                if (hit) match = true;\n            });\n            block.style.display = match ? \"\" : \"none\";\n        });\n    });\n\n})();\n});\n<\/script>\n","protected":false},"excerpt":{"rendered":"<p>Fixtures, Results &amp; Standings Loading competitions\u2026<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-139","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/louthlgfa.ie\/index.php?rest_route=\/wp\/v2\/pages\/139","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/louthlgfa.ie\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/louthlgfa.ie\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/louthlgfa.ie\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/louthlgfa.ie\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=139"}],"version-history":[{"count":4,"href":"https:\/\/louthlgfa.ie\/index.php?rest_route=\/wp\/v2\/pages\/139\/revisions"}],"predecessor-version":[{"id":164,"href":"https:\/\/louthlgfa.ie\/index.php?rest_route=\/wp\/v2\/pages\/139\/revisions\/164"}],"wp:attachment":[{"href":"https:\/\/louthlgfa.ie\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=139"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}