<?php
/** @var array $order */
/** @var array|null $gw */
/** @var bool $choose */
/** @var bool $paid */
$isPaid = $paid ?? ($order['status'] === 'paid');
?>
<section class="page-hero"><div class="container"><h1>订单支付</h1><p>订单号 <?php echo e($order['order_no']); ?></p></div></section>
<div class="container">
 <div class="form-card">
   <div style="padding:16px;border-radius:14px;background:var(--c-surface);border:1px solid var(--c-border);margin-bottom:6px">
     <div style="font-weight:800;font-size:18px"><?php echo e($order['product_name']); ?></div>
     <div style="color:var(--c-muted);font-size:14px">数量 <?php echo e($order['qty']); ?> 套 · 下单人 <?php echo e($order['customer_name']); ?></div>
     <div style="font-size:28px;font-weight:900;color:var(--c-primary);margin-top:8px">应付 ¥<?php echo e($order['amount']); ?></div>
   </div>

   <?php if ($isPaid): ?>
     <div class="alert alert-ok">✓ 该订单已支付成功</div>
     <a class="btn btn-primary" href="<?php echo site_url('order/success/' . $order['order_no']); ?>">查看支付详情</a>
   <?php elseif (!empty($choose)): ?>
     <p style="margin:18px 0 10px;font-weight:700">选择支付方式</p>
     <form method="post" action="<?php echo site_url('order/pay/' . $order['order_no']); ?>">
       <?php echo csrf_field(); ?>
       <div class="pay-channels">
         <button type="submit" name="channel" value="alipay" class="pay-channel">💰 支付宝</button>
         <button type="submit" name="channel" value="wechat" class="pay-channel">💚 微信支付</button>
       </div>
     </form>
   <?php else:
     $mode = $gw['mode'] ?? 'demo';
     if ($mode === 'redirect'): ?>
       <p style="margin:16px 0">正在跳转到支付宝支付…</p>
       <script>setTimeout(function(){ window.location.href = <?php echo json_encode($gw['url']); ?>; }, 300);</script>
       <a class="btn btn-primary" href="<?php echo e($gw['url']); ?>">如未自动跳转，点击此处支付</a>
     <?php elseif ($mode === 'qrcode'): ?>
       <p style="margin:16px 0">请使用微信扫码支付：</p>
       <div class="pay-qr"><?php echo e($gw['qr']); ?></div>
     <?php else: ?>
       <div class="alert alert-ok" style="margin-top:16px">演示模式：点击下方按钮完成模拟支付（不影响真实下单流程）</div>
       <?php if (!empty($gw['config_missing'])): ?><p style="color:var(--c-muted);font-size:13px;margin-top:6px">* 尚未配置商户号，当前为演示支付；在后台「支付设置」填入商户号并切到真实模式即可真实收款。</p><?php endif; ?>
       <div class="pay-demo-box">
         <div class="pay-demo-icon"><?php echo ($gw['channel'] ?? 'alipay') === 'wechat' ? '💚' : '💰'; ?></div>
         <div style="margin:6px 0">订单号 <b><?php echo e($order['order_no']); ?></b></div>
         <a class="btn btn-primary magnetic" href="<?php echo e($gw['simulate']); ?>">模拟支付成功</a>
       </div>
     <?php endif; ?>
   <?php endif; ?>
   <p style="margin-top:20px"><a href="<?php echo site_url('order/query'); ?>">查询我的订单</a></p>
 </div>
</div>
