KSA-ORACLE/resources/js/components/organism/ShuffleCard/ShuffleCardPresentation.vue
2025-09-17 14:41:20 +03:00

584 lines
18 KiB
Vue

<script setup lang="ts">
import CardShuffleTemplate from '@/components/template/CardShuffleTemplate.vue';
import { Card } from '@/types/cart';
import { router } from '@inertiajs/vue3';
import { ref, watchEffect, computed } from 'vue';
const props = defineProps<{
drawCount?: number; // Optional: number of cards expected to be drawn
drawnCards?: Card[]; // Cards provided by the parent at start
clientSessionId?: string;
}>();
defineEmits(['drawCard']);
// Deck / animation state
const deckSize = 10; // spread ~10 cards as requested
const isSpread = ref(false);
const isDrawing = ref(false);
const drawingIndex = ref<number | null>(null);
const revealedCards = ref<Card[]>([]);
const isFlipped = ref<boolean[]>([]);
const remainingDeckSize = computed(() => Math.max(0, deckSize - revealedCards.value.length));
const startDraw = (index: number) => {
if (!props.drawnCards || revealedCards.value.length >= props.drawnCards.length) return;
isDrawing.value = true;
drawingIndex.value = index;
const DRAW_DURATION = 800; // keep in sync with CSS transition timing
setTimeout(() => {
const nextCard = props.drawnCards![revealedCards.value.length];
if (nextCard) {
revealedCards.value.push(nextCard);
isFlipped.value.push(false);
}
// Restack after drawing
isSpread.value = false;
drawingIndex.value = null;
isDrawing.value = false;
}, DRAW_DURATION);
};
const handleDeckClick = () => {
if (isDrawing.value) return;
// First click spreads the deck
if (!isSpread.value) {
isSpread.value = true;
return;
}
// If already spread, clicking deck auto-draws the middle card
if (props.drawnCards && revealedCards.value.length < props.drawnCards.length) {
const middleIndex = Math.ceil(remainingDeckSize.value / 2);
startDraw(middleIndex);
} else {
// No cards left to draw, just restack
isSpread.value = false;
}
};
const onCardClick = (i: number, e?: MouseEvent) => {
// Only handle and stop propagation when spread; otherwise let the deck click handler spread the deck
if (!isSpread.value || isDrawing.value) return;
if (e) e.stopPropagation();
if (!props.drawnCards || revealedCards.value.length >= props.drawnCards.length) return;
startDraw(i);
};
const getCardStyle = (i: number) => {
if (drawingIndex.value === i) {
return {
transform: 'translateY(-220px) scale(1.05)',
zIndex: '100',
} as const;
}
if (isSpread.value) {
const mid = (remainingDeckSize.value + 1) / 2;
const offset = i - mid; // negative to left, positive to right
const x = offset * 40; // horizontal spacing
const rot = offset * 6; // slight fan rotation
return {
transform: `translateX(${x}px) rotate(${rot}deg)`,
zIndex: `${50 - Math.abs(offset)}`,
} as const;
}
// Stacked view with subtle 3D depth
return {
transform: `rotate(${-3 + i}deg) translateZ(-${10 * i}px)`,
} as const;
};
const flipCard = (index: number) => {
isFlipped.value[index] = !isFlipped.value[index];
};
// Reset local animation state whenever given cards change
watchEffect(() => {
if (props.drawnCards && props.drawnCards.length > 0) {
isSpread.value = false;
isDrawing.value = false;
drawingIndex.value = null;
revealedCards.value = [];
isFlipped.value = [];
} else {
isSpread.value = false;
isDrawing.value = false;
drawingIndex.value = null;
revealedCards.value = [];
isFlipped.value = [];
}
});
const goToSelection = () => {
router.visit('/tirage');
};
const goToResult = () => {
if (props.clientSessionId) {
router.visit(`/resultat?client_session_id=${props.clientSessionId}`);
} else {
router.visit(`/resultat-gratuit?id=${props.drawnCards ? props.drawnCards[0].id : ''}`);
}
};
// Backward compatibility if a parent calls this method directly
const setDrawnCards = (cardData: Card[]) => {
if (cardData && cardData.length) {
isSpread.value = false;
isDrawing.value = false;
drawingIndex.value = null;
revealedCards.value = [];
isFlipped.value = new Array(cardData.length).fill(false);
}
};
defineExpose({ setDrawnCards });
</script>
<template>
<CardShuffleTemplate>
<template #card-shuffle-slot>
<div class="card-container">
<!-- Always show the card stack -->
<transition class="card-stack-fade">
<div
class="card-stack relative mt-4 mb-4 flex h-[500px] w-[300px] items-center justify-center"
:class="{ spread: isSpread, drawing: isDrawing }"
@click="handleDeckClick"
v-show="!drawnCards || revealedCards.length < drawnCards.length"
>
<div
v-for="i in remainingDeckSize"
:key="i"
class="card"
:style="getCardStyle(i)"
@click="onCardClick(i, $event)"
>
<div class="card-back">
<div class="card-inner-content">
<img src="cards/1.png" alt="Card Back" class="card-back-image" />
</div>
</div>
</div>
</div>
</transition>
<!-- Show result only after clicking and when drawnCards is available -->
<transition class="card-result-slide">
<div v-if="revealedCards.length > 0" class="cards-result-container">
<div v-for="(card, index) in revealedCards" :key="index" class="card-result-wrapper">
<div class="result-card" :class="{ flipped: isFlipped[index] }" @click="flipCard(index)">
<div class="card-face card-unknown-front">
<div class="card-inner-content">
<img src="cards/1.png" alt="Card Back" class="card-back-image" />
</div>
</div>
<div class="card-face card-known-back">
<img :src="`/cards/${card.id + 1}.png`" :alt="card.name" class="card-image" />
<div class="card-description-overlay">
<h3>{{ card.name }}</h3>
</div>
</div>
</div>
</div>
</div>
</transition>
<button
@click="goToSelection"
class="mt-8 flex h-12 max-w-[480px] min-w-[200px] cursor-pointer items-center justify-center overflow-hidden rounded-full bg-[var(--midnight-blue)] px-8 text-base font-bold tracking-wide text-[var(--pure-white)] transition-all duration-300 hover:bg-[var(--spiritual-earth)] hover:shadow-[var(--spiritual-earth)]/30 hover:shadow-lg disabled:cursor-not-allowed disabled:bg-gray-400 disabled:hover:shadow-none"
>
<span class="truncate">Retourner à la sélection des cartes</span>
</button>
<button
@click="goToResult"
class="mt-8 flex h-12 max-w-[480px] min-w-[200px] cursor-pointer items-center justify-center overflow-hidden rounded-full bg-[var(--midnight-blue)] px-8 text-base font-bold tracking-wide text-[var(--pure-white)] transition-all duration-300 hover:bg-[var(--spiritual-earth)] hover:shadow-[var(--spiritual-earth)]/30 hover:shadow-lg disabled:cursor-not-allowed disabled:bg-gray-400 disabled:hover:shadow-none"
>
<span class="truncate">Resultat du tirage</span>
</button>
</div>
</template>
</CardShuffleTemplate>
</template>
<style scoped>
.card-container {
display: flex;
flex-direction: column;
align-items: center;
}
.card {
width: 250px;
height: 400px;
background: linear-gradient(145deg, var(--pure-white), var(--linen));
border-radius: 16px;
box-shadow:
0 10px 20px rgba(0, 0, 0, 0.1),
0 6px 6px rgba(0, 0, 0, 0.1);
position: absolute;
transition:
transform 0.5s ease-in-out,
box-shadow 0.5s ease-in-out;
cursor: pointer;
transform-style: preserve-3d;
backface-visibility: hidden;
}
/* Animation stack globale */
.card-stack {
transition: transform 0.6s ease-in-out;
display: flex;
align-items: center;
justify-content: center;
perspective: 1000px; /* ajoute profondeur */
}
/* Hover sur la pile */
.card-stack:not(.spread):hover {
transform: translateY(-10px) rotateX(2deg) rotateY(-2deg);
}
.card-stack:not(.spread):hover .card:nth-child(1) {
transform: rotateY(-5deg) rotateX(5deg) translateZ(30px) translateX(-20px);
}
.card-stack:not(.spread):hover .card:nth-child(2) {
transform: rotateY(0deg) rotateX(2deg) translateZ(20px);
}
.card-stack:not(.spread):hover .card:nth-child(3) {
transform: rotateY(5deg) rotateX(5deg) translateZ(10px) translateX(20px);
}
/* Glow doré subtil au hover */
.card-stack:hover .card-back {
box-shadow: 0 0 20px rgba(215, 186, 141, 0.6);
transition: box-shadow 0.6s ease-in-out;
}
/* Animation click */
@keyframes card-click-tilt {
0% {
transform: translateY(-10px) rotateX(2deg) rotateY(-2deg);
}
30% {
transform: translateY(-5px) rotateX(-4deg) rotateY(4deg);
}
60% {
transform: translateY(-12px) rotateX(3deg) rotateY(-3deg);
}
100% {
transform: translateY(-10px) rotateX(2deg) rotateY(-2deg);
}
}
/* Drawing animation */
@keyframes card-drawing {
0% {
transform: translateY(-10px) rotateX(2deg) rotateY(-2deg);
}
25% {
transform: translateY(-30px) rotateX(10deg) rotateY(-10deg);
}
50% {
transform: translateY(-40px) rotateX(-5deg) rotateY(5deg);
}
75% {
transform: translateY(-30px) rotateX(5deg) rotateY(-5deg);
}
100% {
transform: translateY(-10px) rotateX(2deg) rotateY(-2deg);
}
}
/* Active sur clic */
.card-stack.clicked {
animation: card-click-tilt 0.4s ease-in-out;
}
.card-stack.drawing {
animation: card-drawing 1.5s ease-in-out;
}
/* Back des cartes */
.card-back {
position: absolute;
width: 100%;
height: 100%;
backface-visibility: hidden;
border-radius: 16px;
display: flex; /* Keep flexbox for centering if needed */
align-items: center; /* For centering .card-inner-content if it's smaller */
justify-content: center; /* For centering .card-inner-content if it's smaller */
background-color: var(--subtle-gold);
}
.card-inner-content {
width: calc(100% - 10px); /* Adjust 10px to control border thickness (e.g., 5px border on each side) */
height: calc(100% - 10px); /* Adjust this value as well */
background-color: white; /* Or whatever color you want inside the gold border */
border-radius: 14px; /* Slightly smaller to match outer radius with padding */
display: flex; /* Use flex to center the image if it's an <img> tag */
align-items: center;
justify-content: center;
overflow: hidden; /* Ensure image doesn't bleed out */
}
.card-back-image {
width: 100%;
height: 100%;
object-fit: cover; /* Or 'cover' depending on how you want the image to fill the inner content */
border-radius: 14px; /* Match inner content border-radius */
}
.card-result-wrapper {
width: 250px;
height: 400px;
perspective: 1000px;
}
.card-back-design-wrapper {
background: radial-gradient(circle, var(--midnight-blue) 0%, #121a2c 100%);
display: flex;
align-items: center;
justify-content: center;
}
.card-back-design {
width: 80%;
height: 80%;
border: 2px solid var(--subtle-gold);
border-radius: 8px;
position: relative;
display: flex;
align-items: center;
justify-content: center;
}
.card-back-design::before,
.card-back-design::after {
content: '';
position: absolute;
width: 50%;
height: 50%;
border-color: var(--subtle-gold);
opacity: 0.5;
}
.card-face {
position: absolute;
width: 100%;
height: 100%;
backface-visibility: hidden; /* This is crucial for the flip effect */
border-radius: 16px;
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
overflow: hidden; /* To keep content within borders */
}
.card-unknown-front {
background-color: var(--subtle-gold);
display: flex; /* Keep flexbox for centering its *own* content */
align-items: center;
justify-content: center;
}
.card-known-back {
background-color: var(--subtle-gold);
display: flex;
justify-content: center;
align-items: center;
transform: rotateY(180deg); /* This face starts rotated, so it's hidden */
position: relative;
border-radius: 16px; /* Ensure this matches the outer card radius */
overflow: hidden;
}
.card-back-design::before {
top: -2px;
left: -2px;
border-top-width: 1px;
border-left-width: 1px;
border-top-style: solid;
border-left-style: solid;
border-top-left-radius: 8px;
}
.card-back-design::after {
bottom: -2px;
right: -2px;
border-bottom-width: 1px;
border-right-width: 1px;
border-bottom-style: solid;
border-right-style: solid;
border-bottom-right-radius: 8px;
}
/* Result card styles */
.cards-result-container {
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 20px;
margin-top: 2rem;
position: relative;
z-index: 10;
}
.card-result-container {
perspective: 1000px;
}
.result-card {
width: 100%;
height: 100%;
position: relative;
transform-style: preserve-3d;
transition: transform 0.8s;
cursor: pointer;
}
.result-card.flipped {
transform: rotateY(180deg);
}
.card-front,
.card-back-info {
position: absolute;
width: 100%;
height: 100%;
backface-visibility: hidden;
border-radius: 16px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 1rem;
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
text-align: center;
overflow-y: auto;
}
.card-back-info p {
color: var(--midnight-blue); /* Adjust color if needed */
}
.card-front {
background: linear-gradient(145deg, var(--pure-white), var(--linen));
color: var(--midnight-blue);
}
.card-back-info {
/* Replace the existing background property */
background-image: url('back-card.svg'); /* background-size: cover; /* This makes the image cover the entire element */
background-position: center; /* This centers the image in the element */
background-repeat: no-repeat; /* This prevents the image from repeating */
color: var(--pure-white);
transform: rotateY(180deg);
text-align: center;
overflow-y: auto;
}
.card-content-wrapper {
background: linear-gradient(145deg, var(--pure-white), var(--linen));
color: var(--midnight-blue);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 1rem;
transform: rotateY(180deg); /* This is the key part to make it the 'back' of the card */
}
.card-image {
width: 100%;
height: 100%;
object-fit: cover;
border-radius: 16px;
position: absolute;
top: 0;
left: 0;
}
.card-description-overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
/* Adjust background for a brighter, more subtle overlay */
background: rgba(255, 255, 255, 0.2); /* Lighter, more transparent white overlay */
/* You could also use a subtle gradient if you prefer: */
/* background: linear-gradient(to top, rgba(0,0,0,0.5) 0%, rgba(255,255,255,0) 50%); */
color: white; /* Keep text white for contrast */
padding: 1rem;
/* Center the content (just the name) in the middle of the card */
display: flex;
flex-direction: column;
justify-content: center; /* Center vertically */
align-items: center; /* Center horizontally */
text-align: center;
box-sizing: border-box;
pointer-events: none; /* Make overlay non-interactive so clicks go through to flip */
}
.card-description-overlay h3 {
margin: 0; /* Remove default margin */
font-size: 1.8rem; /* Make the name larger */
font-weight: bold;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.7); /* Add subtle shadow for readability */
color: var(--pure-white); /* Ensure it's clearly white */
letter-spacing: 1px; /* Add some letter spacing */
}
/* Hide these elements completely */
.card-description-overlay p.description,
.card-description-overlay p.orientation,
.card-description-overlay div.symbolism {
display: none;
}
.orientation {
font-style: italic;
margin-top: 0.5rem;
color: var(--spiritual-earth);
}
.description {
margin: 1rem 0;
font-size: 0.9rem;
}
.symbolism {
margin-top: 1rem;
font-size: 0.8rem;
}
.symbolism p {
margin: 0.3rem 0;
}
.click-hint {
margin-top: 1rem;
font-size: 0.7rem;
opacity: 0.7;
}
.card-stack-fade-leave-active {
transition: all 0.8s ease;
}
.card-stack-fade-leave-to {
opacity: 0;
transform: translateY(-50px) scale(0.9);
}
.cards-result-slide-enter-active {
transition: all 0.8s ease;
transition-delay: 0.3s;
}
.cards-result-slide-enter-from {
opacity: 0;
transform: translateY(50px);
}
</style>