<template>
    <div class="min-h-screen bg-deep flex items-start justify-center p-4 pt-8 pb-16">
        <div class="w-full max-w-[940px]">
            <div class="bg-panel border border-border rounded-t flex items-center justify-between px-3 py-2">
                <div class="flex items-center gap-2">
                    <div class="w-2 h-2 rounded-full bg-accent"></div>
                    <span class="text-[11px] font-semibold uppercase tracking-[0.15em] text-value">Temporal Control</span>
                </div>
                <div class="flex items-center gap-2">
                    <button @click="terminateAll"
                            class="text-[10px] text-warn/70 hover:text-warn border border-warn/20 hover:border-warn/40 px-2 py-0.5 rounded-sm transition-all uppercase tracking-wider cursor-pointer">
                        Terminate All
                    </button>
                    <button @click="resetAll"
                            class="text-[10px] text-danger/70 hover:text-danger border border-danger/20 hover:border-danger/40 px-2 py-0.5 rounded-sm transition-all uppercase tracking-wider cursor-pointer">
                        Reset
                    </button>
                    <span class="text-border">|</span>
                    <a href="http://localhost:8080" target="_blank"
                       class="text-[10px] text-muted hover:text-accent transition-colors uppercase tracking-wider">
                        Open UI &rarr;
                    </a>
                </div>
            </div>

            <div class="bg-panel border-x border-b border-border rounded-b overflow-hidden">
                <slot />
            </div>
        </div>

        <LogModal ref="logModal" @close="onModalClose" />
    </div>
</template>

<script setup>
import { ref } from 'vue';
import { router } from '@inertiajs/vue3';
import LogModal from '../Components/LogModal.vue';

const logModal = ref(null);

function terminateAll() {
    logModal.value.start('/temporal/terminate-all', 'Terminate All');
}

function resetAll() {
    if (!confirm('This will wipe the database, terminate all workflows, and restart Temporal. Continue?')) return;
    logModal.value.start('/temporal/reset', 'Full Reset');
}

function onModalClose() {
    router.reload();
}
</script>
