<template>
  <div class="host-setting gradient-background-circles">
    <MobileHeader title="Host Setting" />

    <div style="padding: 16px; position: relative; z-index: 2">
      <!-- My Agency 部分 -->
      <div style="margin-bottom: 20px">
        <div style="display: flex; align-items: center; margin-bottom: 12px">
          <div style="font-size: 1.4em; font-weight: 600">My Agency</div>
          <img src="/src/assets/icon/agency.png" alt="" height="25px" style="display: block" />
        </div>

        <div
          style="
            background-color: white;
            padding: 16px;
            border-radius: 12px;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
            display: flex;
            justify-content: space-between;
          "
        >
          <!-- 用户信息 -->
          <div style="display: flex; align-items: center">
            <img
              :src="avatarUrl || ''"
              alt=""
              width="50px"
              style="aspect-ratio: 1/1; border-radius: 50%; object-fit: cover"
              @error="defaultAvatarUrl"
            />
            <div style="flex: 1">
              <div style="margin-bottom: 4px; font-weight: 600">
                {{ userInfo.name }}
              </div>
              <div style="font-size: 0.9em; color: rgba(0, 0, 0, 0.4)">ID: {{ userInfo.id }}</div>
            </div>
          </div>
          <!-- 按钮 -->
          <div style="display: flex; align-items: center">
            <div class="leave-btn" @click="leaveAgent">Leave</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { reactive } from 'vue'
import { useRouter } from 'vue-router'
import MobileHeader from '../components/MobileHeader.vue'
import { showError } from '@/utils/toast.js'

const router = useRouter()

// 用户信息
const userInfo = reactive({
  name: 'User1',
  id: '1234567890',
})

const defaultAvatarUrl = (e) => {
  console.log('头像资源出错')
  e.target.onerror = null //防止循环
  e.target.src = new URL('/src/assets/images/WeeklyStar/defaultAvatar.png', import.meta.url).href
}

// 方法
const leaveAgent = () => {
  if (confirm('Are you sure you want to leave this agency?')) {
    showError('Leave agency request submitted')
    // 这里可以添加实际的离开代理商逻辑
  }
}
</script>

<style scoped>
* {
  color: rgba(0, 0, 0, 0.8);
  font-family: 'SF Pro Text';
}

.host-setting {
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
}

.leave-btn {
  background-color: #fff;
  border: 1px solid #e6e6e6;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.9em;
  font-weight: 500;
  transition: background-color 0.2s;
}

.leave-btn:active {
  background-color: #00000010;
}

@media screen and (max-width: 360px) {
  * {
    font-size: 10px;
  }
}

@media screen and (min-width: 360px) {
  * {
    font-size: 12px;
  }
}

@media screen and (min-width: 768px) {
  * {
    font-size: 24px;
  }
}
</style>
