@extends('layouts.app')
@section('content')
<div class="container mt-4">
    <div class="row justify-content-center">
        <div class="col-md-6">
            <div class="card">
                <div class="card-header bg-primary text-white">
                    {{ isset($product) ? 'Edit Menu' : 'Tambah Menu Baru' }}
                </div>
                <div class="card-body">
                    @if ($errors->any())
                        <div class="alert alert-danger">
                            <ul>
                                @foreach ($errors->all() as $error)
                                    <li>{{ $error }}</li>
                                @endforeach
                            </ul>
                        </div>
                    @endif
                    <form method="POST" enctype="multipart/form-data" action="{{ isset($product) ? url('/produk/'.$product->id.'/update') : url('/produk') }}">
                        @csrf
                        <div class="form-group">
                            <label>Nama Menu</label>
                            <input type="text" name="name" class="form-control" value="{{ $product->name ?? '' }}" required>
                        </div>
                        <div class="form-group">
                            <label>Kategori</label>
                            <select name="category" class="form-control" required>
                                <option value="">-- Pilih Kategori --</option>
                                <option value="makanan" {{ (isset($product) && $product->category=='makanan') ? 'selected' : '' }}>Makanan</option>
                                <option value="minuman" {{ (isset($product) && $product->category=='minuman') ? 'selected' : '' }}>Minuman</option>
                                <option value="snack" {{ (isset($product) && $product->category=='snack') ? 'selected' : '' }}>Snack</option>
                            </select>
                        </div>
                        <div class="form-group">
                            <label>Harga</label>
                            <input type="number" name="price" class="form-control" value="{{ $product->price ?? '' }}" required>
                        </div>
                        <div class="form-group">
                            <label>Foto Menu</label>
                            <input type="file" name="image" class="form-control-file">
                            @if(isset($product) && $product->image)
                                <img src="{{ asset('storage/'.$product->image) }}" width="120" class="mt-2 rounded shadow">
                            @endif
                        </div>
                        <button type="submit" class="btn btn-success">{{ isset($product) ? 'Update' : 'Tambah' }}</button>
                        <a href="/produk" class="btn btn-secondary">Batal</a>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection
