<?php
/**
 * views/wisatawan/payment_failed.php
 * Halaman Gagal Pembayaran
 */
$activeMenu = 'riwayatPesanan';
$pageTitle = 'Pembayaran Gagal - Wisatawan';
include __DIR__ . '/../layouts/header.php';

$pesanan = $pesanan ?? [];
$orderId = $_GET['order_id'] ?? '';
$errorMessage = $_GET['message'] ?? 'Pembayaran gagal diproses. Silakan coba lagi.';
?>

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css">

<div class="dashboard-wrapper">
    <?php include __DIR__ . '/../layouts/sidebar_wisatawan.php'; ?>

    <main class="main-content">
        <div class="failed-container">
            <!-- ICON GAGAL -->
            <div class="failed-icon">
                <i class="fas fa-times-circle"></i>
            </div>

            <h1 class="failed-title">❌ Pembayaran Gagal</h1>
            <p class="failed-subtitle"><?= htmlspecialchars($errorMessage) ?></p>

            <!-- DETAIL PESANAN -->
            <?php if(!empty($pesanan)): ?>
            <div class="failed-card">
                <div class="failed-card-header">
                    <i class="fas fa-file-invoice"></i>
                    <span>Detail Pesanan</span>
                </div>
                <div class="failed-card-body">
                    <div class="detail-row">
                        <span class="detail-label">Kode Pesanan</span>
                        <span class="detail-value"><strong><?= htmlspecialchars($pesanan['kode_pesanan']) ?></strong></span>
                    </div>
                    <div class="detail-row">
                        <span class="detail-label">Kapal</span>
                        <span class="detail-value"><?= htmlspecialchars($pesanan['nama_kapal'] ?? '-') ?></span>
                    </div>
                    <div class="detail-row">
                        <span class="detail-label">Total</span>
                        <span class="detail-value harga">Rp <?= number_format($pesanan['total_harga'], 0, ',', '.') ?></span>
                    </div>
                </div>
            </div>
            <?php endif; ?>

            <!-- KEMUNGKINAN PENYEBAB -->
            <div class="info-box warning">
                <div class="info-box-icon">
                    <i class="fas fa-lightbulb"></i>
                </div>
                <div class="info-box-content">
                    <h4>💡 Kemungkinan Penyebab:</h4>
                    <ul>
                        <li>Saldo tidak mencukupi</li>
                        <li>Kartu kredit ditolak</li>
                        <li>Koneksi internet terputus</li>
                        <li>Batas waktu pembayaran habis</li>
                    </ul>
                </div>
            </div>

            <!-- TOMBOL AKSI -->
            <div class="action-buttons">
                <a href="?page=wisatawan&action=pembayaran&id=<?= $pesanan['id'] ?? 0 ?>" class="btn btn-warning btn-lg">
                    <i class="fas fa-redo"></i> Coba Bayar Lagi
                </a>
                <a href="?page=wisatawan&action=pesananSaya" class="btn btn-secondary btn-lg">
                    <i class="fas fa-list"></i> Daftar Pesanan
                </a>
                <a href="?page=wisatawan&action=detailPesanan&id=<?= $pesanan['id'] ?? 0 ?>" class="btn btn-primary btn-lg">
                    <i class="fas fa-eye"></i> Detail Pesanan
                </a>
            </div>

            <!-- CONTACT SUPPORT -->
            <div class="support-box">
                <i class="fas fa-headset"></i>
                <span>Butuh bantuan? Hubungi <strong>Admin</strong> via WhatsApp</span>
            </div>
        </div>
    </main>
</div>

<style>
.dashboard-wrapper {
    display: flex;
    gap: 24px;
    max-width: 1200px;
    margin: 1.5rem auto 0;
    padding: 0 20px;
    width: 100%;
    flex: 1;
    align-items: flex-start;
}

.main-content {
    flex: 1;
    min-width: 0;
    background: #fff;
    border-radius: 14px;
    padding: 2rem;
    box-shadow: 0 4px 20px rgba(0,0,0,0.06);
    border: 1px solid #e2e8f0;
}

