<?php defined('ABSPATH') || exit;
$S=\DZQCOD\Core::ST; $queue=\DZQCOD\Core::i()->get_call_queue(30);
$oc=['confirmed'=>['l'=>'✅ مؤكد','c'=>'#27ae60'],'callback'=>['l'=>'📞 معاودة','c'=>'#e67e22'],'no-answer'=>['l'=>'❌ لا يجيب','c'=>'#95a5a6'],'cancelled'=>['l'=>'🚫 ملغي','c'=>'#e74c3c'],'fake'=>['l'=>'⚠️ مزيف','c'=>'#2c3e50'],'postponed'=>['l'=>'⏰ مؤجل','c'=>'#d35400'],'duplicate'=>['l'=>'📋 مكرر','c'=>'#8e44ad']]; ?>
<div class="wrap dza-wrap" dir="rtl">
<div class="dza-header"><h1>مركز الاتصال <span><?php echo (int)count($queue); ?> في الانتظار</span></h1></div>
<?php include __DIR__.'/nav.php'; ?>
<div class="dza-content">
<?php if(empty($queue)): ?><div class="dza-empty">🎉 لا توجد طلبات في الانتظار!</div>
<?php else: foreach($queue as $q): $sc=$S[$q['status']]??['c'=>'#999','l'=>$q['status'],'i'=>'']; ?>
<div class="dza-call-card" style="border-right:4px solid <?php echo esc_html($sc['c']); ?>">
<div class="dza-call-info">
<div class="dza-call-head"><a href="<?php echo esc_url(admin_url('post.php?post='.$q['id'].'&action=edit')); ?>" class="oid">#<?php echo esc_html($q['id']); ?></a>
<span class="dza-badge" style="background:<?php echo esc_html($sc['c']); ?>"><?php echo esc_html($sc['l']); ?></span>
<?php if($q['attempts']): ?><small>📞 محاولة <?php echo esc_html($q['attempts']); ?></small><?php endif; ?>
<?php if($q['fraud']>=50): ?><span class="dza-badge" style="background:#e74c3c">🛡️ <?php echo esc_html($q['fraud']); ?>%</span><?php endif; ?>
</div>
<div class="dza-call-details"><strong><?php echo esc_html($q['name']); ?></strong> —
<a href="tel:<?php echo esc_html($q['phone']); ?>" class="phone"><?php echo esc_html($q['phone']); ?></a>
<?php if($q['phone2']): ?> | <a href="tel:<?php echo esc_html($q['phone2']); ?>" class="phone"><?php echo esc_html($q['phone2']); ?></a><?php endif; ?><br>
📍 <?php echo esc_html($q['wilaya'].' - '.$q['commune']); ?> — 🛒 <?php echo esc_html($q['items']); ?> — 💰 <strong><?php echo number_format((float)$q['total'],0); ?> دج</strong>
<?php if($q['color']): ?> — 🎨 <?php echo esc_html($q['color']); ?><?php endif; ?>
<?php if($q['size']): ?> — 📐 <?php echo esc_html($q['size']); ?><?php endif; ?>
<?php if($q['digital']): ?><br><span class="dza-badge" style="background:#2196F3">💾 منتج رقمي</span><?php endif; ?>
<?php if($q['payment']!=='COD'): ?><span class="dza-badge" style="background:#6C63FF">💳 <?php echo esc_html($q['payment']); ?></span><?php endif; ?>
<?php
    $o_obj = wc_get_order($q['id']);
    $cb_slot = $o_obj ? $o_obj->get_meta('_dzqcod_callback_slot_label') : '';
    $otp_confirmed = $o_obj ? $o_obj->get_meta('_dzqcod_otp_confirmed') : '';
?>
<?php if($otp_confirmed === 'yes'): ?><br><span class="dza-badge" style="background:#22c55e">✅ مؤكد OTP</span><?php endif; ?>
<?php if($cb_slot): ?><br><span class="dza-badge" style="background:#6366f1">📞 يفضل: <?php echo esc_html($cb_slot); ?></span><?php endif; ?>
<?php if($q['notes']): ?><br><small style="color:#e67e22">📝 <?php echo esc_html($q['notes']); ?></small><?php endif; ?></div></div>
<div class="dza-call-actions"><div class="dza-outcome-btns">
<?php foreach($oc as $k=>$v): ?><button class="dza-btn sm log-call" data-id="<?php echo esc_html($q['id']); ?>" data-outcome="<?php echo esc_html($k); ?>" style="background:<?php echo esc_html($v['c']); ?>;color:#fff"><?php echo esc_html($v['l']); ?></button><?php endforeach; ?>
</div><input type="text" class="call-notes" data-id="<?php echo esc_html($q['id']); ?>" placeholder="ملاحظات..." style="margin-top:6px;width:100%;padding:6px;border:1px solid #ddd;border-radius:6px;font-size:12px"></div></div>
<?php endforeach; endif; ?></div></div>
</div><!--dza-main-->
</div><!--dza-layout-->
