<template>
  <div class="row items-center justify-between">
    <!-- Payment Methods -->
    <div class="col">
      <div class="payment-methods-scroll-container">
        <div class="payment-methods-list">
          <!-- 复制支付方式数组以实现无缝滚动 -->
          <div v-for="(method, index) in [...paymentMethods, ...paymentMethods, ...paymentMethods]"
            :key="`${method.id}-${index}`" class="payment-method-item">
            <q-img :src="method.icon" :alt="method.name" class="payment-method-icon" fit="contain" />
          </div>
        </div>
      </div>
    </div>

    <!-- Language Selection -->
    <div class="col-auto">
      <q-btn flat no-caps @click="showLanguageDialog = true" class="text-body1 text-grey-7 hover-text-primary">
        <q-icon name="language" class="q-mr-xs" />
        {{ selectedLanguage.nativeName }}
        <q-icon name="keyboard_arrow_down" class="arrow-icon q-ml-xs" :class="{ 'rotate-180': showLanguageDialog }" />
      </q-btn>
    </div>
  </div>

  <footer class="text-grey-9 q-py-lg">
    <div class="row q-gutter-md">
      <!-- Product Category Section -->
      <div class="col-12 col-md">
        <div class="text-h6 text-weight-medium q-mb-md">Product Category</div>
        <div class="column q-gutter-y-sm">
          <a href="#" class="text-grey-9 text-decoration-none hover-white">Hot Sale</a>
          <a href="#" class="text-grey-9 text-decoration-none hover-white">Mobile Games</a>
          <a href="#" class="text-grey-9 text-decoration-none hover-white">PC Games</a>
        </div>
      </div>

      <!-- Corporate Information Section -->
      <div class="col-12 col-md">
        <div class="text-h6 text-weight-medium q-mb-md">Corporate Information</div>
        <div class="column q-gutter-y-sm">
          <a href="#" class="text-grey-9 text-decoration-none hover-white">About Us</a>
          <a href="#" class="text-grey-9 text-decoration-none hover-white">Contact Us</a>
          <a href="#" class="text-grey-9 text-decoration-none hover-white">News and Announcements</a>
        </div>
      </div>

      <!-- Social Account Section -->
      <div class="col-12 col-md">
        <div class="text-h6 text-weight-medium q-mb-md">Social Account</div>
        <div class="column q-gutter-y-sm">
          <a href="#" class="text-grey-9 text-decoration-none">Line</a>
          <a href="#" class="text-grey-9 text-decoration-none">Discord</a>
          <a href="#" class="text-grey-9 text-decoration-none">WhatsApp</a>
        </div>
      </div>
    </div>
  </footer>

  <!-- 语言选择对话框 -->
  <q-dialog v-model="showLanguageDialog">
    <q-card style="min-width: 350px">
      <q-card-section>
        <div class="text-h6">選擇語言 / Select Language</div>
      </q-card-section>

      <q-card-section class="q-pt-none">
        <q-list>
          <q-item v-for="lang in languages" :key="lang.code" clickable v-close-popup @click="selectLanguage(lang)"
            :class="{ 'bg-blue-1': selectedLanguage.code === lang.code }">
            <q-item-section avatar>
              <span class="text-h6">{{ lang.flag }}</span>
            </q-item-section>
            <q-item-section>
              <q-item-label>{{ lang.nativeName }}</q-item-label>
              <q-item-label caption>{{ lang.name }}</q-item-label>
            </q-item-section>
            <q-item-section side v-if="selectedLanguage.code === lang.code">
              <q-icon name="check" color="primary" />
            </q-item-section>
          </q-item>
        </q-list>
      </q-card-section>

      <q-card-actions align="right">
        <q-btn flat label="取消 / Cancel" color="primary" v-close-popup />
      </q-card-actions>
    </q-card>
  </q-dialog>
</template>


<script setup>
import { ref } from 'vue'
import { useQuasar } from 'quasar'

const $q = useQuasar()

// 语言选择对话框显示状态
const showLanguageDialog = ref(false)

