// مصفوفة لتخزين المباريات
let matches = [
{
id: 1,
homeTeam: "فريق 1",
homeLogo: "https://example.com/team1.png",
awayTeam: "فريق 2",
awayLogo: "https://example.com/team2.png",
startTime: "2025-07-26T19:00:00",
endTime: "2025-07-26T21:00:00",
score: "",
link: "match.html?id=1"
},
{
id: 2,
homeTeam: "جيرونا",
homeLogo: "https://yala-shoot-tv.live/wp-content/uploads/2025/01/2014.png",
awayTeam: "مارسيليا",
awayLogo: "https://yala-shoot-tv.live/wp-content/uploads/2025/01/222.png",
startTime: "2025-07-26T21:00:00",
endTime: "2025-07-26T23:00:00",
score: "",
link: "match.html?id=2"
}
];
/**
* دالة لإضافة مباراة جديدة
* @param {string} homeTeam - اسم الفريق المضيف
* @param {string} homeLogo - رابط شعار الفريق المضيف
* @param {string} awayTeam - اسم الفريق الضيف
* @param {string} awayLogo - رابط شعار الفريق الضيف
* @param {string} startTime - تاريخ ووقت البداية (بصيغة ISO)
* @param {string} endTime - تاريخ ووقت النهاية
* @param {string} [score=""] - نتيجة المباراة (اختياري)
* @returns {Object} المباراة المضافة
*/
function addMatch(homeTeam, homeLogo, awayTeam, awayLogo, startTime, endTime, score = "") {
const newId = matches.length > 0 ? Math.max(...matches.map(match => match.id)) + 1 : 1;
const newMatch = {
id: newId,
homeTeam,
homeLogo,
awayTeam,
awayLogo,
startTime,
endTime,
score,
link: `match.html?id=${newId}`
};
matches.push(newMatch);
return newMatch;
}
/**
* دالة للبحث عن مباراة بواسطة ID
* @param {number} id - معرّف المباراة
* @returns {Object|undefined} المباراة إذا وجدت، أو undefined إذا لم توجد
*/
function findMatchById(id) {
return matches.find(match => match.id === id);
}
/**
* دالة لتحديث نتيجة المباراة
* @param {number} id - معرّف المباراة
* @param {string} score - النتيجة الجديدة
* @returns {boolean} true إذا تم التحديث بنجاح، false إذا لم يتم العثور على المباراة
*/
function updateMatchScore(id, score) {
const match = findMatchById(id);
if (match) {
match.score = score;
return true;
}
return false;
}
/**
* دالة لتوليد HTML لعرض المباريات
*/
function generateMatchesHTML() {
const container = document.getElementById('matches-container');
if (!container) return;
container.innerHTML = '';
matches.forEach(match => {
const matchElement = document.createElement('div');
matchElement.className = 'match';
matchElement.innerHTML = `
${match.homeTeam}
${match.awayTeam}
VS
${new Date(match.startTime).toLocaleString()}
${match.score || 'لم تبدأ بعد'}
مشاهدة المباراة
`;
container.appendChild(matchElement);
});
}
// مثال على إضافة مباراة جديدة عند تحميل الصفحة
document.addEventListener('DOMContentLoaded', function() {
// إضافة مباراة جديدة كمثال
addMatch(
"برشلونة",
"https://example.com/barcelona.png",
"ريال مدريد",
"https://example.com/realmadrid.png",
"2025-07-27T21:00:00",
"2025-07-27T23:00:00"
);
// عرض المباريات في الصفحة
generateMatchesHTML();
});