<?php include __DIR__ . '/../layout/header.php'; ?>

<?php ob_start(); ?>
<div style="text-align: center; padding-top: 20px; padding-bottom: 20px;">
    <div style="width: 80px; height: 80px; background-color: rgba(16, 185, 129, 0.1); color: var(--color-success); border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 40px; margin: 0 auto 20px;">
        <i class="fa fa-check-circle"></i>
    </div>
    
    <h2 style="font-size: 26px; font-weight: 700; margin-bottom: 10px;">Siparişiniz Alındı!</h2>
    <p style="color: var(--text-secondary); font-size: 15px; margin-bottom: 25px;">
        Siparişiniz başarıyla sisteme kaydedilmiştir. Satış temsilcimiz en kısa sürede sizinle iletişime geçecektir.
    </p>

    <div style="background-color: var(--bg-secondary); border: 1px solid var(--border-color); border-radius: var(--radius-md); padding: 20px; margin-bottom: 30px; text-align: left; font-size: 14px;">
        <div style="margin-bottom: 8px;"><strong>Sipariş Kodu:</strong> <code style="background-color: var(--bg-accent); padding: 2px 6px; border-radius: 4px;"><?php echo $orderId; ?></code></div>
        <p style="color: var(--text-secondary);">Herhangi bir sorunuz olursa lütfen <strong><?php echo \App\Models\Settings::get('telephone'); ?></strong> numaralı telefondan bizimle irtibata geçiniz.</p>
    </div>

    <?php if (isset($order) && $order->payment_method === 'bank_transfer'): ?>
    <div style="background-color: rgba(245, 158, 11, 0.1); border: 1px solid #f59e0b; border-radius: var(--radius-md); padding: 20px; margin-bottom: 30px; text-align: left; font-size: 14px;">
        <h3 style="color: #d97706; margin-top: 0; margin-bottom: 10px; font-size: 16px;"><i class="fa fa-exclamation-triangle"></i> Önemli Hatırlatma</h3>
        <p style="color: var(--text-1); margin-bottom: 10px;">
            Siparişinizi Havale/EFT ödeme yöntemiyle oluşturdunuz. Siparişinizin iptal edilmemesi için lütfen ödemenizi tamamladıktan sonra dekontunuzu yükleyiniz.
        </p>
        <p style="color: var(--text-1); font-weight: 600; margin: 0;">
            Dekontunuzu Profil > Siparişlerim menüsünden veya aşağıdaki "Siparişi Görüntüle ve Dekont Yükle" butonuna tıklayarak yükleyebilirsiniz.
        </p>
        <div style="margin-top: 15px;">
            <a href="<?php echo $baseUrl; ?>/profile/orders/<?php echo $orderId; ?>" style="display: inline-flex; align-items: center; justify-content: center; gap: 8px; background: #f59e0b; color: #fff; border: none; border-radius: var(--r-sm); padding: 10px 20px; font-size: 14px; font-weight: 600; cursor: pointer; text-decoration: none;">
                <i class="fa fa-upload"></i> Siparişi Görüntüle ve Dekont Yükle
            </a>
        </div>
    </div>
    <?php endif; ?>

    <a href="<?php echo $baseUrl; ?>/" style="display: inline-flex; align-items: center; justify-content: center; gap: 10px; background: var(--orange); color: #fff; border: none; border-radius: var(--r-md); padding: 14px 28px; font-size: 16px; font-weight: 600; cursor: pointer; text-decoration: none; margin-top: 10px;">
        <i class="fa fa-home"></i> Ana Sayfaya Dön
    </a>
</div>
<?php $successHtml = ob_get_clean(); ?>

<?php if (isset($user) && $user): ?>
<style>
/* CSS copied from profile.php */
.account-wrapper { max-width: var(--max-w); margin: 40px auto; padding: 0 20px; display: grid; grid-template-columns: 280px 1fr; gap: 30px; align-items: start; }
@media (max-width: 900px) { .account-wrapper { grid-template-columns: 1fr; } }
.account-sidebar { background: var(--surface-card); border-radius: var(--r-lg); box-shadow: var(--shadow-card); border: 1px solid var(--border); overflow: hidden; }
.sidebar-user { padding: 30px 20px; text-align: center; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.sidebar-avatar { width: 80px; height: 80px; border-radius: 50%; object-fit: cover; margin: 0 auto 15px auto; border: 2px solid var(--orange); box-shadow: var(--shadow-glow); }
.sidebar-avatar-placeholder { width: 80px; height: 80px; border-radius: 50%; background: var(--orange); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 32px; font-weight: 700; margin: 0 auto 15px auto; box-shadow: var(--shadow-glow); }
.sidebar-user h3 { font-size: 18px; color: var(--text-1); margin: 0 0 5px 0; }
.sidebar-user p { font-size: 13px; color: var(--text-3); margin: 0; }
.sidebar-menu { list-style: none; padding: 10px 0; margin: 0; }
.sidebar-menu li { margin: 0; }
.sidebar-menu a { display: flex; align-items: center; gap: 15px; padding: 15px 25px; color: var(--text-2); font-size: 15px; font-weight: 500; transition: all 0.3s ease; border-left: 3px solid transparent; }
.sidebar-menu a:hover { background: var(--surface-2); color: var(--text-1); }
.sidebar-menu a.active { background: var(--surface-2); color: var(--orange); border-left-color: var(--orange); }
.sidebar-menu a i { width: 20px; text-align: center; font-size: 18px; }
.account-content { background: var(--surface-card); border-radius: var(--r-lg); box-shadow: var(--shadow-card); border: 1px solid var(--border); padding: 40px; }
@media (max-width: 768px) { .account-content { padding: 24px; } }
</style>

<div class="account-wrapper">
    <aside class="account-sidebar">
        <div class="sidebar-user">
            <?php if (!empty($user->avatar)): ?>
                <img src="<?php echo htmlspecialchars($user->avatar); ?>" alt="Profil Resmi" referrerpolicy="no-referrer" class="sidebar-avatar">
            <?php else: ?>
                <div class="sidebar-avatar-placeholder">
                    <?php echo mb_substr(mb_strtoupper(htmlspecialchars($user->name), 'UTF-8'), 0, 1, 'UTF-8'); ?>
                </div>
            <?php endif; ?>
            <h3><?php echo htmlspecialchars($user->name); ?></h3>
            <p>Müşteri Hesabı</p>
        </div>
        <ul class="sidebar-menu">
            <li>
                <a href="<?php echo $baseUrl; ?>/profile">
                    <i class="fa fa-user"></i> Hesap Bilgilerim
                </a>
            </li>
            <li>
                <a href="<?php echo $baseUrl; ?>/profile/orders">
                    <i class="fa fa-shopping-bag"></i> Siparişlerim
                </a>
            </li>
            <li>
                <a href="<?php echo $baseUrl; ?>/cart">
                    <i class="fa fa-shopping-cart"></i> Sepetim
                </a>
            </li>
            <li>
                <a href="<?php echo $baseUrl; ?>/logout" style="color: #ef4444; margin-top: 10px; border-top: 1px solid var(--border);">
                    <i class="fa fa-sign-out"></i> Çıkış Yap
                </a>
            </li>
        </ul>
    </aside>
    <main class="account-content">
        <?php echo $successHtml; ?>
    </main>
</div>
<?php else: ?>
<div class="container" style="max-width: 600px; margin: 40px auto; background-color: var(--surface-card); border: 1px solid var(--border); border-radius: var(--r-lg); padding: 40px;">
    <?php echo $successHtml; ?>
</div>
<?php endif; ?>

<?php include __DIR__ . '/../layout/footer.php'; ?>
