<?php
/**
 * SMM Paket Satış Scripti - Makbuz Sayfası
 * @version 1.0.1
 */

require_once __DIR__ . '/config.php';

// Sipariş numarası kontrolü
$orderNumber = $_GET['no'] ?? '';
if (empty($orderNumber)) {
    redirect(SITE_URL);
    exit;
}

// Siparişi çek
try {
    $stmt = $db->prepare("
        SELECT o.*, p.name as package_name, p.quantity as package_quantity,
               c.name as category_name, c.icon as category_icon
        FROM orders o
        LEFT JOIN packages p ON o.package_id = p.id
        LEFT JOIN categories c ON p.category_id = c.id
        WHERE o.order_number = ?
    ");
    $stmt->execute([$orderNumber]);
    $order = $stmt->fetch(PDO::FETCH_ASSOC);
    
    if (!$order) {
        setFlash('error', 'Sipariş bulunamadı.');
        redirect(SITE_URL . '/siparis-sorgula.php');
        exit;
    }
    
    // Makbuz numarası yoksa oluştur ve kaydet
    if (empty($order['invoice_number'])) {
        $invoiceNumber = 'MKB-' . date('Y') . '-' . str_pad($order['id'], 6, '0', STR_PAD_LEFT);
        $db->prepare("UPDATE orders SET invoice_number = ?, invoice_generated_at = NOW() WHERE id = ?")
           ->execute([$invoiceNumber, $order['id']]);
        $order['invoice_number'] = $invoiceNumber;
        $order['invoice_generated_at'] = date('Y-m-d H:i:s');
    }
    
} catch (PDOException $e) {
    setFlash('error', 'Bir hata oluştu.');
    redirect(SITE_URL);
    exit;
}

// Durum bilgileri
$statusInfo = [
    'pending' => ['text' => 'Ödeme Bekleniyor', 'color' => '#f59e0b', 'icon' => 'fas fa-clock', 'bg' => '#fef3c7'],
    'paid' => ['text' => 'Ödeme Alındı', 'color' => '#3b82f6', 'icon' => 'fas fa-credit-card', 'bg' => '#dbeafe'],
    'processing' => ['text' => 'İşleniyor', 'color' => '#8b5cf6', 'icon' => 'fas fa-cog', 'bg' => '#ede9fe'],
    'completed' => ['text' => 'Tamamlandı', 'color' => '#10b981', 'icon' => 'fas fa-check-circle', 'bg' => '#d1fae5'],
    'cancelled' => ['text' => 'İptal Edildi', 'color' => '#ef4444', 'icon' => 'fas fa-times-circle', 'bg' => '#fee2e2'],
    'refunded' => ['text' => 'İade Edildi', 'color' => '#6b7280', 'icon' => 'fas fa-undo', 'bg' => '#f3f4f6'],
    'partial' => ['text' => 'Kısmi Tamamlandı', 'color' => '#f97316', 'icon' => 'fas fa-adjust', 'bg' => '#ffedd5'],
];

$currentStatus = $statusInfo[$order['status']] ?? $statusInfo['pending'];

// Ödeme yöntemi
$paymentMethods = [
    'bank_transfer' => ['text' => 'Havale/EFT', 'icon' => 'fas fa-university'],
    'credit_card' => ['text' => 'Kredi Kartı', 'icon' => 'fas fa-credit-card'],
    'papara' => ['text' => 'Papara', 'icon' => 'fas fa-wallet'],
    'crypto' => ['text' => 'Kripto Para', 'icon' => 'fab fa-bitcoin'],
];
$paymentMethod = $paymentMethods[$order['payment_method']] ?? ['text' => $order['payment_method'], 'icon' => 'fas fa-money-bill'];

// Site bilgileri
$siteName = $settings->get('site_name', 'SMM Panel');
$siteLogo = $settings->getLogoUrl();
$siteEmail = $settings->get('contact_email', '');
$sitePhone = $settings->get('contact_phone', '');
$siteAddress = $settings->get('contact_address', '');

// Tarihler
$orderDate = date('d.m.Y H:i', strtotime($order['created_at']));
$paidDate = $order['paid_at'] ? date('d.m.Y H:i', strtotime($order['paid_at'])) : null;
$completedDate = $order['completed_at'] ? date('d.m.Y H:i', strtotime($order['completed_at'])) : null;

// QR Kod
$qrLink = SITE_URL . '/siparis-sorgula.php?no=' . urlencode($order['order_number']);
$qrCodeUrl = 'https://api.qrserver.com/v1/create-qr-code/?size=100x100&data=' . urlencode($qrLink);

// Her zaman makbuz
$documentTitle = 'MAKBUZ';

$pageTitle = $documentTitle . ' - ' . $order['order_number'];
?>
<!DOCTYPE html>
<html lang="tr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?php echo clean($pageTitle); ?> | <?php echo clean($siteName); ?></title>
    
    <?php if ($settings->getFaviconUrl()): ?>
    <link rel="icon" href="<?php echo clean($settings->getFaviconUrl()); ?>">
    <?php endif; ?>
    
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
    
    <style>
    * { margin: 0; padding: 0; box-sizing: border-box; }
    
    body {
        font-family: 'Inter', sans-serif;
        background: #f1f5f9;
        color: #1e293b;
        line-height: 1.6;
        padding: 20px;
        min-height: 100vh;
    }
    
    .invoice-wrapper {
        max-width: 800px;
        margin: 0 auto;
    }
    
    .invoice-container {
        background: #fff;
        border-radius: 16px;
        box-shadow: 0 10px 40px rgba(0,0,0,0.1);
        overflow: hidden;
        position: relative;
    }
    
    /* Watermark */
    .watermark {
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%) rotate(-30deg);
        font-size: 120px;
        font-weight: 900;
        opacity: 0.04;
        pointer-events: none;
        white-space: nowrap;
        z-index: 1;
    }
    
    /* Header */
    .invoice-header {
        background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
        color: #fff;
        padding: 35px 40px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        position: relative;
        z-index: 2;
    }
    
    .invoice-logo img {
        height: 45px;
        object-fit: contain;
    }
    
    .invoice-logo-text {
        font-size: 24px;
        font-weight: 800;
        display: flex;
        align-items: center;
        gap: 10px;
    }
    
    .invoice-logo-text i {
        color: #6366f1;
    }
    
    .invoice-title {
        text-align: right;
    }
    
    .invoice-title h1 {
        font-size: 28px;
        font-weight: 800;
        letter-spacing: 3px;
        margin-bottom: 5px;
    }
    
    .invoice-title .invoice-number {
        font-size: 13px;
        opacity: 0.8;
        font-family: monospace;
    }
    
    /* Status Banner */
    .status-banner {
        padding: 14px 40px;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 10px;
        font-weight: 700;
        font-size: 13px;
        text-transform: uppercase;
        letter-spacing: 1px;
        position: relative;
        z-index: 2;
    }
    
    /* Content */
    .invoice-content {
        position: relative;
        z-index: 2;
    }
    
    /* Info Grid */
    .info-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 30px;
        padding: 35px 40px;
        border-bottom: 1px solid #e2e8f0;
    }
    
    .info-box {
        background: #f8fafc;
        border-radius: 12px;
        padding: 20px;
    }
    
    .info-box h4 {
        font-size: 10px;
        text-transform: uppercase;
        letter-spacing: 1.5px;
        color: #64748b;
        margin-bottom: 15px;
        font-weight: 700;
        display: flex;
        align-items: center;
        gap: 8px;
    }
    
    .info-box h4 i {
        color: #6366f1;
    }
    
    .info-row {
        display: flex;
        justify-content: space-between;
        padding: 8px 0;
        font-size: 13px;
        border-bottom: 1px dashed #e2e8f0;
    }
    
    .info-row:last-child {
        border-bottom: none;
    }
    
    .info-row .label {
        color: #64748b;
    }
    
    .info-row .value {
        font-weight: 600;
        color: #1e293b;
        text-align: right;
        max-width: 60%;
        word-break: break-word;
    }
    
    /* Order Details */
    .order-section {
        padding: 35px 40px;
        border-bottom: 1px solid #e2e8f0;
    }
    
    .section-title {
        font-size: 14px;
        font-weight: 700;
        margin-bottom: 20px;
        display: flex;
        align-items: center;
        gap: 10px;
        color: #1e293b;
    }
    
    .section-title i {
        color: #6366f1;
        font-size: 16px;
    }
    
    /* Package Card */
    .package-card {
        background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
        border: 1px solid #e2e8f0;
        border-radius: 12px;
        padding: 20px;
        display: flex;
        align-items: center;
        gap: 20px;
    }
    
    .package-icon {
        width: 60px;
        height: 60px;
        background: linear-gradient(135deg, #6366f1, #8b5cf6);
        border-radius: 14px;
        display: flex;
        align-items: center;
        justify-content: center;
        color: #fff;
        font-size: 24px;
        flex-shrink: 0;
    }
    
    .package-info {
        flex: 1;
    }
    
    .package-name {
        font-size: 16px;
        font-weight: 700;
        color: #1e293b;
        margin-bottom: 4px;
    }
    
    .package-category {
        font-size: 12px;
        color: #64748b;
        display: flex;
        align-items: center;
        gap: 6px;
    }
    
    .package-quantity {
        font-size: 13px;
        color: #6366f1;
        font-weight: 600;
        margin-top: 6px;
    }
    
    .package-price {
        text-align: right;
    }
    
    .package-price .amount {
        font-size: 22px;
        font-weight: 800;
        color: #1e293b;
    }
    
    .package-price .label {
        font-size: 11px;
        color: #64748b;
    }
    
    /* Link Box */
    .link-box {
        background: #eff6ff;
        border: 1px solid #dbeafe;
        border-radius: 10px;
        padding: 15px 20px;
        margin-top: 20px;
    }
    
    .link-box h5 {
        font-size: 11px;
        text-transform: uppercase;
        letter-spacing: 1px;
        color: #3b82f6;
        margin-bottom: 8px;
        font-weight: 700;
    }
    
    .link-box p {
        font-size: 13px;
        color: #1e40af;
        word-break: break-all;
        font-family: monospace;
    }
    
    /* Summary */
    .summary-section {
        padding: 30px 40px;
        background: #f8fafc;
    }
    
    .summary-table {
        max-width: 350px;
        margin-left: auto;
    }
    
    .summary-row {
        display: flex;
        justify-content: space-between;
        padding: 10px 0;
        font-size: 14px;
    }
    
    .summary-row .label {
        color: #64748b;
    }
    
    .summary-row .value {
        font-weight: 600;
        color: #1e293b;
    }
    
    .summary-row.discount .value {
        color: #ef4444;
    }
    
    .summary-row.total {
        border-top: 2px solid #e2e8f0;
        margin-top: 10px;
        padding-top: 15px;
    }
    
    .summary-row.total .label {
        font-size: 16px;
        font-weight: 700;
        color: #1e293b;
    }
    
    .summary-row.total .value {
        font-size: 22px;
        font-weight: 800;
        color: #10b981;
    }
    
    /* Timeline */
    .timeline-section {
        padding: 30px 40px;
        border-top: 1px solid #e2e8f0;
    }
    
    .timeline {
        display: flex;
        justify-content: space-between;
        position: relative;
    }
    
    .timeline::before {
        content: '';
        position: absolute;
        top: 20px;
        left: 40px;
        right: 40px;
        height: 2px;
        background: #e2e8f0;
    }
    
    .timeline-item {
        text-align: center;
        position: relative;
        z-index: 1;
    }
    
    .timeline-icon {
        width: 40px;
        height: 40px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        margin: 0 auto 10px;
        font-size: 14px;
    }
    
    .timeline-icon.active {
        background: #10b981;
        color: #fff;
    }
    
    .timeline-icon.pending {
        background: #e2e8f0;
        color: #94a3b8;
    }
    
    .timeline-icon.current {
        background: #3b82f6;
        color: #fff;
        animation: pulse 2s infinite;
    }
    
    @keyframes pulse {
        0%, 100% { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.4); }
        50% { box-shadow: 0 0 0 10px rgba(59, 130, 246, 0); }
    }
    
    .timeline-text {
        font-size: 11px;
        color: #64748b;
        font-weight: 600;
    }
    
    .timeline-date {
        font-size: 10px;
        color: #94a3b8;
        margin-top: 4px;
    }
    
    /* Notes */
    .notes-section {
        padding: 25px 40px;
        background: #fffbeb;
        border-top: 1px solid #fef3c7;
    }
    
    .notes-section h4 {
        font-size: 11px;
        text-transform: uppercase;
        letter-spacing: 1px;
        color: #d97706;
        margin-bottom: 8px;
        font-weight: 700;
        display: flex;
        align-items: center;
        gap: 8px;
    }
    
    .notes-section p {
        font-size: 13px;
        color: #92400e;
    }
    
    /* Footer */
    .invoice-footer {
        padding: 30px 40px;
        display: flex;
        justify-content: space-between;
        align-items: flex-end;
        border-top: 1px solid #e2e8f0;
    }
    
    .footer-info h5 {
        font-size: 10px;
        text-transform: uppercase;
        letter-spacing: 1px;
        color: #64748b;
        margin-bottom: 10px;
        font-weight: 700;
    }
    
    .footer-info p {
        font-size: 12px;
        color: #64748b;
        margin-bottom: 4px;
        display: flex;
        align-items: center;
        gap: 8px;
    }
    
    .footer-info a {
        color: #6366f1;
        text-decoration: none;
    }
    
    .footer-qr {
        text-align: center;
    }
    
    .footer-qr img {
        width: 70px;
        height: 70px;
        border-radius: 8px;
        border: 1px solid #e2e8f0;
    }
    
    .footer-qr p {
        font-size: 9px;
        color: #94a3b8;
        margin-top: 6px;
    }
    
    /* Print Actions */
    .print-actions {
        display: flex;
        justify-content: center;
        gap: 12px;
        margin-top: 25px;
        padding: 0 20px;
    }
    
    .btn-action {
        padding: 12px 24px;
        border: none;
        border-radius: 10px;
        font-size: 14px;
        font-weight: 600;
        cursor: pointer;
        display: flex;
        align-items: center;
        gap: 8px;
        transition: all 0.2s;
        text-decoration: none;
    }
    
    .btn-print {
        background: linear-gradient(135deg, #6366f1, #8b5cf6);
        color: #fff;
        box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
    }
    
    .btn-print:hover {
        transform: translateY(-2px);
        box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
    }
    
    .btn-back {
        background: #fff;
        color: #64748b;
        border: 1px solid #e2e8f0;
    }
    
    .btn-back:hover {
        background: #f8fafc;
        color: #1e293b;
    }
    
    /* Responsive */
    @media (max-width: 768px) {
        body { padding: 10px; }
        
        .invoice-header {
            flex-direction: column;
            text-align: center;
            gap: 20px;
            padding: 25px 20px;
        }
        
        .invoice-title { text-align: center; }
        
        .info-grid {
            grid-template-columns: 1fr;
            padding: 25px 20px;
        }
        
        .order-section,
        .summary-section,
        .timeline-section,
        .invoice-footer {
            padding-left: 20px;
            padding-right: 20px;
        }
        
        .package-card {
            flex-direction: column;
            text-align: center;
        }
        
        .package-price {
            text-align: center;
            margin-top: 15px;
        }
        
        .timeline {
            flex-direction: column;
            gap: 15px;
        }
        
        .timeline::before {
            display: none;
        }
        
        .timeline-item {
            display: flex;
            align-items: center;
            gap: 15px;
            text-align: left;
        }
        
        .timeline-icon {
            margin: 0;
        }
        
        .invoice-footer {
            flex-direction: column;
            gap: 25px;
            align-items: center;
            text-align: center;
        }
        
        .summary-table {
            margin: 0 auto;
        }
        
        .watermark {
            font-size: 60px;
        }
    }
    
    /* Print Styles */
    @media print {
        body {
            background: #fff;
            padding: 0;
            -webkit-print-color-adjust: exact !important;
            print-color-adjust: exact !important;
        }
        
        .invoice-wrapper {
            max-width: 100%;
        }
        
        .invoice-container {
            box-shadow: none;
            border-radius: 0;
        }
        
        .print-actions {
            display: none !important;
        }
        
        .invoice-header,
        .status-banner,
        .package-icon,
        .timeline-icon {
            -webkit-print-color-adjust: exact !important;
            print-color-adjust: exact !important;
        }
    }
    </style>
</head>
<body>

<div class="invoice-wrapper">
    <div class="invoice-container">
        <!-- Watermark -->
        <?php if (in_array($order['status'], ['cancelled', 'refunded'])): ?>
        <div class="watermark" style="color: <?php echo $currentStatus['color']; ?>;">
            <?php echo $currentStatus['text']; ?>
        </div>
        <?php endif; ?>
        
        <!-- Header -->
        <div class="invoice-header">
            <div class="invoice-logo">
                <?php if ($siteLogo): ?>
                    <img src="<?php echo clean($siteLogo); ?>" alt="<?php echo clean($siteName); ?>">
                <?php else: ?>
                    <div class="invoice-logo-text">
                        <i class="fas fa-bolt"></i>
                        <?php echo clean($siteName); ?>
                    </div>
                <?php endif; ?>
            </div>
            <div class="invoice-title">
                <h1><?php echo $documentTitle; ?></h1>
                <div class="invoice-number"><?php echo clean($order['invoice_number']); ?></div>
            </div>
        </div>
        
        <!-- Status Banner -->
        <div class="status-banner" style="background: <?php echo $currentStatus['bg']; ?>; color: <?php echo $currentStatus['color']; ?>;">
            <i class="<?php echo $currentStatus['icon']; ?>"></i>
            <?php echo $currentStatus['text']; ?>
        </div>
        
        <div class="invoice-content">
            <!-- Info Grid -->
            <div class="info-grid">
                <!-- Müşteri Bilgileri -->
                <div class="info-box">
                    <h4><i class="fas fa-user"></i> Müşteri Bilgileri</h4>
                    <div class="info-row">
                        <span class="label">Ad Soyad</span>
                        <span class="value"><?php echo clean($order['customer_name']); ?></span>
                    </div>
                    <div class="info-row">
                        <span class="label">E-posta</span>
                        <span class="value"><?php echo clean($order['customer_email']); ?></span>
                    </div>
                    <?php if ($order['customer_phone']): ?>
                    <div class="info-row">
                        <span class="label">Telefon</span>
                        <span class="value"><?php echo clean($order['customer_phone']); ?></span>
                    </div>
                    <?php endif; ?>
                    <?php if ($order['social_media_username']): ?>
                    <div class="info-row">
                        <span class="label">Kullanıcı Adı</span>
                        <span class="value">@<?php echo clean($order['social_media_username']); ?></span>
                    </div>
                    <?php endif; ?>
                </div>
                
                <!-- Sipariş Bilgileri -->
                <div class="info-box">
                    <h4><i class="fas fa-file-invoice"></i> Sipariş Bilgileri</h4>
                    <div class="info-row">
                        <span class="label">Sipariş No</span>
                        <span class="value"><?php echo clean($order['order_number']); ?></span>
                    </div>
                    <div class="info-row">
                        <span class="label">Sipariş Tarihi</span>
                        <span class="value"><?php echo $orderDate; ?></span>
                    </div>
                    <div class="info-row">
                        <span class="label">Ödeme Yöntemi</span>
                        <span class="value">
                            <i class="<?php echo $paymentMethod['icon']; ?>" style="margin-right: 5px;"></i>
                            <?php echo $paymentMethod['text']; ?>
                        </span>
                    </div>
                    <?php if ($order['api_order_id']): ?>
                    <div class="info-row">
                        <span class="label">API Sipariş ID</span>
                        <span class="value">#<?php echo clean($order['api_order_id']); ?></span>
                    </div>
                    <?php endif; ?>
                </div>
            </div>
            
            <!-- Package Details -->
            <div class="order-section">
                <h3 class="section-title"><i class="fas fa-box"></i> Sipariş Detayı</h3>
                
                <div class="package-card">
                    <div class="package-icon">
                        <i class="<?php echo clean($order['category_icon'] ?? 'fas fa-box'); ?>"></i>
                    </div>
                    <div class="package-info">
                        <div class="package-name"><?php echo clean($order['package_name']); ?></div>
                        <div class="package-category">
                            <i class="fas fa-folder"></i>
                            <?php echo clean($order['category_name'] ?? 'Genel'); ?>
                        </div>
                        <?php if ($order['package_quantity']): ?>
                        <div class="package-quantity">
                            <i class="fas fa-cubes"></i>
                            <?php echo number_format($order['package_quantity'], 0, ',', '.'); ?> Adet
                        </div>
                        <?php endif; ?>
                    </div>
                    <div class="package-price">
                        <div class="label">Birim Fiyat</div>
                        <div class="amount"><?php echo formatMoney($order['amount'] + $order['discount_amount']); ?></div>
                    </div>
                </div>
                
                <!-- Link Box -->
                <?php if ($order['social_media_link']): ?>
                <div class="link-box">
                    <h5><i class="fas fa-link"></i> Hedef Link / Kullanıcı</h5>
                    <p><?php echo clean($order['social_media_link']); ?></p>
                </div>
                <?php endif; ?>
            </div>
            
            <!-- Summary -->
            <div class="summary-section">
                <div class="summary-table">
                    <div class="summary-row">
                        <span class="label">Ara Toplam</span>
                        <span class="value"><?php echo formatMoney($order['amount'] + $order['discount_amount']); ?></span>
                    </div>
                    
                    <?php if ($order['discount_amount'] > 0): ?>
                    <div class="summary-row discount">
                        <span class="label">
                            İndirim
                            <?php if ($order['coupon_code']): ?>
                            <small>(<?php echo clean($order['coupon_code']); ?>)</small>
                            <?php endif; ?>
                        </span>
                        <span class="value">-<?php echo formatMoney($order['discount_amount']); ?></span>
                    </div>
                    <?php endif; ?>
                    
                    <?php if ($order['kdv_amount'] && $order['kdv_amount'] > 0): ?>
                    <div class="summary-row">
                        <span class="label">KDV (%<?php echo (int)$order['kdv_rate']; ?>)</span>
                        <span class="value"><?php echo formatMoney($order['kdv_amount']); ?></span>
                    </div>
                    <?php endif; ?>
                    
                    <div class="summary-row total">
                        <span class="label">Toplam</span>
                        <span class="value"><?php echo formatMoney($order['amount']); ?></span>
                    </div>
                </div>
            </div>
            
            <!-- Timeline -->
            <div class="timeline-section">
                <h3 class="section-title"><i class="fas fa-history"></i> Sipariş Durumu</h3>
                
                <div class="timeline">
                    <?php
                    $steps = [
                        ['key' => 'created', 'icon' => 'fas fa-plus', 'text' => 'Oluşturuldu', 'date' => $orderDate],
                        ['key' => 'paid', 'icon' => 'fas fa-credit-card', 'text' => 'Ödeme', 'date' => $paidDate],
                        ['key' => 'processing', 'icon' => 'fas fa-cog', 'text' => 'İşleniyor', 'date' => null],
                        ['key' => 'completed', 'icon' => 'fas fa-check', 'text' => 'Tamamlandı', 'date' => $completedDate],
                    ];
                    
                    $statusOrder = ['pending' => 0, 'paid' => 1, 'processing' => 2, 'completed' => 3, 'cancelled' => -1, 'refunded' => -1, 'partial' => 2];
                    $currentStep = $statusOrder[$order['status']] ?? 0;
                    
                    foreach ($steps as $index => $step):
                        $isActive = $index < $currentStep;
                        $isCurrent = $index == $currentStep;
                        $iconClass = $isActive ? 'active' : ($isCurrent ? 'current' : 'pending');
                    ?>
                    <div class="timeline-item">
                        <div class="timeline-icon <?php echo $iconClass; ?>">
                            <i class="<?php echo $step['icon']; ?>"></i>
                        </div>
                        <div>
                            <div class="timeline-text"><?php echo $step['text']; ?></div>
                            <?php if ($step['date']): ?>
                            <div class="timeline-date"><?php echo $step['date']; ?></div>
                            <?php endif; ?>
                        </div>
                    </div>
                    <?php endforeach; ?>
                </div>
            </div>
            
            <!-- Notes -->
            <?php if ($order['customer_note'] || $order['admin_note']): ?>
            <div class="notes-section">
                <?php if ($order['customer_note']): ?>
                <h4><i class="fas fa-comment"></i> Müşteri Notu</h4>
                <p><?php echo nl2br(clean($order['customer_note'])); ?></p>
                <?php endif; ?>
                
                <?php if ($order['admin_note'] && (isLoggedIn() && isAdmin())): ?>
                <h4 style="margin-top: 15px;"><i class="fas fa-user-shield"></i> Admin Notu</h4>
                <p><?php echo nl2br(clean($order['admin_note'])); ?></p>
                <?php endif; ?>
            </div>
            <?php endif; ?>
            
            <!-- Footer -->
            <div class="invoice-footer">
                <div class="footer-info">
                    <h5>İletişim Bilgileri</h5>
                    <?php if ($siteEmail): ?>
                    <p><i class="fas fa-envelope"></i> <a href="mailto:<?php echo clean($siteEmail); ?>"><?php echo clean($siteEmail); ?></a></p>
                    <?php endif; ?>
                    <?php if ($sitePhone): ?>
                    <p><i class="fas fa-phone"></i> <?php echo clean($sitePhone); ?></p>
                    <?php endif; ?>
                    <?php if ($siteAddress): ?>
                    <p><i class="fas fa-map-marker-alt"></i> <?php echo clean($siteAddress); ?></p>
                    <?php endif; ?>
                    <p><i class="fas fa-globe"></i> <a href="<?php echo SITE_URL; ?>"><?php echo SITE_URL; ?></a></p>
                </div>
                
                <div class="footer-qr">
                    <img src="<?php echo $qrCodeUrl; ?>" alt="QR Kod">
                    <p>Sipariş Sorgula</p>
                </div>
            </div>
        </div>
    </div>
    
    <!-- Print Actions -->
    <div class="print-actions">
        <button onclick="window.print();" class="btn-action btn-print">
            <i class="fas fa-print"></i>
            <span>Yazdır / PDF</span>
        </button>
        <a href="<?php echo SITE_URL; ?>/siparis-sorgula.php?no=<?php echo urlencode($order['order_number']); ?>" class="btn-action btn-back">
            <i class="fas fa-arrow-left"></i>
            <span>Geri Dön</span>
        </a>
    </div>
</div>

</body>
</html>