<template>
    <div class="eira-bubble d-flex align-items-center justify-content-center position-fixed" :class="{ playing: isPlaying, mobile: isMobile }" @click="togglePlay" title="Play/Pause briefing audio">
        <img src="@/assets/eira-avatar.png" alt="Eira" class="eira-avatar rounded-circle" />
        <div class="play-overlay d-flex align-items-center justify-content-center">
            <span v-if="!isPlaying">
                <CirclePlay class="icon" :size="isMobile ? 18 : 36" />
            </span>
            <span v-else>
                <CirclePause class="icon" :size="isMobile ? 18 : 36" />
            </span>
        </div>
        <audio ref="audioPlayer" :src="audioUrl" @ended="onAudioEnded" />
    </div>
</template>
<script>
import { CirclePlay, CirclePause } from 'lucide-vue-next';
import { isMobileOnly } from 'mobile-device-detect';

export default {
    name: "EiraBubble",
    components: {
        CirclePlay,
        CirclePause
    },
    props: {
        audioUrl: {
            type: String,
            required: true,
        },
    },
    data() {
        return {
            isPlaying: false,
            isMobile: isMobileOnly,
        };
    },
    methods: {
        togglePlay() {
            const audio = this.$refs.audioPlayer;
            if (!audio) return;
            if (this.isPlaying) {
                audio.pause();
            } else {
                audio.play();
            }
            this.isPlaying = !this.isPlaying;
        },
        onAudioEnded() {
            this.isPlaying = false;
        },
    },
};
</script>
<style scoped>
.icon {
    stroke-width: 1.3px;
}

.eira-bubble {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 144px;
    height: 144px;
    background-color: #f6f4ff;
    border-radius: 20px;
    box-shadow: 0 0 12px rgba(155, 109, 255, 0.3);
    cursor: pointer;
    z-index: 9999;
    user-select: none;
    transition: box-shadow 0.3s ease;
}

.eira-bubble.mobile {
    width: 72px;
    height: 72px;
    bottom: 20px;
    right: 20px;
    border-radius: 12px;
}

.eira-avatar {
    width: 112px;
    height: 112px;
    filter: drop-shadow(0 0 5px rgba(155, 109, 255, 0.7));
    pointer-events: none;
    user-select: none;
    position: relative;
}

.eira-bubble.mobile .eira-avatar {
    width: 56px;
    height: 56px;
}

.play-overlay {
    position: absolute;
    bottom: 8px;
    right: 8px;
    width: 44px;
    height: 44px;
    background-color: #6b46c1;
    border-radius: 50%;
    color: white;
    font-size: 28px;
    line-height: 44px;
    text-align: center;
    font-weight: bold;
    box-shadow: 0 0 6px rgba(155, 109, 255, 0.8);
    pointer-events: none;
    user-select: none;
}

.eira-bubble.mobile .play-overlay {
    width: 24px;
    height: 24px;
    bottom: 4px;
    right: 4px;
    font-size: 14px;
    line-height: 24px;
}


@keyframes pulseGlow {

    0%,
    100% {
        box-shadow: 0 0 12px 4px #9b6dff;
    }

    50% {
        box-shadow: 0 0 20px 8px #d2cbff;
    }
}
</style>