<template>
  <div class="host-center gradient-background-circles">
    <!-- 顶部导航 -->
    <MobileHeader title="Host Center" :isHomePage="true" />

    <!-- 主要内容 -->
    <div class="content">
      <!-- 用户信息卡片 -->
      <div class="user-card">
        <!-- APP连接状态指示 -->
        <div v-if="isInApp() && !appConnected" class="app-status connecting">
          <div class="status-indicator"></div>
          <span>正在连接APP...</span>
        </div>

        <div class="user-info">
          <div class="avatar">
            <img
              v-if="userInfo.userAvatar"
              :src="userInfo.userAvatar"
              :alt="userInfo.name"
              @error="handleImageError"
            />
            <span v-else class="avatar-placeholder">{{ getAvatarPlaceholder() }}</span>
          </div>
          <div class="user-details">
            <h3>{{ userInfo.userNickname || userInfo.name }}</h3>
            <p>ID: {{ userInfo.account || userInfo.id }}</p>
          </div>
          <button class="notification-btn" @click="goToNotification">
            <span>✏️</span>
          </button>
        </div>

        <!-- 账户状态标签 -->
        <div class="account-tags">
          <span class="tag host-tag">👑 Host</span>
        </div>
      </div>

      <!-- My salary 区域 -->
      <div class="salary-section">
        <div class="salary-header">
          <h3>My salary:</h3>
          <button class="personal-salary-btn" @click="showDatePicker">
            Personal Salary <span class="arrow">></span>
          </button>
        </div>

        <div class="salary-content">
          <!--暂时禁用，后面补充-->
<!--          <div class="salary-item">
            <p class="salary-label">History Salary:</p>
            <p class="salary-amount">${{ salaryInfo.hostSalary }}</p>
          </div>
          <div class="salary-separator"></div>-->
          <div class="salary-item">
            <p class="salary-label">Current Salary:</p>
            <p class="salary-amount">${{ salaryInfo.currentSalary }}</p>
          </div>
        </div>
      </div>

      <!-- Today's Task -->
      <div class="task-section">
        <h3>Today's Task:</h3>

        <!-- 任务表格 -->
        <div class="task-table">
          <div class="table-row table-header">
            <div class="table-cell">Anchor type</div>
            <div class="table-cell">Minutes</div>
            <div class="table-cell">Gift Task</div>
          </div>
          <div class="table-row table-data">
            <div class="table-cell">{{ taskInfo.anchorType }}</div>
            <div class="table-cell">
              <span class="minutes-completed">{{ taskInfo.minutes }}</span>
            </div>
            <div class="table-cell">{{ taskInfo.giftTask }}</div>
          </div>
        </div>

        <!-- Platform Policy 链接 -->
<!--        <div class="policy-link" @click="goToPlatformPolicy">
          <span>Platform Policy</span>
          <span class="arrow">></span>
        </div>-->
      </div>

      <!-- 进度信息 -->
      <div class="progress-section">
        <div class="progress-header">
          <span class="progress-date">{{ progressInfo.date }}</span>
          <span class="progress-status">{{ progressInfo.status }}</span>
        </div>

        <div class="progress-details">
          <div class="progress-item">
            <span>Target: {{ progressInfo.target }}</span>
            <span>Salary: ${{ progressInfo.salary }}</span>
          </div>
          <div class="progress-item">
            <span>Time(Days): {{ progressInfo.timeDays }}</span>
          </div>
        </div>
      </div>

      <!-- 操作按钮 -->
      <div class="action-buttons">
        <button class="action-btn exchange-btn" @click="exchangeGoldCoins">
          Exchange
        </button>
        <button class="action-btn transfer-btn" @click="transfer">
          Transfer
        </button>
        <!--
        <button class="action-btn withdraw-btn" @click="cashWithdraw">
          Cash<br>Withdraw
        </button>
        -->
      </div>
    </div>
  </div>
</template>

<script setup>
import { reactive } from 'vue'
import { useRouter } from 'vue-router'
import MobileHeader from '../components/MobileHeader.vue'
import {usePageInitializationWithConfig} from "@/utils/pageConfig.js";
import {isInApp} from "@/utils/appBridge.js";

const router = useRouter()


// 进度信息
const progressInfo = reactive({
  date: '2025.08',
  status: 'Pending',
  target: 'B',
  salary: 50,
  timeDays: 20,
  diamond: 50000,
  hostSalary: '–',
  agentSalary: '–',
  total: '–'
})

const showDatePicker = () => {
  router.push('/platform-policy')
}

const goToNotification = () => {
  router.push('/host-setting')
}

const exchangeGoldCoins = () => {
  router.push('/exchange-gold-coins')
}

const transfer = () => {
  router.push('/transfer')
}

const {
  appConnected,
  userInfo,
  salaryInfo,
  taskInfo,
  handleImageError,
  getAvatarPlaceholder
} = usePageInitializationWithConfig('HOST_CENTER')

</script>

<style scoped>
.host-center {
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
}



.content {
  padding: 16px;
  position: relative;
  z-index: 2;
}

/* 用户信息卡片 */
.user-card {
  background-color: white;
  padding: 16px;
  border-radius: 12px;
  margin-bottom: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

/* APP连接状态 */
.app-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 8px;
  margin-bottom: 12px;
  font-size: 12px;
  font-weight: 500;
}

.app-status.connecting {
  background-color: #fef3c7;
  color: #d97706;
}

.app-status.connected {
  background-color: #d1fae5;
  color: #059669;
}

.status-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: currentColor;
}