.failed-container {
    max-width: 600px;
    margin: 0 auto;
    text-align: center;
}

.failed-icon {
    font-size: 5rem;
    color: #ef4444;
    margin-bottom: 1rem;
    animation: shake 0.8s ease;
}

@keyframes shake {
    0%, 100% { transform: rotate(0); }
    20% { transform: rotate(-15deg); }
    40% { transform: rotate(15deg); }
    60% { transform: rotate(-10deg); }
    80% { transform: rotate(10deg); }
}

.failed-title {
    font-size: 1.8rem;
    font-weight: 700;
    color: #991b1b;
    margin-bottom: 0.3rem;
}

.failed-subtitle {
    font-size: 1rem;
    color: #4a5568;
    margin-bottom: 1.5rem;
}

.failed-card {
    background: #f7fafc;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
    overflow: hidden;
    margin-bottom: 1.5rem;
    text-align: left;
}

.failed-card-header {
    background: #fee2e2;
    padding: 0.8rem 1.2rem;
    font-weight: 600;
    color: #991b1b;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    border-bottom: 1px solid #fca5a5;
}

.failed-card-body {
    padding: 1rem 1.2rem;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    padding: 0.4rem 0;
    border-bottom: 1px solid #edf2f7;
}

.detail-row:last-child {
    border-bottom: none;
}

.detail-label {
    color: #718096;
    font-size: 0.85rem;
}

.detail-value {
    font-size: 0.85rem;
    color: #1a202c;
}

.detail-value.harga {
    font-weight: 700;
    color: #2b6cb0;
    font-size: 1.1rem;
}

/* INFO BOX */
.info-box {
    display: flex;
    gap: 1rem;
    background: #fffbeb;
    border: 1px solid #fcd34d;
    border-radius: 12px;
    padding: 1rem 1.2rem;
    margin-bottom: 1.5rem;
    text-align: left;
}

.info-box.warning {
    background: #fffbeb;
    border-color: #fcd34d;
}

.info-box-icon {
    font-size: 1.5rem;
    color: #92400e;
    flex-shrink: 0;
}

.info-box-content h4 {
    font-size: 0.95rem;
    font-weight: 700;
    color: #92400e;
    margin: 0 0 0.3rem;
}

.info-box-content ul {
    margin: 0;
    padding-left: 1.2rem;
    font-size: 0.85rem;
    color: #92400e;
}

.info-box-content ul li {
    margin-bottom: 0.2rem;
}

/* BUTTONS */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 1.2rem;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

.btn-primary {
    background: #2b6cb0;
    color: #fff;
}

.btn-primary:hover {
    background: #1a4a7a;
    color: #fff;
}

.btn-secondary {
    background: #e2e8f0;
    color: #4a5568;
}

.btn-secondary:hover {
    background: #cbd5e0;
    color: #1a202c;
}

.btn-warning {
    background: #f59e0b;
    color: #fff;
}

.btn-warning:hover {
    background: #d97706;
    color: #fff;
}

.btn-lg {
    padding: 0.7rem 1.5rem;
    font-size: 1rem;
}

.action-buttons {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}

.support-box {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.8rem;
    background: #f1f5f9;
    border-radius: 8px;
    font-size: 0.85rem;
    color: #4a5568;
}

.support-box i {
    font-size: 1.2rem;
    color: #2b6cb0;
}

/* RESPONSIVE */
@media (max-width: 768px) {
    .dashboard-wrapper {
        flex-direction: column;
        padding: 0 12px;
        margin-top: 1rem;
    }
    .main-content {
        padding: 1rem;
    }
    .failed-icon {
        font-size: 3.5rem;
    }
    .failed-title {
        font-size: 1.4rem;
    }
    .action-buttons {
        flex-direction: column;
    }
    .action-buttons .btn {
        width: 100%;
        justify-content: center;
    }
    .detail-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.1rem;
    }
    .info-box {
        flex-direction: column;
        align-items: flex-start;
    }
}

@media (max-width: 480px) {
    .main-content {
        padding: 0.8rem;
    }
    .failed-card-body {
        padding: 0.8rem 1rem;
    }
}
</style>

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