<view class="profile-page">

  <!-- ======== MAIN PROFILE VIEW ======== -->
  <view class="main-profile-view">
    <!-- Header -->
    <view class="profile-header">
       <view class="user-main">
          <view class="user-avatar" bindtap="openProfileEditor">
             <t-avatar wx:if="{{userAvatar}}" image="{{userAvatar}}" size="120rpx" />
             <t-avatar wx:else icon="user" size="120rpx" />
          </view>
           <view class="user-text">
              <view class="user-name" bindtap="openProfileEditor">{{userName}}</view>
              <view class="level-badge" bindtap="goToBadges">{{userLevelTag || 'Lv.0 园艺新手'}}</view>
             <view class="user-sun-days">
                <view class="sun-days-item">
                    <t-icon name="sunny" size="24rpx" color="#FBC02D" />
                    <text>{{userSunlight}} 阳光</text>
                </view>
                <view class="sun-days-divider"></view>
                <view class="sun-days-item">
                    <t-icon name="calendar" size="24rpx" color="#66BB6A" />
                    <text>加入 {{joinedDays}} 天</text>
                </view>
              </view>
          </view>
       </view>
       <view class="settings-btn" bindtap="goToNotificationSettings">
           <t-icon name="setting" size="40rpx" color="#666" />
       </view>
    </view>

    <!-- Stats Card (Fixed) -->


    <scroll-view scroll-y class="profile-content" enhanced show-scrollbar="{{false}}" scroll-top="{{scrollTop}}">
       <!-- Menu -->
       <view class="profile-menu">
           <view class="menu-group-title">常用功能</view>
           
           <view class="menu-item" bindtap="goToExchange">
               <view class="menu-left">
                   <view class="menu-icon-bg" style="background: #FCE4EC">
                       <t-icon name="gift" size="36rpx" color="#E91E63" />
                   </view>
                   <text class="menu-text">兑换中心</text>
               </view>
               <view class="menu-right-info">
                   <text class="menu-badge-text">开发中</text>
                   <t-icon name="chevron-right" size="36rpx" color="#ccc" />
               </view>
           </view>

           <view class="menu-item" bindtap="goToBadges">
               <view class="menu-left">
                   <view class="menu-icon-bg" style="background: #F3E5F5">
                       <t-icon name="award" size="36rpx" color="#9C27B0" />
                   </view>
                   <text class="menu-text">等级徽章</text>
               </view>
               <view class="menu-right-info">
                   <t-icon name="chevron-right" size="36rpx" color="#ccc" />
               </view>
           </view>

           <view class="menu-item" bindtap="goToFavorites">
               <view class="menu-left">
                   <view class="menu-icon-bg" style="background: #FFF3E0">
                       <t-icon name="star" size="36rpx" color="#FF9800" />
                   </view>
                   <text class="menu-text">我的收藏</text>
               </view>
               <t-icon name="chevron-right" size="36rpx" color="#ccc" />
           </view>

           <view class="menu-item" bindtap="goToPosts">
               <view class="menu-left">
                   <view class="menu-icon-bg" style="background: #E3F2FD">
                       <t-icon name="file-copy" size="36rpx" color="#2196F3" />
                   </view>
                   <text class="menu-text">我的发布</text>
               </view>
               <t-icon name="chevron-right" size="36rpx" color="#ccc" />
           </view>

           <view class="menu-item" bindtap="goToIdentifyHistory">
               <view class="menu-left">
                   <view class="menu-icon-bg" style="background: #E8F5E9">
                       <t-icon name="scan" size="36rpx" color="#4CAF50" />
                   </view>
                   <text class="menu-text">识别记录</text>
               </view>
               <t-icon name="chevron-right" size="36rpx" color="#ccc" />
           </view>

           <view class="menu-group-title" style="margin-top: 32rpx;">更多服务</view>

           <view class="menu-item" bindtap="goToAbout">
               <view class="menu-left">
                   <view class="menu-icon-bg" style="background: #F5F5F5">
                       <t-icon name="help-circle" size="36rpx" color="#616161" />
                   </view>
                   <text class="menu-text">帮助与关于</text>
               </view>
               <t-icon name="chevron-right" size="36rpx" color="#ccc" />
           </view>
       </view>

       <view style="height: 100rpx;"></view>
    </scroll-view>
  </view>

  <!-- Profile Edit Popup -->
  <t-popup visible="{{showProfileEditor}}" placement="bottom" bind:visible-change="onProfilePopupChange">
    <view class="profile-edit-popup">
      <view class="popup-header">
        <text class="popup-title">编辑资料</text>
        <view class="popup-close" bindtap="closeProfileEditor">
          <t-icon name="close" size="40rpx" color="#999" />
        </view>
      </view>

      <button class="edit-row avatar-btn" open-type="chooseAvatar" bind:chooseavatar="onChooseAvatar">
        <text class="edit-row-label">头像</text>
        <view class="edit-row-right">
          <t-avatar
            wx:if="{{tempAvatar || userAvatar}}"
            image="{{tempAvatar || userAvatar}}"
            size="96rpx"
          />
          <t-avatar wx:else icon="user" size="96rpx" />
          <t-icon name="chevron-right" size="32rpx" color="#C5C5C5" />
        </view>
      </button>

      <view class="edit-row">
        <text class="edit-row-label">昵称</text>
        <input
          class="nickname-input"
          type="text"
          placeholder="请输入昵称"
          placeholder-style="color: #C5C5C5;"
          value="{{tempNickname}}"
          bindinput="onNicknameInput"
        />
      </view>

      <view class="edit-actions">
        <t-button theme="primary" block shape="round" bind:tap="saveProfile">保存</t-button>
      </view>
    </view>
  </t-popup>

</view>
