@extends('layouts.app')

@section('title', 'Edit Inventory Item')

@section('content')

<div class="row">
    <div class="col-sm-12">

        <div class="card">

            <div class="card-header d-flex justify-content-between">
                <div class="header-title">
                    <h4 class="card-title">Edit Item</h4>
                </div>
            </div>

            <div class="card-body">

                <form
                    action="{{ route('inventory.update', $item->item_id) }}"
                    method="POST"
                >

                    @csrf
                    @method('PUT')

                    <div class="row">

                        {{-- Item Name --}}
                        <div class="col-md-6">
                            <div class="form-group">

                                <label>Item Name *</label>

                                <input
                                    type="text"
                                    name="item_name"
                                    class="form-control"
                                    value="{{ old('item_name', $item->item_name) }}"
                                    required
                                >

                                @error('item_name')
                                    <small class="text-danger">
                                        {{ $message }}
                                    </small>
                                @enderror

                            </div>
                        </div>


                        {{-- Item Code --}}
                        <div class="col-md-6">
                            <div class="form-group">

                                <label>Item Code *</label>

                                <input
                                    type="text"
                                    name="item_code"
                                    class="form-control"
                                    value="{{ old('item_code', $item->item_code) }}"
                                    required
                                >

                                @error('item_code')
                                    <small class="text-danger">
                                        {{ $message }}
                                    </small>
                                @enderror

                            </div>
                        </div>


                        {{-- Category --}}
                        <div class="col-md-6">
                            <div class="form-group">

                                <label>Category *</label>

                                <select
                                    name="category_id"
                                    class="form-control"
                                    required
                                >

                                    <option value="">Select Category</option>

                                    @foreach($categories as $category)

                                        <option
                                            value="{{ $category->category_id }}"
                                            {{ $item->category_id == $category->category_id ? 'selected' : '' }}
                                        >
                                            {{ $category->category_name }}
                                        </option>

                                    @endforeach

                                </select>

                                @error('category_id')
                                    <small class="text-danger">
                                        {{ $message }}
                                    </small>
                                @enderror

                            </div>
                        </div>


                        {{-- Purchase Price --}}
                        <div class="col-md-6">
                            <div class="form-group">

                                <label>Purchase Price *</label>

                                <input
                                    type="number"
                                    step="0.01"
                                    name="item_purchase_price"
                                    class="form-control"
                                    value="{{ old('item_purchase_price', $item->item_purchase_price) }}"
                                    required
                                >

                                @error('item_purchase_price')
                                    <small class="text-danger">
                                        {{ $message }}
                                    </small>
                                @enderror

                            </div>
                        </div>


                        {{-- Sale Price --}}
                        <div class="col-md-6">
                            <div class="form-group">

                                <label>Sale Price *</label>

                                <input
                                    type="number"
                                    step="0.01"
                                    name="item_saleprice"
                                    class="form-control"
                                    value="{{ old('item_saleprice', $item->item_saleprice) }}"
                                    required
                                >

                                @error('item_saleprice')
                                    <small class="text-danger">
                                        {{ $message }}
                                    </small>
                                @enderror

                            </div>
                        </div>


                        {{-- Quantity --}}
                        <div class="col-md-6">
                            <div class="form-group">

                                <label>Quantity *</label>

                                <input
                                    type="number"
                                    name="item_quantity"
                                    class="form-control"
                                    value="{{ old('item_quantity', $item->item_quantity) }}"
                                    required
                                >

                                @error('item_quantity')
                                    <small class="text-danger">
                                        {{ $message }}
                                    </small>
                                @enderror

                            </div>
                        </div>


                        {{-- Minimum Stock --}}
                        <div class="col-md-6">
                            <div class="form-group">

                                <label>Minimum Stock *</label>

                                <input
                                    type="number"
                                    name="minimum_stock"
                                    class="form-control"
                                    value="{{ old('minimum_stock', $item->minimum_stock) }}"
                                    required
                                >

                                @error('minimum_stock')
                                    <small class="text-danger">
                                        {{ $message }}
                                    </small>
                                @enderror

                            </div>
                        </div>

                    </div>


                    <button type="submit" class="btn btn-primary mr-2">
                        Update Item
                    </button>

                    <a
                        href="{{ route('inventory.list') }}"
                        class="btn btn-danger"
                    >
                        Cancel
                    </a>

                </form>

            </div>

        </div>

    </div>
</div>

@endsection