{include file="app/index/view/public/header"}

<div class="blog-hotbar">
  <span class="blog-hotbar-label">📢 线报</span>
  <div class="blog-hotbar-list">
    <span class="blog-hotbar-item">全网最新优惠情报，实时更新</span>
    <span class="blog-hotbar-item">🛒 淘宝 · 京东 · 天猫</span>
    <span class="blog-hotbar-item">📊 数据来源 · 大淘客</span>
  </div>
</div>

{if !empty($tips)}
<div class="mb-20" style="background:#fff7f7 ; border:1px solid #ffd6d6 ; color:#c0392b ; padding:12px 16px ; border-radius:10px ; font-size:14px">
  ⚠️ {$tips}
</div>
{/if}

<div class="row">
  <div class="column-big">

    {if !empty($list)}
      <div class="d-flex" style="flex-direction:column ; gap:14px ; margin-bottom:24px">
      {foreach $list as $item}
      <?php
        $platform = $item['platform'] ?? '';
        $p = trim($platform);
        if ($p == '京东')        { $pColor = '#e1251b'; }
        elseif ($p == '天猫')    { $pColor = '#ff3f7f'; }
        elseif ($p == '淘宝')    { $pColor = '#ff7a00'; }
        else                     { $pColor = '#888'; }
        $goodsId   = !empty($item['id']) ? $item['id'] : 0;
        // 线报 itemIds 可能为逗号分隔的多个商品 id，仅取第一个用于跳转购买
        if (!empty($goodsId) && strpos($goodsId, ',') !== false) {
            $goodsId = explode(',', $goodsId)[0];
        }
        // 跳转购买链接：redirect/jump 内部会用 yun_items 库 item_from 自动纠正平台，
        // 即使此处平台写死 tb 也能正确转链到京东/拼多多等。
        $detailUrl = !empty($goodsId) ? url('index/redirect/jump', ['platform' => 'tb', 'id' => $goodsId]) : '';
        $pic       = $item['pic'] ?? '';
        $content   = $item['content'] ?? '';
        $copyText  = !empty($content) ? $content : ($item['contentCopy'] ?? '');
        $time      = $item['createTime'] ?? '';
      ?>
      <article class="shadow-theme tipoff-card of-hidden d-flex" style="border-radius:14px ; border:1px solid rgba(0,0,0,0.06) ; gap:14px ; padding:14px">
        <a href="{$detailUrl}" target="_blank" style="flex:0 0 110px;text-decoration:none;">
          {if !empty($pic)}
          <img src="<?php echo $pic; ?>" alt="线报" class="w-110 h-110" style="object-fit:cover ; border-radius:10px ; background:#f5f5f5">
          {else}
          <div class="w-110 h-110 d-flex" style="border-radius:10px ; background:#f5f5f5 ; align-items:center ; justify-content:center"><span style="font-size:40px;color:#ccc;">🖼️</span></div>
          {/if}
        </a>
        <div class="d-flex" style="flex:1 ; min-width:0 ; flex-direction:column">
          <div class="d-flex" style="align-items:center ; gap:8px ; margin-bottom:8px">
            <span style="background:<?php echo $pColor; ?>;color:#fff;font-size:12px;font-weight:700;padding:3px 10px;border-radius:12px;"><?php echo $p ?: '优惠'; ?></span>
            {if !empty($item['isRecommend']) || !empty($item['homeRecommend'])}
            <span style="background:#fff0f0;color:#ff4757;font-size:12px;font-weight:700;padding:3px 10px;border-radius:12px;">精选</span>
            {/if}
            {if !empty($time)}
            <span style="color:#999;font-size:12px;margin-left:auto;">🕒 <?php echo $time; ?></span>
            {/if}
          </div>
          {if !empty($item['recommendDesc'])}
          <div style="font-size:15px;font-weight:700;color:var(--aColor,#1f2329);line-height:1.4;margin-bottom:6px;">{$item['recommendDesc']}</div>
          {/if}
          {if !empty($item['contentCopy'])}
          <p class="of-hidden" style="font-size:13px ; color:#555 ; line-height:1.6 ; margin:0 0 10px ; display:-webkit-box ; -webkit-line-clamp:3 ; -webkit-box-orient:vertical">{$item['contentCopy']}</p>
          {elseif !empty($content)}
          <p style="font-size:13px;color:#555;line-height:1.6;margin:0 0 10px;word-break:break-all;">{$content}</p>
          {/if}
          <div class="d-flex" style="margin-top:auto ; align-items:center ; gap:10px">
            {if !empty($detailUrl)}
            <a href="{$detailUrl}" target="_blank" style="padding:7px 18px;background:linear-gradient(135deg,#667eea,#764ba2);color:#fff;border:none;border-radius:8px;font-size:13px;font-weight:600;text-decoration:none;">查看商品</a>
            {/if}
            {if !empty($copyText)}
            <button type="button" class="tipoff-copy" data-copy="<?php echo htmlspecialchars($copyText, ENT_QUOTES); ?>" class="cur-pointer" style="padding:7px 18px ; background:#fff ; border:1px solid #ff6b6b ; color:#ff4757 ; border-radius:8px ; font-size:13px ; font-weight:600">复制口令</button>
            {/if}
          </div>
        </div>
      </article>
      {/foreach}
      </div>
    {else}
      <div class="text-center" style="padding:80px 20px">
        <div style="font-size:64px;margin-bottom:16px;">📭</div>
        <h3 class="mb-12" style="font-size:24px ; color:var(--aColor) ; font-weight:700">暂无线报数据</h3>
        <p style="color:var(--lightColor);margin-bottom:24px;font-size:15px;">线报暂未更新，请稍后再来查看。</p>
      </div>
    {/if}

  </div>
  {include file="app/index/view/public/sidebar"}
</div>

{include file="app/index/view/public/footer"}

<script>
document.addEventListener('click', function (e) {
  var btn = e.target.closest && e.target.closest('.tipoff-copy');
  if (!btn) return;
  var text = btn.getAttribute('data-copy') || '';
  var done = function () {
    var old = btn.textContent;
    btn.textContent = '已复制 ✓';
    btn.style.color = '#30b060';
    btn.style.borderColor = '#30b060';
    setTimeout(function () { btn.textContent = old; btn.style.color = ''; btn.style.borderColor = ''; }, 1500);
  };
  if (navigator.clipboard && navigator.clipboard.writeText) {
    navigator.clipboard.writeText(text).then(done, function () { fallbackCopy(text, done); });
  } else {
    fallbackCopy(text, done);
  }
});
function fallbackCopy(text, done) {
  try {
    var ta = document.createElement('textarea');
    ta.value = text; ta.style.position = 'fixed'; ta.style.opacity = '0';
    document.body.appendChild(ta); ta.select();
    document.execCommand('copy'); document.body.removeChild(ta);
    done();
  } catch (err) {}
}
</script>
