@extends('admin.layout')

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

@section('content')
    <div class="card">
        <h2>Tambah Produk Baru</h2>
        @if($errors->any())<div class="error">{{ $errors->first() }}</div>@endif
        <form method="post" action="{{ route('admin.products.store') }}" enctype="multipart/form-data">
            @csrf
            <div class="form-row">
                <label>Kategori</label>
                <select name="category_id" required>
                    <option value="">-- Pilih Kategori --</option>
                    @foreach($categories as $cat)
                        <option value="{{ $cat->id }}" @selected(old('category_id') == $cat->id)>{{ $cat->name }}</option>
                    @endforeach
                </select>
            </div>
            <div class="form-row">
                <label>Nama Produk</label>
                <input type="text" name="name" value="{{ old('name') }}" required>
            </div>
            <div class="form-row">
                <label>Warna</label>
                <input type="text" name="color" value="{{ old('color') }}">
            </div>
            <div class="form-row">
                <label>Image URL / Path</label>
                <input type="text" name="image_url" value="{{ old('image_url') }}">
                <div style="margin-top:8px">atau upload gambar:</div>
                <input type="file" name="image" accept="image/*">
            </div>

            <h3>Pengendalian Stok (Min-Max)</h3>
            <div class="sizes-grid">
                <div class="size-item">
                    <label>Stok Minimum (Reorder Point)</label>
                    <input type="number" name="min_stock" value="{{ old('min_stock', 5) }}" min="0" required>
                </div>
                <div class="size-item">
                    <label>Stok Maksimum</label>
                    <input type="number" name="max_stock" value="{{ old('max_stock', 50) }}" min="0" required>
                </div>
            </div>

            <h3>Stok per Ukuran</h3>
            <div class="sizes-grid">
                @foreach(['S','M','L','XL','XXL'] as $s)
                    <div class="size-item">
                        <label>{{ $s }}</label>
                        <input type="number" name="sizes[{{ $s }}]" value="{{ old("sizes.$s", 0) }}" min="0">
                    </div>
                @endforeach
            </div>

            <div style="margin-top:16px">
                <button class="btn" type="submit">Simpan Produk</button>
                <a class="btn ghost" href="{{ route('admin.products.index') }}" style="margin-left:12px">Batal</a>
            </div>
        </form>
    </div>
@endsection