.app-status.connecting .status-indicator {
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

.user-info {
  display: flex;
  align-items: center;
  margin-bottom: 12px;
}

.avatar {
  width: 50px;
  height: 50px;
  border-radius: 25px;
  background-color: #8B5CF6;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 20px;
  font-weight: 600;
  margin-right: 12px;
  overflow: hidden;
  position: relative;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 25px;
}

.avatar .avatar-placeholder {
  color: white;
  font-size: 20px;
  font-weight: 600;
}

.user-details {
  flex: 1;
}

.user-details h3 {
  margin: 0 0 4px 0;
  font-size: 16px;
  font-weight: 600;
  color: #333;
}

.user-details p {
  margin: 0;
  font-size: 14px;
  color: #666;
}

.system-info {
  font-size: 12px !important;
  color: #8B5CF6 !important;
  margin-top: 2px !important;
}

.edit-btn {
  width: 32px;
  height: 32px;
  border: none;
  background: none;
  font-size: 16px;
  cursor: pointer;
}

.notification-btn {
  width: 32px;
  height: 32px;
  border: none;
  background: none;
  font-size: 16px;
  cursor: pointer;
}

/* 身份切换标签 */
.identity-tabs {
  display: flex;
  gap: 8px;
  margin: 12px 0;
}

.identity-tab {
  padding: 6px 12px;
  border: 1px solid #e5e7eb;
  border-radius: 16px;
  background-color: white;
  color: #666;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.identity-tab.active {
  background-color: #8B5CF6;
  color: white;
  border-color: #8B5CF6;
}

.identity-tab:not(.active):hover {
  border-color: #8B5CF6;
  color: #8B5CF6;
}

.identity-tab.disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.identity-tab.disabled:hover {
  border-color: #e5e7eb;
  color: #666;
}

.identity-tab.disabled.active:hover {
  border-color: #8B5CF6;
  color: white;
}

.account-tags {
  display: flex;
  gap: 8px;
}

.tag {
  padding: 4px 12px;
  border-radius: 16px;
  font-size: 12px;
  font-weight: 600;
}

.host-tag {
  background-color: #E0E7FF;
  color: #5B21B6;
}

.agency-tag {
  background-color: #DBEAFE;
  color: #1E40AF;
}

.coin-tag {
  background-color: #FEF3C7;
  color: #D97706;
}

.salary-tag {
  background-color: #FEF3C7;
  color: #D97706;
}

/* My salary 区域 */
.salary-section {
  background-color: white;
  padding: 16px;
  border-radius: 12px;
  margin-bottom: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.salary-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.salary-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: #333;
}

.personal-salary-btn {
  background: none;
  border: none;
  color: #8B5CF6;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: all 0.2s;
}

.personal-salary-btn:hover {
  color: #7C3AED;
}

.salary-content {
  display: flex;
  align-items: center;
  gap: 20px;
}

.salary-item {
  flex: 1;
  text-align: center;
}

.salary-label {
  margin: 0 0 8px 0;
  font-size: 14px;
  color: #666;
}

.salary-amount {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  color: #333;
}

.salary-separator {
  width: 1px;
  height: 40px;
  background-color: #8B5CF6;
}

/* Today's Task 区域 */
.task-section {
  background-color: white;
  padding: 16px;
  border-radius: 12px;
  margin-bottom: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.task-section h3 {
  margin: 0 0 16px 0;
  font-size: 16px;
  font-weight: 600;
  color: #333;
}

/* 任务表格 */
.task-table {
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 12px;
}

.table-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
}

.table-header {
  background-color: #f8f9fa;
  border-bottom: 1px solid #e5e7eb;
}

.table-data {
  background-color: white;
}

.table-cell {
  padding: 12px 8px;
  text-align: center;
  border-right: 1px solid #e5e7eb;
  font-size: 14px;
}

.table-cell:last-child {
  border-right: none;
}

.table-header .table-cell {
  font-weight: 600;
  color: #374151;
}

.table-data .table-cell {
  color: #111827;
}

.minutes-progress {
  color: #6B7280;
}

.minutes-completed {
  color: #10B981;
  font-weight: 600;
}

/* Platform Policy 链接 */
.policy-link {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  margin-top: 12px;
  background-color: #f8f9fa;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  border: 1px solid #e9ecef;
}

.policy-link:hover {
  background-color: #e9ecef;
  border-color: #8B5CF6;
}

.policy-link:active {
  transform: scale(0.98);
}

.policy-link span:first-child {
  font-size: 14px;
  font-weight: 500;
  color: #333;
}



/* 进度信息 */
.progress-section {
  background-color: white;
  padding: 16px;
  border-radius: 12px;
  margin-bottom: 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.progress-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.progress-date {
  font-size: 16px;
  font-weight: 600;
  color: #333;
}

.progress-status {
  background: linear-gradient(to right, #FF7578, #FF3D40);
  color: white;
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
}

.progress-details {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.progress-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.progress-item span {
  font-size: 14px;
  color: #333;
}

/* 操作按钮 */
.action-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.action-btn {
  padding: 14px 12px;
  border: none;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  line-height: 1.2;
  transition: all 0.2s;
  width: 100%;
}

.action-btn:active {
  transform: scale(0.98);
}

.exchange-btn {
  background-color: #FDE68A;
  color: #D97706;
}

.transfer-btn {
  background-color: #8B5CF6;
  color: white;
}

.withdraw-btn {
  background-color: #10B981;
  color: white;
}



/* 通用箭头样式 */
.arrow {
  font-size: 16px;
  font-weight: bold;
  color: #8B5CF6;
}
</style>
