@extends('layouts.app')

@section('title', 'Detail Pesanan')

@section('content')
<div class="max-w-4xl mx-auto py-6 sm:px-6 lg:px-8">
    <div class="px-4 py-6 sm:px-0">
        <!-- Back Button -->
        <div class="mb-6">
            <a href="{{ route('orders.index') }}" class="text-blue-600 hover:text-blue-800 flex items-center">
                <svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7"></path>
                </svg>
                Kembali ke Daftar Pesanan
            </a>
        </div>

        <div class="bg-white shadow-lg rounded-lg overflow-hidden">
            <div class="px-6 py-4 bg-gray-50 border-b border-gray-200">
                <h1 class="text-2xl font-bold text-gray-900">Detail Pesanan #{{ $order->id }}</h1>
                <p class="text-gray-600">Informasi lengkap pesanan pelanggan</p>
            </div>

            <div class="p-6 space-y-6">
                <!-- Status -->
                <div class="flex items-center justify-between">
                    <div>
                        <h2 class="text-lg font-semibold text-gray-900">Status Pesanan</h2>
                        <span class="inline-flex items-center px-3 py-1 rounded-full text-sm font-medium
                            @if($order->status == 'pending') bg-yellow-100 text-yellow-800
                            @elseif($order->status == 'processing') bg-blue-100 text-blue-800
                            @elseif($order->status == 'shipped') bg-purple-100 text-purple-800
                            @elseif($order->status == 'delivered') bg-green-100 text-green-800
                            @else bg-red-100 text-red-800 @endif">
                            {{ ucfirst($order->status) }}
                        </span>
                    </div>
                    <div class="text-right">
                        <p class="text-sm text-gray-500">Tanggal Pesan</p>
                        <p class="text-sm font-medium text-gray-900">{{ $order->created_at->format('d M Y, H:i') }}</p>
                    </div>
                </div>

                <!-- Customer Information -->
                <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                    <div>
                        <h3 class="text-lg font-semibold text-gray-900 mb-4">Informasi Pelanggan</h3>
                        <div class="space-y-3">
                            <div>
                                <label class="text-sm font-medium text-gray-500">Nama</label>
                                <p class="text-sm text-gray-900">{{ $order->customer_name }}</p>
                            </div>
                            <div>
                                <label class="text-sm font-medium text-gray-500">Email</label>
                                <p class="text-sm text-gray-900">{{ $order->customer_email }}</p>
                            </div>
                            <div>
                                <label class="text-sm font-medium text-gray-500">Telepon</label>
                                <p class="text-sm text-gray-900">{{ $order->customer_phone }}</p>
                            </div>
                            <div>
                                <label class="text-sm font-medium text-gray-500">Alamat</label>
                                <p class="text-sm text-gray-700">{{ $order->customer_address }}</p>
                            </div>
                        </div>
                    </div>

                    <!-- Product Information -->
                    <div>
                        <h3 class="text-lg font-semibold text-gray-900 mb-4">Detail Produk</h3>
                        <div class="bg-gray-50 rounded-lg p-4">
                            <div class="flex items-center space-x-4">
                                <img class="w-16 h-16 object-cover rounded-lg" src="{{ $order->product->image ? asset('storage/' . $order->product->image) : 'https://via.placeholder.com/64x64?text=No+Image' }}" alt="{{ $order->product->name }}">
                                <div>
                                    <h4 class="font-medium text-gray-900">{{ $order->product->name }}</h4>
                                    <p class="text-sm text-gray-500">{{ $order->product->description ? \Illuminate\Support\Str::limit($order->product->description, 50) : 'Tidak ada deskripsi' }}</p>
                                </div>
                            </div>
                        </div>
                        <div class="mt-4 space-y-2">
                            <div class="flex justify-between">
                                <span class="text-sm text-gray-500">Harga Satuan</span>
                                <span class="text-sm font-medium text-gray-900">Rp {{ number_format($order->product->price, 0, ',', '.') }}</span>
                            </div>
                            <div class="flex justify-between">
                                <span class="text-sm text-gray-500">Jumlah</span>
                                <span class="text-sm font-medium text-gray-900">{{ $order->quantity }} pcs</span>
                            </div>
                            <div class="flex justify-between border-t pt-2">
                                <span class="text-lg font-semibold text-gray-900">Total</span>
                                <span class="text-lg font-bold text-green-600">Rp {{ number_format($order->total_price, 0, ',', '.') }}</span>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Notes -->
                @if($order->notes)
                    <div>
                        <h3 class="text-lg font-semibold text-gray-900 mb-2">Catatan</h3>
                        <p class="text-gray-700 bg-gray-50 rounded-lg p-4">{{ $order->notes }}</p>
                    </div>
                @endif

                <!-- Action Buttons -->
                <div class="flex justify-end space-x-4 pt-6 border-t border-gray-200">
                    <a href="{{ route('orders.edit', $order) }}"
                       class="px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-blue-600 hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500">
                        Edit Pesanan
                    </a>
                    <form method="POST" action="{{ route('orders.destroy', $order) }}" class="inline">
                        @csrf
                        @method('DELETE')
                        <button type="submit" class="px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-red-600 hover:bg-red-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-red-500"
                                onclick="return confirm('Apakah Anda yakin ingin menghapus pesanan ini?')">
                            Hapus Pesanan
                        </button>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection