@extends('layouts.app')

@section('content')
    <div class="container">
        <div class="row">
            <div class="{{ $containerSize }}">
                @include('layouts.alerts')

                <div class="panel panel-default">
                    <div class="panel-heading"><strong>@lang($heading) {{ $singular }}</strong></div>
                    @if($result !== null)
                        <div class="panel-body">
                            <div class="table-responsive">
                                <table class="table table-striped table-bordered">
                                    <thead>
                                    <tr>
                                        <th>
                                            @lang('Attribute')
                                        </th>
                                        <th>
                                            @lang('Value')
                                        </th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    @foreach($columns as $column)
                                        <tr>
                                            <td>
                                                @lang($column)
                                            </td>
                                            <td>
                                                @if($column === 'parent_id' && $result->parent_id !== null)
                                                    <a href="{{  route($router . '.show', [
                                                            'id' => $result->parent_id,
                                                            'classId' => $result->parent_class_id
                                                        ]) }}">
                                                            <span class="btn btn-link center-block">
                                                                {{ $result->parent_id  }} - {{ $result->parent_class }}
                                                            </span>
                                                    </a>
                                                @elseif($column === 'location' && $result->location_id !== null)
                                                    <a href="{{  route('locations.show', [
                                                            'id' => $result->location_id
                                                        ]) }}">
                                                            <span class="btn btn-link center-block">
                                                                {{ $result->$column  }}
                                                            </span>
                                                    </a>
                                                @elseif($column === 'manufacturer' && $result->manufacturer_id !== null)
                                                    <a href="{{  route('manufacturers.show', [
                                                            'id' => $result->manufacturer_id
                                                        ]) }}">
                                                            <span class="btn btn-link center-block">
                                                                {{ $result->$column  }}
                                                            </span>
                                                    </a>
                                                @elseif($column === 'supplier' && $result->supplier_id !== null)
                                                    <a href="{{  route('suppliers.show', [
                                                            'id' => $result->supplier_id
                                                        ]) }}">
                                                            <span class="btn btn-link center-block">
                                                                {{ $result->$column  }}
                                                            </span>
                                                    </a>
                                                @elseif($column === 'children_ids' && is_array($result->children_ids))
                                                    @foreach($result->children_ids as $children_id)
                                                        <a href="{{  route("entities.index", [
                                                                'classId' => $children_id['class_id'],
                                                                ($router === 'entity'? 'type_id' : 'parent_id') => "*$result->id*"
                                                            ]) }}">
                                                            <span class="btn btn-link center-block">
                                                                {{ $children_id['class_name'] }}
                                                                ({{ $children_id['entities_count'] }})
                                                            </span>
                                                        </a>
                                                    @endforeach
                                                @else
                                                    {{ $result->$column ?: '-' }}
                                                @endif
                                            </td>
                                        </tr>
                                    @endforeach
                                    </tbody>
                                </table>
                            </div>
                        </div>
                        @if($canEdit || $canDelete)

                            @if($canEdit && !$canDelete)
                                <div class="panel-footer text-center">
                                    <a class="btn btn-labeled btn-default"
                                       href="{{ route($router . '.edit', [
                                            'id' => $objectId,
                                            'classId' => $classId
                                       ]) }}">
                                                        <span class="btn-label">
                                                            <i class="glyphicon glyphicon-edit"></i>
                                                            @lang('do.Edit')
                                                        </span>
                                    </a>
                                </div>
                            @endif
                            @if($canDelete)
                                <div class="panel-footer">
                                    <form action="{{ route($router . '.destroy', [
                                                        'id' => $objectId,
                                                        'classId' => $classId
                                                    ]) }}"
                                          method="post">
                                        {{ method_field('DELETE') }}
                                        {{ csrf_field() }}
                                        <button type="submit" class="btn btn-labeled btn-default">
                                            <span class="btn-label">
                                                <i class="glyphicon glyphicon-trash text-danger"></i>
                                                @lang('do.Delete')
                                            </span>
                                        </button>
                                        @if($canEdit)
                                            <div class="pull-right">
                                                <a class="btn btn-labeled btn-default"
                                                   href=" {!! route($router . '.edit', [
                                                        'id' => $objectId,
                                                        'classId' => $classId
                                                   ]) !!} ">
                                                        <span class="btn-label">
                                                            <i class="glyphicon glyphicon-edit"></i>
                                                            @lang('do.Edit')
                                                        </span>
                                                </a>
                                            </div>
                                        @endif
                                    </form>
                                </div>
                            @endif
                        @endif
                    @else
                        @lang($nothingFound)!
                    @endif
                </div>
            </div>
        </div>
@endsection
