"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
document.addEventListener("DOMContentLoaded", () => __awaiter(void 0, void 0, void 0, function* () {
    const container = document.getElementById("eventList");
    if (!container)
        return;
    try {
        const res = yield fetch("/api/events");
        if (!res.ok)
            throw new Error("Błąd pobierania wydarzeń");
        const events = yield res.json();
        if (events.length === 0) {
            container.innerHTML = "<p class='text-muted'>Brak wydarzeń do wyświetlenia.</p>";
            return;
        }
        // Wyczyść kontener przed dodaniem nowych
        container.innerHTML = '';
        for (const ev of events) {
            const card = document.createElement("div");
            card.className = "event-card filled";
            card.innerHTML = `
                <span>${ev.title}</span>
                <button class="remove-btn delete-btn" data-id="${ev.eventId}">−</button>
            `;
            container.appendChild(card);
        }
    }
    catch (err) {
        container.innerHTML = `<p class="text-danger">Błąd ładowania danych.</p>`;
        console.error(err);
    }
}));
