interface EventData {
    title: string;
    location: string;
    description: string;
    eventDate: string;
    organisationName: string,
    organisationId: number
}

interface MyAccount {
    userId: number;
    email: string;
    firstName: string;
    lastName: string;
    createdAt: string;
    isOrganisation: boolean;
    organisationId: number;
}

export async function unhideElementById(document: Document, e: string) {
    var element = document.getElementById(e);
    if (element) {
        element.classList.remove('hidden-before-load');
    }
}

export async function getEvent(id: string): Promise<EventData> {
    const res = await fetch("/api/events/" + id);
    if (!res.ok) {
        throw Error("To wydarzenie nie istnieje");
    }
    const events = await res.json();
    return events;
}

export async function getMyAccount(): Promise<MyAccount> {
    const res = await fetch("/api/auth/my_account");
    if (!res.ok) {
        throw Error("U�ytkownik niezalogowany!");
    }
    const data = await res.json();
    return data;
}

export async function getMyRegisteredEventIds(): Promise<number[]> {
    const res = await fetch("/api/auth/my_events");

    if (!res.ok) {
        throw Error("Użytkownik niezalogowany!");
    }

    const events = await res.json();

    return events.map((event: { eventId: number }) => event.eventId);
}
