<template>
  <q-layout view="hHh lpR fFf">
    <q-header class="bg-dark text-black">
      <q-toolbar class="sd-page-padding bg-white">
        <!-- Logo -->
        <img src="~assets/images/logo.png" alt="logo"
          style="position: absolute; left: 4%; top: 50%; transform: translateY(-50%); width: 170px; height: 44px;" />
        <q-btn flat no-caps class="text-black" style="height: 100px;" @click="$router.push('/target-page')">
          <span>主站</span>
        </q-btn>
        <div class="row items-center no-wrap">
          <q-btn-dropdown :transition-duration="0" :menu-offset="[0, -8]" flat no-caps class="text-black"
            style="height: 100px;" @mouseenter="$refs.gamesDropdown.show()" ref="gamesDropdown">
            <template v-slot:label>
              <span class="">游戏游戏</span>
            </template>
            <q-list @mouseenter="$refs.gamesDropdown.show()" @mouseleave="$refs.gamesDropdown.hide()">
              <q-item clickable v-close-popup to="/games">
                <q-item-section>All Games</q-item-section>
              </q-item>
              <q-item clickable v-close-popup to="/blog">
                <q-item-section>Blog</q-item-section>
              </q-item>
              <q-item clickable v-close-popup to="/help">
                <q-item-section>Help Center</q-item-section>
              </q-item>
            </q-list>
          </q-btn-dropdown>
          <q-btn flat no-caps class="text-black" style="height: 100px;" @click="$router.push('/target-page')">
            <span>博客</span>
          </q-btn>
        </div>
        <q-space />
        <div class="row items-center no-wrap q-gutter-md">
          <!-- Search -->
          <q-input v-model="searchText" placeholder="搜索游戏..." dense outlined style="width: 300px;"
            class="rounded-borders">
            <template v-slot:prepend>
              <q-icon name="search" />
            </template>
            <template v-slot:append>
              <q-btn flat round dense icon="close" v-if="searchText" @click="searchText = ''" />
            </template>
          </q-input>

          <!-- Cart -->
          <q-btn flat round class="bg-grey-3 rounded-borders">
            <q-icon name="shopping_cart" />
            <q-badge color="red" floating>1</q-badge>
          </q-btn>

          <!-- Language/Currency -->
          <q-btn flat @click="showLanguageDialog = true" class="bg-grey-3 rounded-borders text-black q-px-md q-py-sm">
            $ {{ selectedCurrency }} | {{ selectedLanguage }}
          </q-btn>

          <!-- Language Selection Dialog -->
          <q-dialog v-model="showLanguageDialog">
            <q-card style="min-width: 300px;">
              <q-card-section>
                <div class="text-h6">选择语言和货币</div>
              </q-card-section>

              <q-card-section>
                <div class="q-mb-md">
                  <div class="text-subtitle2 q-mb-sm">语言</div>
                  <q-select v-model="selectedLanguage" :options="languageOptions" emit-value map-options outlined
                    dense />
                </div>

                <div>
                  <div class="text-subtitle2 q-mb-sm">货币</div>
                  <q-select v-model="selectedCurrency" :options="currencyOptions" emit-value map-options outlined
                    dense />
                </div>
              </q-card-section>

              <q-card-actions align="right">
                <q-btn flat label="取消" color="grey" @click="showLanguageDialog = false" />
                <q-btn flat label="确定" color="primary" @click="confirmSelection" />
              </q-card-actions>
            </q-card>
          </q-dialog>

          <!-- User Profile -->
          <q-avatar class="bg-grey-3 rounded-borders" size="40px">
            <q-icon name="account_circle" size="32px" />
          </q-avatar>
        </div>
      </q-toolbar>
    </q-header>

    <q-page-container>
      <template v-if="$q.platform.is.mobile">
        <router-view v-slot="{ Component }">
          <transition appear enter-active-class="animated fadeIn" leave-active-class="animated fadeOut" mode="out-in">
            <component :is="Component" :key="$route.path" />
          </transition>
        </router-view>
        <!-- 移动端页脚 -->
        <q-footer class="bg-white text-black border-top">
          <q-toolbar class="q-pa-md">
            <div class="row items-center justify-around full-width">
              <q-btn flat class="col text-center" to="/">
                <div class="column items-center">
                  <q-icon name="home" size="24px" />
                  <div class="text-caption q-mt-xs">首页</div>
                </div>
              </q-btn>
              <q-btn flat class="col text-center" to="/games">
                <div class="column items-center">
                  <q-icon name="sports_esports" size="24px" />
                  <div class="text-caption q-mt-xs">游戏</div>
                </div>
              </q-btn>
              <q-btn flat class="col text-center">
                <div class="column items-center">
                  <q-icon name="shopping_cart" size="24px" />
                  <q-badge color="red" floating>1</q-badge>
                  <div class="text-caption q-mt-xs">购物车</div>
                </div>
              </q-btn>
              <q-btn flat class="col text-center" to="/help">
                <div class="column items-center">
                  <q-icon name="help" size="24px" />
                  <div class="text-caption q-mt-xs">帮助</div>
                </div>
              </q-btn>
              <q-btn flat class="col text-center">
                <div class="column items-center">
                  <q-icon name="account_circle" size="24px" />
                  <div class="text-caption q-mt-xs">我的</div>
                </div>
              </q-btn>
            </div>
          </q-toolbar>
        </q-footer>
      </template>
      <template v-else>
        <CustomScrollContainer height="calc(100vh - 100px)" :top-offset="100">
          <router-view v-slot="{ Component }">
            <transition appear enter-active-class="animated fadeIn" leave-active-class="animated fadeOut" mode="out-in">
              <component :is="Component" :key="$route.path" />
            </transition>
          </router-view>
        </CustomScrollContainer>
      </template>
    </q-page-container>

  </q-layout>
</template>

<script setup>
import { ref } from 'vue'
import CustomScrollContainer from 'src/components/CustomScrollContainer.vue'

// 搜索文本
const searchText = ref('')

// 语言选择相关
const showLanguageDialog = ref(false)
const selectedLanguage = ref('EN')
const selectedCurrency = ref('USD')

// 语言选项
const languageOptions = [
  { label: 'English', value: 'EN' },
  { label: '中文', value: 'CN' },
  { label: '日本語', value: 'JP' },
  { label: '한국어', value: 'KR' }
]

// 货币选项
const currencyOptions = [
  { label: 'USD - 美元', value: 'USD' },
  { label: 'CNY - 人民币', value: 'CNY' },
  { label: 'JPY - 日元', value: 'JPY' },
  { label: 'KRW - 韩元', value: 'KRW' },
  { label: 'EUR - 欧元', value: 'EUR' }
]

// 确认选择
const confirmSelection = () => {
  showLanguageDialog.value = false
  // 这里可以添加保存用户选择的逻辑，比如保存到本地存储或发送到服务器
  console.log('Selected Language:', selectedLanguage.value)
  console.log('Selected Currency:', selectedCurrency.value)
}
</script>

<style scoped></style>