// 支付方式数据
const paymentMethods = ref([
  {
    id: 1,
    name: 'Visa',
    icon: 'https://upload.wikimedia.org/wikipedia/commons/thumb/5/5e/Visa_Inc._logo.svg/200px-Visa_Inc._logo.svg.png'
  },
  {
    id: 2,
    name: 'Mastercard',
    icon: 'https://upload.wikimedia.org/wikipedia/commons/thumb/2/2a/Mastercard-logo.svg/200px-Mastercard-logo.svg.png'
  },
  {
    id: 3,
    name: 'PayPal',
    icon: 'https://upload.wikimedia.org/wikipedia/commons/thumb/b/b5/PayPal.svg/200px-PayPal.svg.png'
  },
  {
    id: 4,
    name: 'Apple Pay',
    icon: 'https://upload.wikimedia.org/wikipedia/commons/thumb/f/fa/Apple_logo_black.svg/200px-Apple_logo_black.svg.png'
  },
  {
    id: 5,
    name: 'Google Pay',
    icon: 'https://upload.wikimedia.org/wikipedia/commons/thumb/f/f2/Google_Pay_Logo.svg/200px-Google_Pay_Logo.svg.png'
  },
  {
    id: 6,
    name: 'Alipay',
    icon: 'https://upload.wikimedia.org/wikipedia/commons/thumb/2/2a/Alipay_Wordmark_Logo.png/330px-Alipay_Wordmark_Logo.png'
  },
  {
    id: 7,
    name: 'WeChat Pay',
    icon: 'https://upload.wikimedia.org/wikipedia/commons/thumb/7/7a/WeChat_Pay.png/330px-WeChat_Pay.png'
  },
  {
    id: 8,
    name: 'UnionPay',
    icon: 'https://upload.wikimedia.org/wikipedia/commons/thumb/1/1b/UnionPay_logo.svg/200px-UnionPay_logo.svg.png'
  },
  {
    id: 9,
    name: 'American Express',
    icon: 'https://upload.wikimedia.org/wikipedia/commons/thumb/f/fa/American_Express_logo_%282018%29.svg/200px-American_Express_logo_%282018%29.svg.png'
  },
  {
    id: 10,
    name: 'JCB',
    icon: 'https://upload.wikimedia.org/wikipedia/commons/thumb/4/40/JCB_logo.svg/200px-JCB_logo.svg.png'
  }
])

// 语言选项数据
const languages = ref([
  {
    code: 'zh-CN',
    name: 'Chinese (Simplified)',
    nativeName: '简体中文',
    flag: '🇨🇳'
  },
  {
    code: 'zh-TW',
    name: 'Chinese (Traditional)',
    nativeName: '繁體中文',
    flag: '🇹🇼'
  },
  {
    code: 'en',
    name: 'English',
    nativeName: 'English',
    flag: '🇺🇸'
  },
  {
    code: 'ja',
    name: 'Japanese',
    nativeName: '日本語',
    flag: '🇯🇵'
  },
  {
    code: 'ko',
    name: 'Korean',
    nativeName: '한국어',
    flag: '🇰🇷'
  }
])

// 当前选中的语言
const selectedLanguage = ref(languages.value[0])

// 选择语言方法
const selectLanguage = (lang) => {
  selectedLanguage.value = lang
  $q.notify({
    message: `语言已切换到 ${lang.nativeName}`,
    color: 'positive',
    position: 'top'
  })
}
</script>

<style scoped>
.hover-white:hover {
  color: white !important;
}

/* 支付方式和语言选择样式 */
.payment-methods-container {
  max-width: 600px;
}

.payment-methods-image {
  width: 100%;
  height: 40px;
  object-fit: cover;
  border-radius: 4px;
}

.hover-text-primary:hover {
  color: var(--q-primary) !important;
  transition: color 0.2s ease;
}

/* 支付方式横向滚动样式 */
.payment-methods-scroll-container {
  overflow: hidden;
  width: 100%;
  white-space: nowrap;
}

.payment-methods-list {
  display: inline-block;
  animation: scroll-horizontal 20s linear infinite;
}

.payment-method-item {
  display: inline-block;
  margin-right: 16px;
  height: 40px;
  width: 80px;
  vertical-align: middle;
  background-color: white;
  border-radius: 4px;
  padding: 4px;
  box-sizing: border-box;
}

.payment-method-icon {
  height: 100%;
  width: 100%;
  object-fit: contain;
}

@keyframes scroll-horizontal {
  0% {
    transform: translateX(0);
  }

  100% {
    transform: translateX(-50%);
  }
}

.payment-methods-list:hover {
  animation-play-state: paused;
}

.arrow-icon {
  transition: transform 0.3s ease;
}

.rotate-180 {
  transform: rotate(180deg);
}
</style>