@extends('layouts.admin')

@section('title', 'Tambah Stok Produk')

@section('content')
<div class="max-w-3xl mx-auto space-y-6">

    <!-- Header -->
    <div class="flex items-center gap-4">
        <a href="{{ route('admin.stock_logs.index') }}"
           class="w-10 h-10 flex items-center justify-center rounded-lg border border-gray-300 bg-white text-gray-500 hover:bg-gray-50 transition">
            <i class="bi bi-arrow-left"></i>
        </a>
        <div>
            <h1 class="text-xl font-semibold text-gray-800">Tambah Stok</h1>
            <p class="text-sm text-gray-500">Tambahkan stok untuk varian produk tertentu</p>
        </div>
    </div>

    <!-- Error -->
    @if ($errors->any())
        <div class="rounded-lg border border-red-300 bg-red-50 p-4">
            <div class="flex gap-3">
                <i class="bi bi-exclamation-circle text-red-500 mt-1"></i>
                <ul class="text-sm text-red-600 list-disc list-inside space-y-1">
                    @foreach ($errors->all() as $error)
                        <li>{{ $error }}</li>
                    @endforeach
                </ul>
            </div>
        </div>
    @endif

    <!-- Card -->
    <div class="bg-white border border-gray-300 rounded-2xl shadow-sm p-6">
        <form action="{{ route('admin.stock_logs.store') }}" method="POST" class="space-y-5">
            @csrf

            <!-- Produk Varian -->
            <div class="space-y-2">
                <label class="text-sm font-semibold text-gray-700">
                    Produk & Varian <span class="text-red-500">*</span>
                </label>

                <select name="produk_varian_id"
                        class="w-full text-sm rounded-xl border-2 border-gray-300 focus:border-green-500 focus:ring-0 px-4 py-2.5 transition"
                        required>
                    <option value="" disabled selected>-- Pilih Varian --</option>

                    @foreach($produks as $produk)
                        @if($produk->varians->count() > 0)
                            <optgroup label="{{ $produk->nama }}">
                                @foreach($produk->varians as $varian)
                                    <option value="{{ $varian->id }}">
                                        [{{ $varian->sku ?? '-' }}] - {{ $varian->ukuran }}, {{ $varian->warna }} | Stok: {{ $varian->stok }}
                                    </option>
                                @endforeach
                            </optgroup>
                        @endif
                    @endforeach
                </select>
            </div>

            <!-- Jumlah -->
            <div class="space-y-2">
                <label class="text-sm font-semibold text-gray-700">
                    Jumlah Stok Masuk <span class="text-red-500">*</span>
                </label>

                <div class="relative">
                    <span class="absolute left-4 top-1/2 -translate-y-1/2 text-primary font-bold text-lg">+</span>
                    <input type="number"
                           name="jumlah"
                           min="1"
                           placeholder="Contoh: 10"
                           class="w-full pl-10 pr-4 py-2.5 text-sm rounded-xl border-2 border-gray-300 focus:border-primary focus:ring-0 transition"
                           required>
                </div>

                <p class="text-xs text-gray-400">
                    Stok akan ditambahkan ke stok saat ini (misal: 10 + 5 = 15)
                </p>
            </div>

            <!-- Keterangan -->
            <div class="space-y-2">
                <label class="text-sm font-semibold text-gray-700">
                    Keterangan (Opsional)
                </label>

                <textarea name="keterangan"
                          rows="3"
                          placeholder="Contoh: Restock dari supplier..."
                          class="w-full text-sm rounded-xl border-2 border-gray-300 focus:border-primary focus:ring-0 px-4 py-2.5 transition"></textarea>
            </div>

            <!-- Action -->
            <div class="flex justify-end gap-3 pt-4 border-t border-gray-200">
                <a href="{{ route('admin.stock_logs.index') }}"
                   class="px-5 py-2 text-sm bg-gray-100 text-gray-600 rounded-lg hover:bg-gray-200 transition">
                    Batal
                </a>

                <button type="submit"
                        class="px-6 py-2 text-sm font-semibold text-white bg-blue-600 rounded-lg hover:bg-blue-700 transition flex items-center gap-2 shadow-sm">
                    <i class="bi bi-check-circle"></i>
                    Simpan
                </button>
            </div>

        </form>
    </div>

</div>
@endsection