<template>
  <div class="min-h-screen">
    <nav class="bg-gray-800 p-4 flex justify-between">
      <div class="text-2xl font-bold">Skunk Lounge</div>
      <div class="space-x-4">
        <span class="text-crypto-green">{{ user.name }} (VIP Level: {{ user.vip_level }})</span>
        <span v-if="user.is_kyc_verified" class="text-green-400">KYC Verified</span>
        <a href="/lobby" class="hover:text-crypto-green">Games</a>
        <a href="/profile" class="hover:text-crypto-green">Profile</a>
        <a href="/logout" class="hover:text-crypto-green">Logout</a>
      </div>
    </nav>
    <div class="p-6">
      <div v-if="success" class="bg-green-500 p-2 rounded mb-4">{{ success }}</div>
      <div v-if="error" class="bg-red-500 p-2 rounded mb-4">{{ error }}</div>
      <div class="bg-gray-800 rounded-lg p-4 mb-6 flex justify-between items-center">
        <span>Skunk Coins: {{ wallet.balance }}</span>
        <div class="flex space-x-4">
          <form @submit.prevent="addCoins">
            <input v-model="amount" type="number" class="bg-gray-700 p-2 rounded text-white" placeholder="Enter amount">
            <button type="submit" class="bg-crypto-green hover:bg-green-600 text-white px-4 py-2 rounded ml-2">Add Coins</button>
          </form>
          <form @submit.prevent="redeemPromo">
            <input v-model="promoCode" type="text" class="bg-gray-700 p-2 rounded text-white" placeholder="Promo code">
            <button type="submit" class="bg-crypto-green hover:bg-green-600 text-white px-4 py-2 rounded ml-2">Redeem</button>
          </form>
        </div>
      </div>
      <div class="bg-gray-800 rounded-lg p-4 mb-6">
        <h3 class="text-lg mb-2">Player Stats</h3>
        <p>Total Winnings: {{ stats.total_winnings }} Skunk Coins</p>
        <p>Total Bets: {{ stats.total_bets }} Skunk Coins</p>
        <p>Play Count: {{ stats.play_count }}</p>
        <p>Win Streak: {{ stats.win_streak }}</p>
      </div>
      <div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-6">
        <div v-for="game in games" :key="game.id" class="bg-gray-800 rounded-lg overflow-hidden transform hover:scale-105 transition game-card">
          <img :src="game.thumbnail_url" :alt="game.name" class="w-full h-48 object-cover">
          <div class="p-4">
            <h3 class="text-lg">{{ game.name }}</h3>
            <button class="bg-crypto-green hover:bg-green-600 text-white px-4 py-2 rounded mt-2">Play Now</button>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue';
import { useForm } from '@inertiajs/vue3'; // Use useForm for Inertia POST requests

defineProps({
  wallet: Object,
  games: Array,
  user: Object,
  stats: Object,
  success: String,
  error: String,
});

const depositForm = useForm({ amount: '' });
const promoForm = useForm({ code: '' });

const addCoins = () => {
  depositForm.post('/lobby/add-coins', {
    onSuccess: () => depositForm.reset(),
  });
};

const redeemPromo = () => {
  promoForm.post('/lobby/redeem-promo', {
    onSuccess: () => promoForm.reset(),
  });
};
</script>

<style scoped>
.game-card {
  @apply transition-all duration-300 hover:shadow-lg hover:shadow-crypto-green/50;
}
</style>