<view class="page">
  <!-- 顶部导航栏 -->
  <view class="unified-header">
    <view class="unified-header-left" bindtap="goBack">
      <image src="/images/icon-back.png" class="unified-back-icon" mode="aspectFit"></image>
      <text class="unified-back-text">返回</text>
    </view>
    <text class="unified-header-title">生成推广海报</text>
    <view class="unified-header-right"></view>
  </view>

  <view class="content" style="padding-top: {{totalNavHeight}}px">
    <block wx:if="{{!isLoading}}">
        <swiper class="poster-swiper" previous-margin="40rpx" next-margin="40rpx" bindchange="onPosterChange">
            <swiper-item wx:for="{{posters}}" wx:key="id" class="poster-item">
                <view class="poster-card {{currentPosterIndex === index ? 'active' : ''}}">
                    <image src="{{item.url}}" mode="aspectFill" class="poster-img" binderror="onImageError" data-index="{{index}}" />
                    <view class="qr-overlay" style="bottom: {{item.qrBottom}}%; right: {{item.qrRight}}%;">
                        <image src="{{qrCodeUrl}}" class="qr-img" binderror="onQrError" />
                    </view>
                </view>
            </swiper-item>
        </swiper>

        <view class="action-area">
            <button class="save-btn" bindtap="savePoster">保存到相册</button>
            <button class="share-btn" open-type="share">转发给好友</button>
        </view>
    </block>
    
    <view wx:else class="loading-state">
        <view class="loading-spinner"></view>
        <text>正在加载素材...</text>
    </view>
    
    <!-- Canvas for drawing (Hidden) -->
    <canvas type="2d" id="posterCanvas" class="poster-canvas" style="width:750px; height:1334px; opacity: 0; position: absolute; left:-9999px;"></canvas>
  </view>
</view>
