@extends('layouts.app')

@section('title', 'Order #' . $order->order_number . ' - Order Details')

@section('styles')
<style>
    /* Page-specific typography overrides */
    h1 {
        font-family: 'Abril Fatface', cursive;
        font-size: 2.5rem;
        color: var(--text-primary);
        margin-bottom: 0.5rem;
    }

    h2 {
        font-family: 'Abril Fatface', cursive;
        font-size: 1.6rem;
        color: var(--text-primary);
        margin-bottom: var(--spacing-md);
    }

    h3 {
        font-family: var(--font-sans);
        font-size: 1.1rem;
        font-weight: 600;
        color: var(--text-primary);
        margin-bottom: 0.5rem;
    }

    .page-intro {
        margin-bottom: var(--spacing-lg);
    }

    .page-intro p {
        color: var(--text-secondary);
        font-size: 1rem;
    }

    /* Card styles */
    .card {
        padding: var(--spacing-lg);
        margin-bottom: var(--spacing-lg);
    }

    .card:hover {
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    }

    .card-section {
        margin-bottom: var(--spacing-lg);
        padding-bottom: var(--spacing-lg);
        border-bottom: 1px solid var(--border-color);
    }

    .card-section:last-child {
        border-bottom: none;
        margin-bottom: 0;
        padding-bottom: 0;
    }

    .content-grid {
        display: grid;
        grid-template-columns: 2fr 1fr;
        gap: var(--spacing-lg);
    }

    /* Order items styling */
    .order-item {
        padding: var(--spacing-md);
        background-color: white;
        border-radius: 20px;
        margin-bottom: var(--spacing-md);
        border: 1px solid var(--border-color);
        transition: var(--transition);
    }

    .order-item:hover {
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    }

    .item-header {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        margin-bottom: var(--spacing-sm);
    }

    .item-name {
        font-weight: 600;
        color: var(--text-primary);
        font-size: 1rem;
    }

    .item-price {
        font-weight: 700;
        color: var(--accent-dark);
        font-size: 1.1rem;
    }

    .item-meta {
        color: var(--text-secondary);
        font-size: 0.9rem;
    }

    /* Payment action styling */
    .payment-action-box {
        padding: var(--spacing-lg);
        border-radius: 20px;
        margin-top: var(--spacing-lg);
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: var(--spacing-lg);
    }

    .payment-action-box.pending {
        background-color: var(--accent-light);
        border: 2px solid var(--accent-dark);
    }

    .payment-action-box.failed {
        background-color: var(--accent-light);
        border: 2px solid var(--accent-dark);
    }

    .payment-action-box.success {
        background-color: var(--accent-light);
        border: 2px solid var(--accent-dark);
    }

    .payment-amount {
        text-align: right;
    }

    .payment-amount-label {
        color: var(--text-secondary);
        font-size: 0.9rem;
        margin-bottom: 0.5rem;
    }

    .payment-amount-value {
        font-size: 2rem;
        font-weight: 700;
        color: var(--accent-dark);
    }

    .pending .payment-amount-value {
        color: var(--accent-dark);
    }

    .failed .payment-amount-value {
        color: var(--accent-dark);
    }

    .success .payment-amount-value {
        color: var(--accent-dark);
    }

    .btn {
        display: inline-block;
        padding: 1rem 2rem;
        background-color: var(--accent-dark);
        color: white;
        text-decoration: none;
        border-radius: 20px;
        font-weight: 600;
        transition: var(--transition);
        border: none;
        cursor: pointer;
        font-size: 1rem;
    }

    .btn:hover {
        background-color: var(--accent-pink);
        transform: translateY(-2px);
    }

    .btn-pending {var(--accent-dark);
        color: white;
    }

    .btn-failed {
        background-color: var(--accent-dark)
        background-color: #dc3545;
        color: white;
    }

    .success-check {
        font-sivar(--accent-dark)m;
        color: #28a745;
    }

    .status-badge {
        display: inline-block;
        padding: 0.4rem 0.8rem;
        border-radius: 20px;
        font-size: 0.85rem;
        font-weight: 600;
        text-transform: capitalize;
    }

    .status-badge.paid {var(--accent-light);
        color: var(--accent-dark);
    }

    .status-badge.pending {
        background-color: var(--accent-light);
        color: var(--accent-dark);
    }

    .status-badge.failed {
        background-color: var(--accent-light);
        color: var(--accent-dark);
    }

    .status-badge.processing {
        background-color: var(--accent-light);
        color: var(--accent-dark);
    }

    .status-badge.shipped {
        background-color: var(--accent-light);
        color: var(--accent-dark);
    }

    .status-badge.delivered {
        background-color: var(--accent-light);
        color: var(--accent-dark)or: #d4edda;
        color: #155724;
    }

    @media (max-width: 768px) {
        .content-grid {
            grid-template-columns: 1fr;
        }

        h1 {
            font-size: 1.8rem;
        }

        .payment-action-box {
            flex-direction: column;
            align-items: flex-start;
        }

        .payment-amount {
            text-align: left;
        }
    }
</style>
@endsection

