<script setup lang="ts">
import { ref, watch } from 'vue';

const props = defineProps<{
    show: boolean;
    delay: number; // Delay in milliseconds before the animation starts
}>();

const isVisible = ref(false);

watch(
    () => props.show,
    (newValue) => {
        if (newValue) {
            setTimeout(() => {
                isVisible.value = true;
            }, props.delay);
        } else {
            isVisible.value = false;
        }
    },
);
</script>

<template>
    <div v-if="isVisible" class="companion-container">
        <div class="animated-element">
            <svg
                class="w-32 h-32 text-[var(--subtle-gold)] animate-pulse"
                fill="none"
                stroke="currentColor"
                viewBox="0 0 24 24"
                xmlns="http://www.w3.org/2000/svg"
            >
                <path
                    d="M12 2L15.09 8.26L22 9.27L17 14.14L18.18 21.02L12 17.77L5.82 21.02L7 14.14L2 9.27L8.91 8.26L12 2Z"
                    stroke-linecap="round"
                    stroke-linejoin="round"
                    stroke-width="1.5"
                ></path>
            </svg>
        </div>
        <p class="companion-text">Votre lecture est prête...</p>
    </div>
</template>

<style scoped>
.companion-container {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    z-index: 20; /* Ensure it's on top of other elements */
    opacity: 0;
    animation: fadeInScale 0.8s ease-out forwards;
}

.animated-element {
    animation: float 2s ease-in-out infinite;
}

.companion-text {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--subtle-gold);
    animation: pulseText 2s ease-in-out infinite;
}

@keyframes fadeInScale {
    from {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.8);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}

@keyframes float {
    0%,
    100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-10px);
    }
}

@keyframes pulseText {
    0%,
    100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
}
</style>
