<script setup>

import ShadowedBox from "../../../../Views/Components/ShadowedBox.vue";

const props = defineProps({
    events: Array,
})

console.log(props.events)
</script>

<template>
    <div style="width: 95%; margin: 20px auto;">

        <div v-if="props.events.length === 0" style="text-align: center; color: #6b7280; padding: 40px 0;">
            Aktuell sind keine Veranstaltungen verfügbar.
        </div>

        <shadowed-box
            v-for="event in props.events"
            :key="event.id"
            style="padding: 24px; margin-bottom: 20px;"
        >
            <div style="display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: 12px;">
                <div>
                    <h2 style="margin: 0 0 4px 0; font-size: 1.25rem;">{{ event.name }}</h2>
                    <span style="color: #6b7280; font-size: 0.9rem;">{{ event.postalCode }} {{ event.location }}</span>
                </div>
                <span
                    v-if="event.registrationAllowed"
                    style="background: #d1fae5; color: #065f46; padding: 4px 12px; border-radius: 999px; font-size: 0.8rem; font-weight: 600; white-space: nowrap;"
                >
                        Anmeldung offen
                    </span>
                <span
                    v-else
                    style="background: #fee2e2; color: #991b1b; padding: 4px 12px; border-radius: 999px; font-size: 0.8rem; font-weight: 600; white-space: nowrap;"
                >
                        Anmeldung geschlossen
                    </span>
            </div>

            <hr style="margin: 16px 0; border: none; border-top: 1px solid #e5e7eb;" />

            <table style="width: 100%; border-collapse: collapse;">
                <tr>
                    <th style="text-align: left; padding: 6px 12px 6px 0; width: 220px; color: #374151; font-weight: 600;">Zeitraum</th>
                    <td style="padding: 6px 0; color: #111827;">{{ event.eventBegin }} – {{ event.eventEnd }} ({{ event.duration }} Tage)</td>
                </tr>
                <tr>
                    <th style="text-align: left; padding: 6px 12px 6px 0; width: 220px; color: #374151; font-weight: 600;">Veranstaltungsort</th>
                    <td style="padding: 6px 0; color: #111827;">{{ event.postalCode }} {{ event.location }}</td>
                </tr>
                <tr>
                    <th style="text-align: left; padding: 6px 12px 6px 0; color: #374151; font-weight: 600;">Frühbuchen bis</th>
                    <td style="padding: 6px 0; color: #111827;">{{ event.earlyBirdEnd.formatted }}</td>
                </tr>
                <tr>
                    <th style="text-align: left; padding: 6px 12px 6px 0; color: #374151; font-weight: 600;">Anmeldeschluss</th>
                    <td style="padding: 6px 0; color: #111827;">{{ event.registrationFinalEnd.formatted }}</td>
                </tr>
                <tr v-if="event.email">
                    <th style="text-align: left; padding: 6px 12px 6px 0; color: #374151; font-weight: 600;">Kontakt</th>
                    <td style="padding: 6px 0;">
                        <a :href="'mailto:' + event.email" style="color: #2563eb;">{{ event.email }}</a>
                    </td>
                </tr>
            </table>

            <div style="margin-top: 20px; display: flex; justify-content: flex-end;">
                <a
                    :href="'/event/' + event.identifier + '/signup'"
                    style="
                            display: inline-block;
                            padding: 10px 24px;
                            background-color: #2563eb;
                            color: white;
                            border-radius: 8px;
                            text-decoration: none;
                            font-weight: 600;
                            font-size: 0.95rem;
                            opacity: 1;
                            transition: background-color 0.2s;
                        "
                    :style="{ opacity: event.registrationAllowed ? '1' : '0.5', pointerEvents: event.registrationAllowed ? 'auto' : 'none' }"
                >
                    Zur Anmeldung →
                </a>
            </div>
        </shadowed-box>

    </div><div style="width: 95%; margin: 20px auto;">

    <div v-if="props.events.length === 0" style="text-align: center; color: #6b7280; padding: 40px 0;">
        Aktuell sind keine Veranstaltungen verfügbar.
    </div>
</div>
</template>

<style scoped>

</style>
