<script setup lang="ts">
import { Head, useForm, Link as InertiaLink } from '@inertiajs/vue3';
import { route } from 'ziggy-js';
import AppLayout from '@/layouts/AppLayout.vue';

const props = defineProps<{
    dynamic: {
        id: number;
        name: string;
        rules: string;
    };
}>();

const form = useForm({
    name: props.dynamic.name,
    rules: props.dynamic.rules,
});

const breadcrumbs = [
    {
        name: 'Dynamics',
        href: route('dynamics.index'),
    },
    {
        name: props.dynamic.name,
        href: route('dynamics.show', props.dynamic.id),
    },
    {
        name: 'Settings',
        href: route('dynamics.edit', props.dynamic.id),
    },
];

function submit() {
    form.patch(route('dynamics.update', props.dynamic.id));
}
</script>

<template>
    <Head title="Dynamic Settings" />

    <div class="c-dynamic-settings">
        <div class="c-dynamic-settings__container">
            <div class="c-dynamic-settings__card">
                <div class="c-dynamic-settings__body">
                    <h3 class="c-dynamic-settings__title">Dynamic Settings</h3>

                    <form @submit.prevent="submit" class="c-dynamic-settings__form">
                        <div class="c-dynamic-settings__field">
                            <label for="name" class="c-dynamic-settings__label">Name</label>
                            <input v-model="form.name" id="name" type="text" class="c-dynamic-settings__input" />
                            <div v-if="form.errors.name" class="c-dynamic-settings__error">
                                {{ form.errors.name }}
                            </div>
                        </div>

                        <div class="c-dynamic-settings__field">
                            <label for="rules" class="c-dynamic-settings__label">Rules</label>
                            <textarea v-model="form.rules" id="rules" rows="4" class="c-dynamic-settings__textarea"></textarea>
                            <div v-if="form.errors.rules" class="c-dynamic-settings__error">
                                {{ form.errors.rules }}
                            </div>
                        </div>

                        <div class="c-dynamic-settings__actions">
                            <button type="submit" :disabled="form.processing" class="c-dynamic-settings__submit-btn">
                                Save
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</template>

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

.c-dynamic-settings {
    @apply py-12;
}

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

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

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

.c-dynamic-settings__title {
    @apply text-lg font-medium;
}

.c-dynamic-settings__form {
    @apply mt-6 space-y-6;
}

.c-dynamic-settings__field {
    @apply block;
}

.c-dynamic-settings__label {
    @apply block text-sm font-medium text-gray-700 dark:text-gray-300;
}

.c-dynamic-settings__input {
    @apply mt-1 block w-full rounded-md border border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300 dark:focus:border-indigo-600 dark:focus:ring-indigo-600;
}

.c-dynamic-settings__textarea {
    @apply mt-1 block w-full rounded-md border border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300 dark:focus:border-indigo-600 dark:focus:ring-indigo-600;
}

.c-dynamic-settings__error {
    @apply text-sm text-red-600;
}

.c-dynamic-settings__actions {
    @apply flex items-center gap-4;
}

.c-dynamic-settings__submit-btn {
    @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;
}
</style>
