<!--首页-->
<view class="page-container">
  <!-- 顶部用户信息 -->
  <view class="header">
    <view class="user-info">
      <image class="avatar" src="{{userInfo.avatar || '/images/default-avatar.png'}}" mode="aspectFill"></image>
      <view class="user-details">
        <text class="nickname">{{userInfo.nickname || '未登录'}}</text>
        <text class="location">{{weatherInfo.location || '获取位置中...'}}</text>
      </view>
    </view>
    <view class="weather" wx:if="{{weatherInfo}}">
      <text class="temperature">{{weatherInfo.temperature}}°</text>
      <text class="weather-desc">{{weatherInfo.weather}}</text>
    </view>
  </view>

  <!-- 统计卡片 -->
  <view class="stats-container">
    <view class="stats-grid">
      <view class="stat-item" bindtap="goToFarmList">
        <text class="stat-number">{{farmStats.farmCount}}</text>
        <text class="stat-label">养殖场</text>
      </view>
      <view class="stat-item" bindtap="goToAnimalList">
        <text class="stat-number">{{farmStats.animalCount}}</text>
        <text class="stat-label">动物数量</text>
      </view>
      <view class="stat-item" bindtap="goToStatistics">
        <text class="stat-number">{{farmStats.healthRate}}%</text>
        <text class="stat-label">健康率</text>
      </view>
      <view class="stat-item" bindtap="goToStatistics">
        <text class="stat-number">¥{{farmStats.totalValue}}</text>
        <text class="stat-label">总价值</text>
      </view>
    </view>
  </view>

  <!-- 快捷操作 -->
  <view class="quick-actions">
    <view class="section-title">快捷操作</view>
    <view class="actions-grid">
      <view 
        class="action-item" 
        wx:for="{{quickActions}}" 
        wx:key="name"
        data-url="{{item.url}}"
        bindtap="onQuickAction"
      >
        <view class="action-icon">
          <image src="/images/icons/{{item.icon}}.png" mode="aspectFit"></image>
        </view>
        <text class="action-name">{{item.name}}</text>
      </view>
    </view>
  </view>

  <!-- 最近活动 -->
  <view class="recent-activities" wx:if="{{recentActivities.length > 0}}">
    <view class="section-header">
      <text class="section-title">最近活动</text>
      <text class="section-more" bindtap="goToMessages">查看更多</text>
    </view>
    <view class="activities-list">
      <view 
        class="activity-item" 
        wx:for="{{recentActivities}}" 
        wx:key="id"
        data-item="{{item}}"
        bindtap="onActivityTap"
      >
        <view class="activity-content">
          <text class="activity-title">{{item.title}}</text>
          <text class="activity-desc">{{item.content}}</text>
          <text class="activity-time">{{item.created_at}}</text>
        </view>
        <view class="activity-arrow"></view>
      </view>
    </view>
  </view>

  <!-- 加载状态 -->
  <view class="loading" wx:if="{{loading}}">
    <view class="loading-spinner"></view>
    <text>加载中...</text>
  </view>

  <!-- 空状态 -->
  <view class="empty" wx:if="{{!loading && farmStats.farmCount === 0}}">
    <image class="empty-icon" src="/images/empty-farm.png" mode="aspectFit"></image>
    <text class="empty-text">还没有养殖场</text>
    <text class="empty-desc">添加您的第一个养殖场开始管理</text>
    <button class="btn btn-primary mt-3" bindtap="goToFarmList">添加养殖场</button>
  </view>
</view>