@if (isset($relation[0]))
<div>
    @if (isset($options['many_to_many']))
        {{ html()->form('POST', route($route_name.'.detach', [$view_var->id, $options['many_to_many']]))->attributes(['id' => $class])->open() }}
    @else
        {{ html()->form('DELETE', route($class.'.destroy', [0]))->attributes(['id' => $tab['name'].$class])->open() }}
    @endif

    @if ($count < config('datatables.relationThreshold'))
        <table class="table">
            @foreach ($relation as $rel_elem)
                <?php $labelData = $rel_elem->view_index_label(); ?>
                <tr class="{{isset ($labelData['bsclass']) ? $labelData['bsclass'] : ''}}">
                    <td width="20"> {{ Form::checkbox('ids['.$rel_elem->id.']', 1, null, null, ['style' => 'simple']) }} </td>
                    <td class="pl-2">
                        <div class="flex items-center">
                            {!! $rel_elem->view_icon() !!}
                            <a href="{{ route($class.'.'.$method, $rel_elem->id) }}" class="ml-0">
                                {!! is_array($labelData) ? $labelData['header'] : $labelData !!}
                            </a>
                        </div>
                    </td>
                </tr>
            @endforeach
        </table>
    @else
        <table id="{{ Str::slug(strtolower($tab['name']).$class) }}Datatable"
            class="table table-hover datatable table-bordered d-table w-100"
            data-table="true"
            data-ajax="{{ route((new ReflectionClass($view_var))->getShortName().'.relationDatatable', ['model' => $view_var->id, 'relation' => $class]) }}"
        >
            <thead>
                <tr>
                    <th class="w-5"></th>
                    <th class="w-100">Label</th>
                </tr>
            </thead>
            <tbody>
            </tbody>
        </table>
    @endif
    {{ html()->form()->close() }}
</div>
@else

<div class="text-dark" style="padding: 1.5rem;font-weight:bold;">
    {{ $options['empty_message'] ?? trans('view.jQuery_sZeroRecords') }}
</div>

@endif
