@extends('layouts.app')

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

@section('content')

        <div class="row">
            <div class="col-lg-12">
                <div class="d-flex flex-wrap flex-wrap align-items-center justify-content-between mb-4">
                    <div>
                        <h4 class="mb-3">Item List</h4>
                        <p class="mb-0">The items list effectively dictates Item presentation and provides space<br> to list your inventory items and offering in the most appealing way.</p>
                    </div>
@php
    $isAdmin = auth()->user()->role &&
               strtolower(auth()->user()->role->role_name) === 'admin';
@endphp

@if($isAdmin)
    <a href="{{ route('inventory.add') }}" class="btn btn-primary add-list">
        <i class="las la-plus mr-3"></i>Add Item
    </a>
@endif                </div>
            </div>
            <div class="col-lg-12">
                <div class="table-responsive rounded mb-3">
                <table class="data-tables table mb-0 tbl-server-info">
                    <thead class="bg-white text-uppercase">
                        <tr class="ligth ligth-data">
                            <th>
                                <div class="checkbox d-inline-block">
                                    <input type="checkbox" class="checkbox-input" id="checkbox1">
                                    <label for="checkbox1" class="mb-0"></label>
                                </div>
                            </th>
                            <th>Item name</th>
                            <th>ItemCode</th>
                            <th>Category</th>
                            <th>Purchase Price </th>
                            <th>Sale Price </th>
                            <th>Stock Quantity</th>
                            <th>Action</th>
                        </tr>
                    </thead>
<tbody class="ligth-body">

    @forelse($items as $item)

        <tr>

            <td>
                <div class="checkbox d-inline-block">
                    <input
                        type="checkbox"
                        class="checkbox-input"
                        id="checkbox{{ $item->item_id }}"
                    >

                    <label
                        for="checkbox{{ $item->item_id }}"
                        class="mb-0"
                    ></label>
                </div>
            </td>

            <td>
                {{ $item->item_name }}
            </td>

            <td>
                {{ $item->item_code }}
            </td>

            <td>
                {{ $item->category->category_name ?? 'N/A' }}
            </td>

            <td>
                RS {{ number_format($item->item_purchase_price, 2) }}
            </td>

            <td>
                RS {{ number_format($item->item_saleprice, 2) }}
            </td>

            <td>
                {{ $item->item_quantity }}
            </td>

<td>
    <div class="d-flex align-items-center list-action">

        {{-- View --}}
        <a
            class="badge badge-info mr-2"
            data-toggle="tooltip"
            data-placement="top"
            title="View"
            href="{{ route('inventory.show', $item->item_id) }}"
        >
            <i class="ri-eye-line mr-0"></i>
        </a>


        @if($isAdmin)

            {{-- Edit --}}
            <a
                class="badge bg-success mr-2"
                data-toggle="tooltip"
                data-placement="top"
                title="Edit"
                href="{{ route('inventory.edit', $item->item_id) }}"
            >
                <i class="ri-pencil-line mr-0"></i>
            </a>


            {{-- Delete --}}
            <form
                action="{{ route('inventory.destroy', $item->item_id) }}"
                method="POST"
                style="display: inline;"
                onsubmit="return confirm('Are you sure you want to delete this item?');"
            >
                @csrf
                @method('DELETE')

                <button
                    type="submit"
                    class="badge bg-warning mr-2 border-0"
                    data-toggle="tooltip"
                    data-placement="top"
                    title="Delete"
                >
                    <i class="ri-delete-bin-line mr-0"></i>
                </button>
            </form>

        @endif

    </div>
</td>
        </tr>

    @empty

        <tr>
            <td colspan="8" class="text-center">
                No inventory items found.
            </td>
        </tr>

    @endforelse

</tbody>                </table>
                </div>
            </div>
        </div>
        <!-- Page end  -->
    </div>
    
    <div class="modal fade" id="edit-note" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog modal-dialog-centered" role="document">
            <div class="modal-content">
                <div class="modal-body">
                    <div class="popup text-left">
                        <div class="media align-items-top justify-content-between">                            
                            <h3 class="mb-3">Item</h3>
                            <div class="btn-cancel p-0" data-dismiss="modal"><i class="las la-times"></i></div>
                        </div>
                        <div class="content edit-notes">
                            <div class="card card-transparent card-block card-stretch event-note mb-0">
                                <div class="card-body px-0 bukmark">
                                    <div class="d-flex align-items-center justify-content-between pb-2 mb-3 border-bottom">                                                    
                                        <div class="quill-tool">
                                        </div>
                                    </div>
                                    <div id="quill-toolbar1">
                                        <p>Virtual Digital Marketing Course every week on Monday, Wednesday and Saturday.Virtual Digital Marketing Course every week on Monday</p>
                                    </div>
                                </div>
                                <div class="card-footer border-0">
                                    <div class="d-flex flex-wrap align-items-ceter justify-content-end">
                                        <div class="btn btn-primary mr-3" data-dismiss="modal">Cancel</div>
                                        <div class="btn btn-outline-primary" data-dismiss="modal">Save</div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
      </div>
        <!-- Page end  -->
    </div>
      </div>
   
@endsection