<script setup lang="ts">
import { Head, Link } from '@inertiajs/vue3';
import { route } from 'ziggy-js';

defineOptions({
    layout: {
        breadcrumbs: [
            {
                title: 'Dynamics',
                href: route('dynamics.index'),
            },
        ],
    },
});

defineProps<{
    dynamics: Array<{
        id: string;
        name: string;
        rules: string;
    }>;
}>();
</script>

<template>
    <Head title="Dynamics" />

    <div class="c-dynamics-index">
        <div class="c-dynamics-index__container">
            <div class="c-dynamics-index__card">
                <div class="c-dynamics-index__body">
                    <div class="c-dynamics-index__header">
                        <h3 class="c-dynamics-index__title">Your Dynamics</h3>
                        <Link
                            :href="route('dynamics.create')"
                            class="c-dynamics-index__button"
                        >
                            Create Dynamic
                        </Link>
                    </div>

                    <div
                        v-if="dynamics.length > 0"
                        class="c-dynamics-index__grid"
                    >
                        <div
                            v-for="dynamic in dynamics"
                            :key="dynamic.id"
                            class="c-dynamics-index__item"
                        >
                            <Link :href="route('dynamics.show', dynamic.id)">
                                <h4 class="c-dynamics-index__item-title">
                                    {{ dynamic.name }}
                                </h4>
                            </Link>
                            <p class="c-dynamics-index__item-desc">
                                {{ dynamic.rules }}
                            </p>
                        </div>
                    </div>
                    <div v-else>
                        <p class="c-dynamics-index__empty">
                            You don't have any dynamics yet.
                        </p>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<style scoped>
@reference "../../../css/app.css";

.c-dynamics-index {
    @apply py-12;
}

.c-dynamics-index__container {
    @apply mx-auto max-w-7xl sm:px-6 lg:px-8;
}

.c-dynamics-index__card {
    @apply overflow-hidden bg-white shadow-sm sm:rounded-lg dark:bg-gray-800;
}

.c-dynamics-index__body {
    @apply p-6 text-gray-900 dark:text-gray-100;
}

.c-dynamics-index__header {
    @apply mb-6 flex items-center justify-between;
}

.c-dynamics-index__title {
    @apply text-lg font-medium;
}

.c-dynamics-index__button {
    @apply inline-flex items-center rounded-md border border-transparent bg-gray-800 px-4 py-2 text-xs font-semibold tracking-widest text-white uppercase transition duration-150 ease-in-out hover:bg-gray-700 focus:bg-gray-700 focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 focus:outline-none active:bg-gray-900 dark:bg-gray-200 dark:text-gray-800 dark:hover:bg-white dark:focus:bg-white dark:focus:ring-offset-gray-800 dark:active:bg-gray-300;
}

.c-dynamics-index__grid {
    @apply grid grid-cols-1 gap-6 md:grid-cols-2 lg:grid-cols-3;
}

.c-dynamics-index__item {
    @apply border-b border-gray-200 bg-white p-6 dark:border-gray-600 dark:bg-gray-700;
}

.c-dynamics-index__item-title {
    @apply text-lg font-semibold;
}

.c-dynamics-index__item-desc {
    @apply mt-2 text-sm text-gray-600 dark:text-gray-400;
    white-space: pre-line;
}

.c-dynamics-index__empty {
    @apply text-gray-500 dark:text-gray-400;
}
</style>
