@extends('admin.layouts.app')

@section('title', 'Raw Material Items List')

@section('content')
    <div class="page-header">
        <div class="page-title">
            <h4>Raw Material Item List</h4>
            <h6>Manage your Raw Material Items</h6>
        </div>
        @if(auth()->user()->hasPermission('Raw Material Item Create'))
        <div class="page-btn">
            <a href="{{ route('raw-material-items.create') }}" class="btn btn-added">
                <img src="{{ asset('assets/img/icons/plus.svg') }}" alt="img" class="me-1">Add Raw Material Item
            </a>
        </div>
        @endif
    </div>

    <div class="card">
        <div class="card-body">
            <div class="table-top">
                <div class="search-set">
                    <div class="search-input">
                        <a class="btn btn-searchset">
                            <img src="{{ asset('assets/img/icons/search-white.svg') }}" alt="img">
                        </a>
                    </div>
                </div>
            </div>
            <div class="table-responsive">
                <table class="table datanew dataTable no-footer table-striped">
                    <thead>
                        <tr>
                            <th>#</th>
                            <th>DOC NO</th>
                            @if(auth()->user()->hasPermission('Raw Material Item Update'))
                            <th>Action</th>
                            @endif
                            <th>Name</th>
                            <th>Categories</th>
                            {{-- <th>Stock</th> --}}
                            <th>Chart Of Accounts</th>
                            <th>Min. Level</th>
                            <th>Max. Level</th>
                            <th>Party</th>
                            @role('Superadmin')
                            <th>Company</th>
                            @endrole
                            
                        </tr>
                    </thead>
                    <tbody>
                        @foreach ($rawMaterialItems as $rawMaterialItem)
                            <tr>
                                <td>{{ $loop->iteration }}</td>
                                <td><a class="link-primary" href="{{ route('raw-material-items.show', $rawMaterialItem->id) }}">{{ optional($rawMaterialItem->category)->prefix }}-{{ $rawMaterialItem->code }}</a></td>
                                @if(auth()->user()->hasPermission('Raw Material Item Update'))
                                <td>
                                    <a class="me-3" href="{{ route('raw-material-items.edit', $rawMaterialItem->id) }}">
                                        <img src="{{ asset('assets/img/icons/edit.svg') }}" alt="Edit">
                                    </a>
                                </td>
                                @endif
                                <td>{{ $rawMaterialItem->name }}</td>
                                <td>
                                    <span class="badge bg-primary">{{ optional($rawMaterialItem->category)->name }}</span>
                                    @if ($rawMaterialItem->subCategory)
                                        <span class="badge bg-info">{{ $rawMaterialItem->subCategory->name }}</span>
                                    @endif
                                </td>
                                {{-- <td>{{ $rawMaterialItem->current_stock ?? '-' }}</td> --}}
                                <td>
                                    <span class="badge bg-primary">{{ $rawMaterialItem->chart_of_account->particular ?? 'N/A' }}</span>
                                    @if ($rawMaterialItem->sub_chart_of_account)
                                        <span class="badge bg-info">{{ $rawMaterialItem->sub_chart_of_account->name }}</span>
                                    @endif
                                </td>
                                <td>{{ $rawMaterialItem->min_level }}</td>
                                <td>{{ $rawMaterialItem->max_level }}</td>
                                <td>
                                    {{ $rawMaterialItem->party ? $rawMaterialItem->party->name . ' (' . 
                                        ($rawMaterialItem->party->is_supplier == 1 ? 'Supplier' : 
                                        ($rawMaterialItem->party->is_distributor == 1 ? 'Franchiser' : '')) 
                                    . ')' : 'N/A' }}
                                </td>                                
                                @role('Superadmin')
                                <td>{{ $rawMaterialItem->company->name ?? 'N/A' }}</td>
                                @endrole
                                
                            </tr>
                        @endforeach
                    </tbody>
                </table>
            </div>
        </div>
    </div>
@endsection