@extends('layouts.admin')

@section('title', 'Edit Produk')
@section('page-title', 'Edit Produk')

@section('content')
<div class="card">
    <div class="card-body">
        <form action="{{ route('petani.produk.update', $produk->id) }}" method="POST" enctype="multipart/form-data">
            @csrf
            @method('PUT')
            
            <div class="form-group mb-3">
                <label>Nama Produk</label>
                <input type="text" name="nama_produk" class="form-control" value="{{ $produk->nama_produk }}" required>
            </div>

            <div class="row">
                <div class="col-md-6">
                    <div class="form-group mb-3">
                        <label>Harga (Rp)</label>
                        <input type="number" name="harga" class="form-control" value="{{ $produk->harga }}" required>
                    </div>
                </div>
                <div class="col-md-6">
                    <div class="form-group mb-3">
                        <label>Stok</label>
                        <input type="number" name="stok" class="form-control" value="{{ $produk->stok }}" required>
                    </div>
                </div>
            </div>

            <div class="form-group mb-3">
                <label>Deskripsi</label>
                <textarea name="deskripsi" class="form-control" rows="4" required>{{ $produk->deskripsi }}</textarea>
            </div>

            <div class="form-group mb-3">
                <label>Foto Produk (Biarkan kosong jika tidak ingin mengganti)</label>
                <input type="file" name="foto_produk" class="form-control" accept="image/*">
                @if($produk->foto_produk)
                    <small class="text-muted">Foto saat ini:</small><br>
                    <img src="{{ asset('storage/'.$produk->foto_produk) }}" width="100" class="mt-2 rounded">
                @endif
            </div>

            <button type="submit" class="btn btn-success">Update Produk</button>
            <a href="{{ route('petani.produk.index') }}" class="btn btn-secondary">Batal</a>
        </form>
    </div>
</div>
@endsection