<x-app-layout>
    @section('title', 'Edit Obat Masuk')

    <div class="space-y-6">
        <!-- Breadcrumb -->
        <nav class="flex" aria-label="Breadcrumb">
            <ol class="inline-flex items-center space-x-1 md:space-x-3">
                <li>
                    <a href="{{ route('obat-masuk.index') }}" class="text-[#7A7FAE] hover:text-[#4A538F]">Obat Masuk</a>
                </li>
                <li>
                    <div class="flex items-center">
                        <svg class="w-4 h-4 text-[#7A7FAE]" fill="currentColor" viewBox="0 0 20 20">
                            <path fill-rule="evenodd" d="M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z" clip-rule="evenodd"/>
                        </svg>
                        <span class="ml-1 text-[#2F347A] font-medium">Edit Obat</span>
                    </div>
                </li>
            </ol>
        </nav>

        <div class="flex items-center justify-between">
            <h1 class="text-2xl font-bold text-[#2F347A]">Edit Obat Masuk</h1>
        </div>

        <form method="POST" action="{{ route('obat-masuk.update', $obatMasuk) }}">
            @csrf
            @method('PUT')
            
            <!-- Informasi Obat -->
            <x-card class="p-6 mb-6">
                <h3 class="text-lg font-semibold text-[#2F347A] mb-4 pb-2 border-b border-[#E5E7F2]">Informasi Obat</h3>
                
                <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                    <x-form-input 
                        name="nama_obat" 
                        label="Nama Obat" 
                        placeholder="Masukkan nama obat"
                        :value="old('nama_obat', $obatMasuk->nama_obat)"
                        :error="$errors->first('nama_obat')"
                        required />

                    <x-form-input 
                        name="kode_batch" 
                        label="Kode Batch" 
                        placeholder="Contoh: BTH-2024-001"
                        :value="old('kode_batch', $obatMasuk->kode_batch)"
                        :error="$errors->first('kode_batch')"
                        required />

                    <x-form-select 
                        name="kategori_id" 
                        label="Kategori" 
                        :error="$errors->first('kategori_id')"
                        required>
                        <option value="">Pilih Kategori</option>
                        @foreach($kategoris as $kategori)
                            <option value="{{ $kategori->id }}" {{ old('kategori_id', $obatMasuk->kategori_id) == $kategori->id ? 'selected' : '' }}>
                                {{ $kategori->nama }}
                            </option>
                        @endforeach
                    </x-form-select>

                    <x-form-select 
                        name="satuan_id" 
                        label="Satuan" 
                        :error="$errors->first('satuan_id')"
                        required>
                        <option value="">Pilih Satuan</option>
                        @foreach($satuans as $satuan)
                            <option value="{{ $satuan->id }}" {{ old('satuan_id', $obatMasuk->satuan_id) == $satuan->id ? 'selected' : '' }}>
                                {{ $satuan->nama }}
                            </option>
                        @endforeach
                    </x-form-select>
                </div>
            </x-card>

            <!-- Sumber Dana & Stok -->
            <x-card class="p-6 mb-6">
                <h3 class="text-lg font-semibold text-[#2F347A] mb-4 pb-2 border-b border-[#E5E7F2]">Sumber Dana & Stok</h3>
                
                <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                    <x-form-input 
                        name="sumber_dana" 
                        label="Sumber Dana" 
                        placeholder="Masukkan sumber dana (opsional)"
                        :value="old('sumber_dana', $obatMasuk->sumber_dana)"
                        :error="$errors->first('sumber_dana')" />

                    <x-form-input 
                        name="barcode" 
                        label="Barcode" 
                        placeholder="Masukkan barcode (opsional)"
                        :value="old('barcode', $obatMasuk->barcode)"
                        :error="$errors->first('barcode')" />

                    <x-form-input 
                        name="stok" 
                        label="Jumlah Stok" 
                        type="number"
                        min="0"
                        placeholder="Jumlah obat"
                        :value="old('stok', $obatMasuk->stok)"
                        :error="$errors->first('stok')"
                        required />

                    <x-form-input 
                        name="no_faktur" 
                        label="No. Faktur" 
                        placeholder="Nomor faktur pembelian"
                        :value="old('no_faktur', $obatMasuk->no_faktur)"
                        :error="$errors->first('no_faktur')" />

                    <x-form-input 
                        name="no_sbbk" 
                        label="No. SBBK" 
                        placeholder="Nomor SBBK (opsional)"
                        :value="old('no_sbbk', $obatMasuk->no_sbbk)"
                        :error="$errors->first('no_sbbk')" />
                </div>
            </x-card>

            <!-- Tanggal -->
            <x-card class="p-6 mb-6">
                <h3 class="text-lg font-semibold text-[#2F347A] mb-4 pb-2 border-b border-[#E5E7F2]">Tanggal</h3>
                
                <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                    <x-form-input 
                        name="tanggal_penerimaan" 
                        label="Tanggal Penerimaan" 
                        type="date"
                        :value="old('tanggal_penerimaan', $obatMasuk->tanggal_penerimaan->format('Y-m-d'))"
                        :error="$errors->first('tanggal_penerimaan')"
                        required />

                    <x-form-input 
                        name="tanggal_kadaluarsa" 
                        label="Tanggal Kadaluarsa" 
                        type="date"
                        :value="old('tanggal_kadaluarsa', $obatMasuk->tanggal_kadaluarsa->format('Y-m-d'))"
                        :error="$errors->first('tanggal_kadaluarsa')"
                        required />
                </div>
            </x-card>

            <!-- Catatan -->
            <x-card class="p-6 mb-6">
                <x-form-textarea 
                    name="catatan" 
                    label="Catatan" 
                    placeholder="Catatan tambahan (opsional)"
                    rows="3"
                    :value="old('catatan', $obatMasuk->catatan)"
                    :error="$errors->first('catatan')" />
            </x-card>

            <!-- Actions -->
            <div class="flex justify-end gap-4">
                <x-btn type="secondary" href="{{ route('obat-masuk.index') }}">Batal</x-btn>
                <x-btn type="primary">Simpan Perubahan</x-btn>
            </div>
        </form>
    </div>
</x-app-layout>
