<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"/>
    <title>Edit Permintaan Peminjaman - {{ config('app.name', 'Laravel') }}</title>
    
    <script src="https://cdn.tailwindcss.com"></script>
    <script src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js" defer></script>
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
    
    <style>
        :root {
            --bg: #f8fafc; --panel: #ffffff; --muted: #6b7280; --accent: #0b5ed7;
            --accent-600: #0b63d6; --danger: #dc2626; --card-border: #eef2f7; --soft: #f8fafc;
            --font-main: 'Inter', system-ui, -apple-system, sans-serif;
        }
        * { box-sizing: border-box; }
        
        body { 
            margin: 0; 
            font-family: var(--font-main); 
            background: var(--bg); 
            color: #111827; 
            -webkit-font-smoothing: antialiased;
        }
        
        .app { display: flex; min-height: 100vh; }
        
        /* Content area adjustments for responsiveness */
        .content { 
            flex: 1; 
            padding: 32px; 
            width: 100%;
            transition: all 0.3s ease;
        }

        /* Responsive Styles */
        @media (max-width: 1024px) {
            .app { display: block; }
            .content { padding: 20px; padding-top: 80px; }
        }
        
        @media (max-width: 640px) {
            .content { padding: 16px; padding-top: 80px; }
        }
    </style>
</head>
<body>
<div class="app">
    {{-- Sidebar --}}
    @include('partials.sidebar')

    {{-- Konten Utama --}}
    <main class="content">
        <div class="max-w-3xl mx-auto">
            {{-- Header --}}
            <div class="flex flex-col md:flex-row md:items-center justify-between mb-6 md:mb-8 gap-4">
                <div>
                    <h1 class="text-2xl md:text-3xl font-semibold text-gray-900">Edit Permintaan</h1>
                    <p class="mt-1 text-sm text-gray-600">
                        @if($restricted)
                            Silakan revisi data sesuai instruksi staf.
                        @else
                            Ubah detail permintaan peminjaman berikut.
                        @endif
                    </p>
                </div>
                <div>
                    <a href="{{ route('borrow.index') }}"
                       class="inline-flex items-center px-4 py-2 rounded-lg bg-gray-100 hover:bg-gray-200 text-gray-700 text-sm font-medium shadow-sm transition-colors w-full md:w-auto justify-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="M10 19l-7-7m0 0l7-7m-7 7h18"></path></svg>
                        Kembali
                    </a>
                </div>
            </div>

            {{-- Card Form --}}
            <div class="bg-white rounded-xl shadow-sm border border-gray-200 overflow-hidden">
                <form action="{{ route('borrow.update', $borrowRequest->id) }}" method="POST">
                    @csrf
                    @method('PUT')

                    <input type="hidden" name="item_id" value="{{ $borrowRequest->item_id }}">
                    <input type="hidden" name="tanggal_pinjam" value="{{ $borrowRequest->tanggal_pinjam }}">

                    <div class="p-5 md:p-6 space-y-6">
                        
                        {{-- Detail Barang (Read Only) --}}
                        <div class="bg-gray-50 rounded-lg p-4 border border-gray-200">
                            <div class="flex items-start gap-4">
                                <div class="flex-shrink-0">
                                    <div class="w-12 h-12 rounded-lg bg-white border border-gray-200 flex items-center justify-center text-gray-400">
                                        <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4"></path></svg>
                                    </div>
                                </div>
                                <div>
                                    <h3 class="text-sm font-medium text-gray-900">Barang</h3>
                                    <p class="text-base font-semibold text-gray-800">{{ $borrowRequest->item->nama }}</p>
                                    <p class="text-xs text-gray-500 mt-0.5">Tgl Pinjam: {{ $borrowRequest->tanggal_pinjam->format('d M Y, H:i') }}</p>
                                </div>
                            </div>
                        </div>

                        {{-- Jumlah --}}
                        <div>
                            <label class="block text-sm font-medium text-gray-700 mb-1">Jumlah</label>
                            <input type="number" name="jumlah"
                                   value="{{ old('jumlah', $borrowRequest->jumlah) }}"
                                   class="block w-full rounded-lg border-gray-300 focus:border-blue-500 focus:ring-blue-500 shadow-sm sm:text-sm py-2.5 px-3"
                                   @if(!$restricted || request()->user()->role === 'staff_bidang') required @endif>
                            @error('jumlah')
                                <p class="text-sm text-red-600 mt-1">{{ $message }}</p>
                            @enderror
                        </div>

                        {{-- Tanggal Kembali --}}
                        <div>
                            <label class="block text-sm font-medium text-gray-700 mb-1">Tanggal & Jam Kembali</label>
                            <input type="datetime-local" name="tanggal_kembali"
                                   value="{{ old('tanggal_kembali', $borrowRequest->tanggal_kembali ? $borrowRequest->tanggal_kembali->format('Y-m-d\TH:i') : '') }}"
                                   min="{{ $borrowRequest->tanggal_pinjam->format('Y-m-d\TH:i') }}"
                                   class="block w-full rounded-lg border-gray-300 focus:border-blue-500 focus:ring-blue-500 shadow-sm sm:text-sm py-2.5 px-3"
                                   @if(!$restricted || request()->user()->role === 'staff_bidang') required @endif>
                            @error('tanggal_kembali')
                                <p class="text-sm text-red-600 mt-1">{{ $message }}</p>
                            @enderror
                        </div>

                        {{-- Catatan Revisi --}}
                        @if($restricted && $borrowRequest->comment)
                        <div class="p-4 bg-yellow-50 border border-yellow-200 rounded-lg">
                            <div class="flex gap-3">
                                <div class="flex-shrink-0">
                                    <svg class="h-5 w-5 text-yellow-400" viewBox="0 0 20 20" fill="currentColor">
                                        <path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z" clip-rule="evenodd" />
                                    </svg>
                                </div>
                                <div>
                                    <h3 class="text-sm font-medium text-yellow-800">Catatan dari Staf</h3>
                                    <div class="mt-1 text-sm text-yellow-700">
                                        {{ $borrowRequest->comment }}
                                    </div>
                                </div>
                            </div>
                        </div>
                        @endif
                    </div>

                    {{-- Footer Actions --}}
                    <div class="px-5 py-4 md:px-6 bg-gray-50 border-t border-gray-200 flex flex-col-reverse sm:flex-row sm:justify-end gap-3">
                        <a href="{{ route('borrow.index') }}"
                           class="w-full sm:w-auto inline-flex justify-center items-center px-4 py-2 border border-gray-300 shadow-sm text-sm font-medium rounded-lg text-gray-700 bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 transition-colors">
                            Batal
                        </a>
                        <button type="submit"
                                class="w-full sm:w-auto inline-flex justify-center items-center px-4 py-2 border border-transparent shadow-sm text-sm font-medium rounded-lg text-white bg-blue-600 hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 transition-colors">
                            Simpan Perubahan
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </main>
</div>
</body>
</html>