<!doctype html>
<html>

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta name="description" content="项目主页" details="展示特定项目的详细信息和统计数据">
  <title>项目主页</title>
</head>

<style>
  body {
    background-color: var(--bg-color-secondary);
    color: var(--text-color);
    padding: var(--spacing-lg);
  }

  .container {
    max-width: 1200px;
    margin: 0 auto;
  }

  header {
    background: linear-gradient(135deg, var(--color-primary), color-mix(in srgb, var(--color-primary), black 20%));
    color: white;
    padding: 40px 0;
    border-radius: var(--radius-lg);
    margin-bottom: var(--spacing-xl);
    box-shadow: var(--shadow-md);
  }

  .header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 30px;
  }

  .project-info {
    display: flex;
    align-items: center;
  }

  .project-icon {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    object-fit: cover;
    border: 4px solid white;
    box-shadow: var(--shadow-sm);
    margin-right: 20px;
  }

  .project-title h1 {
    font-size: 2.5rem;
    margin-bottom: 5px;
    color: white;
  }

  .project-type {
    display: inline-block;
    background-color: rgba(255, 255, 255, 0.2);
    padding: 5px 15px;
    border-radius: 30px;
    font-size: 0.9rem;
    font-weight: 600;
  }

  .project-status {
    background-color: var(--color-success);
    color: white;
    padding: 8px 20px;
    border-radius: 30px;
    font-weight: bold;
    display: inline-flex;
    align-items: center;
    box-shadow: var(--shadow-sm);
  }

  .project-status i {
    margin-right: 8px;
  }

  .main-content {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: var(--spacing-xl);
  }

  .description-card,
  .stats-card {
    background-color: var(--bg-color);
    border-radius: var(--radius-lg);
    padding: 30px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
  }

  .card-title {
    font-size: 1.6rem;
    margin-bottom: 20px;
    color: var(--color-primary);
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 10px;
  }

  .description-content {
    font-size: 1.1rem;
    line-height: 1.7;
    color: var(--text-color);
  }

  .stat-item {
    display: flex;
    align-items: center;
    margin-bottom: 20px;
  }

  .stat-icon {
    width: 50px;
    height: 50px;
    background-color: color-mix(in srgb, var(--color-primary), transparent 90%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 15px;
    color: var(--color-primary);
    font-size: 1.4rem;
  }

  .stat-info h3 {
    font-size: 1.3rem;
    margin-bottom: 5px;
    color: var(--text-color);
  }

  .stat-info p {
    color: var(--text-color-secondary);
  }

  .date-stat {
    display: flex;
    justify-content: space-between;
    margin-top: 30px;
    border-top: 1px solid var(--border-color);
    padding-top: 20px;
  }

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

  .date-item:first-child {
    border-right: 1px solid var(--border-color);
  }

  .date-label {
    color: var(--text-color-secondary);
    font-size: 0.9rem;
  }

  .date-value {
    font-size: 1.1rem;
    font-weight: bold;
    margin-top: 5px;
    color: var(--text-color);
  }
  
  @media (max-width: 768px) {
    .main-content {
      grid-template-columns: 1fr;
    }
    .header-content {
      flex-direction: column;
      text-align: center;
    }
    .project-info {
      flex-direction: column;
      margin-bottom: 20px;
    }
    .project-icon {
      margin-right: 0;
      margin-bottom: 15px;
    }
  }
</style>

<body>
  <div class="container">
    <header>
      <div class="header-content">
        <div class="project-info">
          <img :src="app.icon || 'http://public.veypi.com/img/avatar/0075.jpg'" alt="项目图标" class="project-icon">
          <div class="project-title">
            <h1>{{app.name || '未命名项目'}}</h1>
            <span class="project-type"><i class="fas fa-globe"></i> {{app.typ || '公开项目'}}</span>
          </div>
        </div>
        <div class="project-status">
          <i class="fas fa-check-circle"></i> {{app.status || '状态良好'}}
        </div>
      </div>
    </header>

    <div class="main-content">
      <div class="description-card">
        <h2 class="card-title">项目描述</h2>
        <div class="description-content">
          <p v-if="app.des">{{app.des}}</p>
          <p v-else>这是一个公开的项目，欢迎查看和参与。项目处于良好状态，您可以安全地使用和贡献。</p>
        </div>
      </div>

      <div class="stats-card">
        <h2 class="card-title">项目统计</h2>

        <div class="stat-item">
          <div class="stat-icon">
            <i class="fas fa-users"></i>
          </div>
          <div class="stat-info">
            <h3>{{app.user_count || 0}}</h3>
            <p>参与用户</p>
          </div>
        </div>

        <div class="stat-item">
          <div class="stat-icon">
            <i class="fas fa-key"></i>
          </div>
          <div class="stat-info">
            <h3>{{$G.app.id ? $G.app.id.substring(0, 8) : 'N/A'}}</h3>
            <p>项目ID (缩略)</p>
          </div>
        </div>

        <div class="stat-item">
          <div class="stat-icon">
            <i class="fas fa-shield-alt"></i>
          </div>
          <div class="stat-info">
            <h3>{{app.typ || '公开'}}</h3>
            <p>项目类型</p>
          </div>
        </div>

        <div class="date-stat">
          <div class="date-item">
            <div class="date-label">创建于</div>
            <div class="date-value">{{formatDate(app.created_at) || 'N/A'}}</div>
          </div>
          <div class="date-item">
            <div class="date-label">最后更新</div>
            <div class="date-value">{{formatDate(app.updated_at) || 'N/A'}}</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</body>

<script setup>
  // 默认应用数据
  app = {
    id: '',
    name: '',
    icon: '',
    des: '',
    typ: '',
    status: '',
    created_at: '',
    updated_at: '',
    user_count: 0,
    init_role: null,
    init_url: ''
  }
  
  // 格式化日期函数
  formatDate = (isoString) => {
    if (!isoString) return null;

    const date = new Date(isoString);
    if (isNaN(date.getTime())) return isoString; // 如果解析失败返回原字符串

    const year = date.getFullYear();
    const month = String(date.getMonth() + 1).padStart(2, '0');
    const day = String(date.getDate()).padStart(2, '0');
    const hours = String(date.getHours()).padStart(2, '0');
    const minutes = String(date.getMinutes()).padStart(2, '0');

    return `${year}-${month}-${day} ${hours}:${minutes}`;
  }

  // 同步应用数据
  sync = () => {
    // 从路由参数获取ID，或者使用默认值/模拟值
    const id = $router.params.id || $G.app?.id
    
    if (!id) {
       // 如果没有ID，可能是直接访问，展示示例数据或跳转
       // $router.push('/app')
       return
    }
    
    $axios.get(`/api/app/${id}`)
      .then((data) => {
        Object.assign(app, data)
        document.title = `${app.name} - 项目主页`
      })
      .catch((e) => {
        console.log(e)
        // 错误处理，保留在当前页或跳转
        // $router.push('/app')
      })
  }
  
  // 页面加载时执行
  sync()
</script>

</html>