@extends('layouts.app')

@section('title', 'Add 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">Add Item</h4>
                </div>
            </div>

            <div class="card-body">

                <form action="{{ route('inventory.store') }}" method="POST">
                    @csrf

                    <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"
                                    placeholder="Enter Item Name"
                                    value="{{ old('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"
                                    placeholder="Enter Item Code"
                                    value="{{ old('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 }}"
                                            {{ old('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"
                                    name="item_purchase_price"
                                    class="form-control"
                                    placeholder="Enter Purchase Price"
                                    value="{{ old('item_purchase_price') }}"
                                    min="0"
                                    step="0.01"
                                    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"
                                    name="item_saleprice"
                                    class="form-control"
                                    placeholder="Enter Sale Price"
                                    value="{{ old('item_saleprice') }}"
                                    min="0"
                                    step="0.01"
                                    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"
                                    placeholder="Enter Quantity"
                                    value="{{ old('item_quantity') }}"
                                    min="0"
                                    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"
                                    placeholder="Enter Minimum Stock"
                                    value="{{ old('minimum_stock') }}"
                                    min="0"
                                    required
                                >

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

                    </div>


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

                    <button type="reset" class="btn btn-danger">
                        Reset
                    </button>

                </form>

            </div>
        </div>
    </div>
</div>

@endsection