@section('content')
<div class="container">
    <div class="page-intro">
        <h1>Order Details</h1>
        <p>Order #{{ $order->order_number }}</p>
    </div>

    <div class="content-grid">
        <!-- Main Content -->
        <div>
            <!-- Order Status -->
            <div class="card">
                <h2>Order Status</h2>
                <div class="card-section">
                    <span class="status-badge {{ $order->status }}">
                        {{ str_replace('_', ' ', ucfirst($order->status)) }}
                    </span>
                    <p style="margin-top: var(--spacing-sm); color: var(--text-secondary); font-size: 0.9rem;">
                        Ordered on {{ $order->created_at->format('d M Y \a\t H:i') }}
                    </p>
                </div>
            </div>

            <!-- Order Items -->
            <div class="card">
                <h2>Order Items</h2>
                @foreach($order->items as $item)
                    <div class="order-item">
                        <div class="item-header">
                            <div>
                                <div class="item-name">{{ $item->product->name }}</div>
                                <div class="item-meta">{{ $item->type }}</div>
                                @if($item->length)
                                    <div class="item-meta">Length: {{ $item->length }}m</div>
                                @endif
                                @if($item->width && $item->height)
                                    <div class="item-meta">Dimensions: {{ $item->width }}m × {{ $item->height }}m</div>
                                @endif
                            </div>
                            <div>
                                <div class="item-price">R {{ number_format($item->price, 2) }}</div>
                                <div class="item-meta" style="text-align: right;">Qty: {{ $item->quantity }}</div>
                            </div>
                        </div>
                    </div>
                @endforeach
            </div>

            <!-- Shipping Details -->
            <div class="card">
                <h2>Delivery Details</h2>
                
                <div class="card-section">
                    <h3>Customer Information</h3>
                    <dl style="color: var(--text-secondary);">
                        <div class="spec-group">
                            <dt>Name:</dt>
                            <dd>{{ $order->customer_name }}</dd>
                        </div>
                        <div class="spec-group">
                            <dt>Email:</dt>
                            <dd>{{ $order->customer_email }}</dd>
                        </div>
                        <div class="spec-group">
                            <dt>Phone:</dt>
                            <dd>{{ $order->customer_phone }}</dd>
                        </div>
                    </dl>
                </div>

                <div class="card-section">
                    <h3>Shipping Address</h3>
                    <p style="color: var(--text-secondary); line-height: 1.6;">{{ $order->shipping_address }}</p>
                </div>

                @if($order->notes)
                    <div class="card-section">
                        <h3>Order Notes</h3>
                        <p style="color: var(--text-secondary);">{{ $order->notes }}</p>
                    </div>
                @endif
            </div>
        </div>

        <!-- Sidebar -->
        <div>
            <!-- Order Summary & Payment -->
            <div class="card">
                <h2>Order Summary</h2>
                
                <div class="card-section">
                    <div class="payment-row" style="display: flex; justify-content: space-between; margin-bottom: var(--spacing-sm); color: var(--text-secondary);">
                        <span>Subtotal:</span>
                        <span>R {{ number_format($order->total, 2) }}</span>
                    </div>
                    <div class="payment-row total" style="display: flex; justify-content: space-between; border-top: 2px solid var(--border-color); padding-top: var(--spacing-md); font-weight: 700; font-size: 1.2rem;">
                        <span>Total:</span>
                        <span>R {{ number_format($order->total, 2) }}</span>
                    </div>
                </div>

                <h3 style="margin-top: var(--spacing-lg); margin-bottom: var(--spacing-md);">Payment Status</h3>
                
                <div style="padding: var(--spacing-sm); background-color: var(--accent-light); border-radius: 20px; margin-bottom: var(--spacing-lg);">
                    <div style="display: flex; justify-content: space-between; align-items: center;">
                        <strong>Payment</strong>
                        <span class="status-badge {{ $order->payment_status }}">{{ ucfirst($order->payment_status) }}</span>
                    </div>
                </div>

                <!-- Payment Actions -->
                @if($order->payment_status === 'pending' && $order->yoco_redirect_url)
                    <div class="payment-action-box pending">
                        <div>
                            <h3 style="margin-top: 0; color: var(--accent-dark);">Payment Required</h3>
                            <p style="color: var(--accent-dark); margin: var(--spacing-sm) 0 0 0;">Click below to complete your payment.</p>
                            <a href="{{ $order->yoco_redirect_url }}" 
                               target="_blank"
                               class="btn btn-pending"
                               style="margin-top: var(--spacing-md);">
                                Pay Now
                            </a>
                        </div>
                        <div class="payment-amount">
                            <div class="payment-amount-label">Amount Due</div>
                            <div class="payment-amount-value">R {{ number_format($order->total, 2) }}</div>
                        </div>
                    </div>
                @elseif($order->payment_status === 'failed' && $order->yoco_redirect_url)
                    <div class="payment-action-box failed">
                        <div>
                            <h3 style="margin-top: 0; color: var(--accent-dark);">Payment Failed</h3>
                            <p style="color: var(--accent-dark); margin: var(--spacing-sm) 0 0 0;">Please try your payment again.</p>
                            <a href="{{ $order->yoco_redirect_url }}" 
                               target="_blank"
                               class="btn btn-failed"
                               style="margin-top: var(--spacing-md);">
                                Retry Payment
                            </a>
                        </div>
                        <div class="payment-amount">
                            <div class="payment-amount-label">Amount Due</div>
                            <div class="payment-amount-value">R {{ number_format($order->total, 2) }}</div>
                        </div>
                    </div>
                @elseif($order->payment_status === 'paid')
                    <div class="payment-action-box success">
                        <div style="display: flex; gap: var(--spacing-md); align-items: flex-start;">
                            <div class="success-check">✓</div>
                            <div>
                                <h3 style="margin-top: 0; color: var(--accent-dark);">Payment Received</h3>
                                <p style="color: var(--accent-dark); margin: var(--spacing-sm) 0 0 0; font-size: 0.9rem;">Thank you! Your order is being processed.</p>
                            </div>
                        </div>
                    </div>
                @endif
            </div>

            <!-- Back Link -->
            <div style="text-align: center; margin-top: var(--spacing-lg);">
                <a href="{{ route('my-orders') }}" style="color: var(--accent-dark); text-decoration: none; font-weight: 600;">
                    ← Back to Orders
                </a>
            </div>
        </div>
    </div>
</div>
@endsection
