@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) {{ $customHeading?$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>
                                                {{ $result->$column ?: '-' }}
                                            </td>
                                        </tr>
                                    @endforeach
                                    @if($result->children_ids !== null && count($result->children_ids) > 0)
                                        <tr>
                                            <td>
                                                @lang('children_ids')
                                            </td>
                                            <td>
                                                @foreach($result->children_ids as $children_id)
                                                    @php($route = ($children_id->is_type) ? ("entity") : ("entities.index"))
                                                    <a href="{{  route($route, [
                                                            'classId' => $children_id->class_id,
                                                            strtolower($singular) => "*$result->name*"
                                                        ]) }}">
                                                            <span class="btn btn-link center-block">
                                                                {{ $children_id->class_name }}
                                                                ({{ $children_id->entities_count }})
                                                            </span>
                                                    </a>
                                                @endforeach
                                            </td>
                                        </tr>
                                    @endif
                                    </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
                                       ]) }}">
                                                        <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,
                                                        ''
                                                    ]) }}"
                                          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
                                                   ]) !!} ">
                                                        <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
