@extends('layouts.layout-2')

@section('content')
    <style>
        .alert ul {
            margin-bottom: 0;
        }

    </style>
    @if ($errors->any())
        <div class="row">
            <div class="col-sm-12">
                <div class="alert alert-danger">
                    <ul>
                        @foreach ($errors->all() as $error)
                            <li>{{ $error }}</li>
                        @endforeach
                    </ul>
                </div>
            </div>
        </div>
    @endif



    <h4 class="font-weight-bold py-3 mb-1">
        Reiseführer Tree @if($id == "new") <span class="text-primary">anlegen</span> @else {{"(".$model->name.")"}}
        verwalten @endif
        {{--  <div class="float-right">
             <a href="{{route('iq_content_tree_repair', [$model->id])}}" class="btn btn-default btn-sm">{{ __('repair') }}</a>
         </div>
         --}}
    </h4>
    <div class="clearfix"></div>

    <input type="hidden" name="id" id="id" value="{{$id}}">

    <div class="row mx-0">

        <!-- Messages sidebox -->
        <div class="messages-sidebox mb-4">
            <button type="button" class="btn btn-primary btn-sm btn-block" data-toggle="modal"
                    data-target="#modals-load-content"
                    data-id="add"
                    data-model="tree"
                    data-action="tree-node"
                    data-request="{!! array_to_json(['tree_id'=>$model->id]) !!}"
                    data-route="{{ route('iq_content_modal_load') }}"><i class="ion ion-ios-add-circle"></i> Add node
            </button>
            <hr class="border-light my-1">

            <div class="">
                {!! Form::open(['url' => route('iq_content_tree_detail', [$model->id]), 'class' => '']) !!}
                <input type="hidden" id="nestable-output" name="nestable-output" value="">
                <input type="hidden" name="tree_id" value="{{$model->id}}">

                <div class="mb-2" style="height: 35px">
                    <div class="float-right">
                        <button type="button" class="btn btn-default btn-sm" data-action="expand-all"
                                id="nestable-menu-expand"><i class="ion ion-ios-arrow-down"></i></button>
                        <button type="button" class="btn btn-default btn-sm" data-action="collapse-all"
                                id="nestable-menu-collapse"><i class="ion ion-ios-arrow-up"></i></button>
                    </div>
                    <div class="iq-save-bar" style="display: none">
                        <a href="" class="btn btn-warning btn-md icon-btn messages-tooltip text-white mr-2"
                           title="Refresh"><i class="ion ion-md-refresh"></i></a>
                        <button type="submit" class="btn btn-success  btn-md icon-btn messages-tooltip text-white"
                                title="Save"><i class="ion ion-md-save"></i></button>
                    </div>
                </div>
                <div>
                    <div class="badge badge-outline-primary btn-block py-2 px-3 text-left "><span
                                class="fa fa-globe"></span> {{$model->name}}
                        <a href="" class="float-right" data-toggle="modal" data-target="#modals-load-content"
                           data-id="{{$model->id}}"
                           data-model="tree"
                           data-action="tree-content"
                           data-request=""
                           data-route="{{ route('iq_content_modal_load') }}"><span class="fa fa-edit"></span></a>
                    </div>
                    <div class="dd" id="netstable-content-tree" data-id="{{$model->id}}">
                        {!! \App\Services\HTMLTreeHelper::makeNestableList($model, ($tree_node ? $tree_node->id : false)) !!}
                    </div>
                </div>
                {!! Form::close() !!}
            </div>

        </div>
        <!-- / Messages sidebox -->

        <div class="col">
            @if($tree_node)
                <div class="card">
                    <div class="card-body py-3">
                        <!-- Controls -->
                        {!! Form::open(['url' => route('iq_content_tree_detail', [$model->id, $tree_node->id, ($section? $section : '')]), 'class' => '']) !!}
                        <div class="media flex-wrap align-items-center py-2 px-0">
                            <div class="media-body d-flex flex-wrap flex-basis-100 flex-basis-sm-auto">
                                <div class="iq-save-bar" style="display: none">
                                    <a href="" class="btn btn-warning btn-md icon-btn messages-tooltip text-white mr-2"
                                       title="Refresh"><i class="ion ion-md-refresh"></i></a>
                                    <button type="submit"
                                            class="btn btn-success  btn-md icon-btn messages-tooltip text-white"
                                            title="Save"><i class="ion ion-md-save"></i></button>
                                </div>
                            </div>
                        </div>
                        <div class="">
                            {{--  <div class="nav-responsive-md">
                                 <ul class="nav nav-pills nav-fill">
                                     <li class="nav-item">
                                         <a  href="{{route('iq_content_tree_detail', [$model->id, $tree_node->id])}}" class="nav-link @if(!$section) active1 @endif">{{$tree_node->name}}
                                         </a>
                                     </li>
                                     @if($tree_node->iq_content_sites)
                                         @foreach($tree_node->iq_content_sites as $iq_content_site)
                                             <li class="nav-item">
                                                 <a  href="{{route('iq_content_tree_detail', [$model->id, $tree_node->id,$iq_content_site->id])}}" class="nav-link @if($iq_content_site && $iq_content_site->id == $section) active @endif">{{ $iq_content_site->id }}

                                                 </a>
                                             </li>
                                         @endforeach
                                     @endif
                                 </ul>
                             </div>
                                 --}}

                            @if(!$site_fields)
                                <div class="">
                                    <input type="hidden" name="id" value="{{$tree_node->id}}">
                                    <input type="hidden" name="model" value="tree">
                                    <input type="hidden" name="action" value="tree-node">
                                    <input type="hidden" name="tree_id" value="{{$model->id}}">

                                    <h4 class="mb-0 bg-light p-1">Name / Link</h4>
                                    <hr class="mt-0">
                                    <div class="form-row mb-2">
                                        <div class="form-group col">
                                            <label class="custom-control custom-checkbox float-right">
                                                {!! Form::checkbox('active', 1, $tree_node->active, ['class'=>'custom-control-input']) !!}
                                                <span class="custom-control-label">{{__('aktiv')}}</span>
                                            </label>
                                            <label for="name" class="form-label">Name (Navigation)*</label>
                                            {{ Form::text('name', $tree_node->name,  array('placeholder'=>'', 'class'=>'form-control', 'required'=>'true')) }}
                                        </div>
                                    </div>
                                    <div class="form-row">
                                        <div class="form-group col-10 col-sm-11">
                                            <div class="input-group mb-4">
                                                <div class="input-group-prepend">
                                                    <span class="input-group-text">
                                                          <a href="{{ $tree_node->getUrl() }}" class="" target="_blank">
                                                            <span class="fa fa-external-link-alt mr-2 text-secondary"></span>
                                                            </a>
                                                    </span>
                                                </div>
                                                {{ Form::text('uri', $tree_node->getUri(),  array('readonly'=>true, 'class'=>'form-control')) }}
                                            </div>
                                        </div>
                                        <div class="form-group col-2 col-sm-1">
                                            <a class="btn btn-sm btn-danger float-right" href="{{ route('iq_content_tree_delete', [$model->id, $tree_node->id, ($section? $section : '')]) }}" onclick="return confirm('Wirklich löschen? Node wird mit allen Unter-Nodes und Verknüpfungen gelöscht. ');">
                                                <i class="fa fa-trash-alt"></i>
                                            </a>
                                        </div>
                                    </div>

                                    <h4 class="mb-0 bg-light p-1">Seiten</h4>
                                    <hr class="mt-0">
                                    <div class="form-row mb-2">
                                        <div class="form-group col">
                                            <button type="button" class="btn btn-primary btn-sm float-right mb-2"
                                                    data-toggle="modal" data-target="#modals-load-content"
                                                    data-id="add"
                                                    data-model="tree"
                                                    data-action="tree-site-content"
                                                    data-request="{!! array_to_json(['tree_id'=>$model->id,'tree_node_id'=>$tree_node->id]) !!}"
                                                    data-route="{{ route('iq_content_modal_load') }}"><i
                                                        class="ion ion-ios-add-circle"></i> Seite hinzufügen
                                            </button>
                                            @if($tree_node->iq_content_sites->count())
                                                <table class="table table-striped border-bottom">
                                                    <thead>
                                                    <tr>
                                                        <th style="max-width: 60px;">&nbsp;</th>
                                                        <th>{{__('Name')}}</th>
                                                        <th>{{__('Zuordnung')}}</th>
                                                        <th>{{__('Keyword')}}</th>
                                                        <th>{{__('Langer Text')}}</th>
                                                        <th>{{__('sichtbar')}}</th>
                                                        <th>#</th>
                                                    </tr>
                                                    </thead>
                                                    <tbody>
                                                    @foreach($tree_node->iq_content_sites as $iq_content_site)
                                                        <tr>
                                                            <td style="width: 5%;">
                                                                <a href="{{ route('cms_travel_guide_detail', [$iq_content_site->travel_guide->id]) }}"
                                                                   class="btn icon-btn btn-sm btn-primary">
                                                                    <span class="fa fa-edit"></span>
                                                                </a>
                                                            </td>
                                                            <td>{{$iq_content_site->travel_guide->name}}</td>
                                                            <td><button type="button" class="btn btn-xs btn-secondary"
                                                                        data-toggle="modal" data-target="#modals-load-content"
                                                                        data-id="{{$iq_content_site->id}}"
                                                                        data-model="tree"
                                                                        data-action="site-travel-identifier"
                                                                        data-request="{!! array_to_json(['tree_id'=>$model->id,'tree_node_id'=>$tree_node->id]) !!}"
                                                                        data-route="{{ route('iq_content_modal_load') }}">
                                                                    <i class="fa fa-edit"></i> {{$iq_content_site->getTravelType()}}</button>
                                                            </td>

                                                            <td>{{$iq_content_site->travel_guide->keyword}}</td>
                                                            <td> @if($iq_content_site->travel_guide->scope)
                                                                    <span class="badge badge-pill badge-success"><i
                                                                                class="fa fa-check"></i></span>
                                                                @else
                                                                    <span class="badge badge-pill badge-danger"><i
                                                                                class="fa fa-times"></i></span>
                                                                @endif
                                                            </td>
                                                            <td>
                                                                @if($iq_content_site->travel_guide->active)
                                                                    <span class="badge badge-pill badge-success"><i
                                                                                class="fa fa-check"></i></span>
                                                                @else
                                                                    <span class="badge badge-pill badge-danger"><i
                                                                                class="fa fa-times"></i></span>
                                                                @endif
                                                            </td>
                                                            <td>
                                                                <a class="text-danger"
                                                                   href="{{ route('iq_content_tree_detail_remove', ['guide', $model->id, $tree_node->id, $iq_content_site->travel_guide->id, 'tree']) }}"
                                                                   title="entfernen" data-placement="left" rel="tooltip" onclick="return confirm('{{__('Seite aus Tree entfernen?')}}');">
                                                                    <i class="fa fa-reply"></i>
                                                                </a>
                                                            </td>
                                                        </tr>
                                                    @endforeach
                                                    </tbody>
                                                </table>
                                            @endif

                                            {{--<select class="selectpicker" name="site_id" id="site_id"
                                                    data-style="btn-light" data-live-search="true" data-container="body">
                                                 {!! \App\Models\IQContentSite::getSiteOptions($tree_node->site_id) !!}

                                            </select>--}}
                                        </div>
                                    </div>

                                    <h4 class="mb-0 bg-light p-1">Hauptbild</h4>
                                    <hr class="mt-0">
                                    <div class="media mx-auto pb-3" id="lfm-data-fill">
                                        <img src="{{$tree_node->getImage('thumb_url')}}" alt="" class="img_thumb_url d-block ui-w-100">
                                        <div class="media-body mt-2 ml-2">
                                            <div class="form-row">
                                                <div class="form-group col-10 col-sm-11" >
                                                    {{ Form::hidden('image[slug]', $tree_node->getImage('slug')) }}
                                                    {{ Form::hidden('image[thumb_url]', $tree_node->getImage('thumb_url')) }}
                                                    {{ Form::hidden('image[url]', $tree_node->getImage('url')) }}
                                                    {{ Form::text('image[title]', $tree_node->getImage('title'),  array('placeholder'=>'Bildtitel', 'class'=>'form-control mb-2')) }}
                                                    {{ Form::text('image[alt]', $tree_node->getImage('alt'),  array('placeholder'=>'Bild ALT Tag', 'class'=>'form-control')) }}
                                                </div>
                                                <div class="form-group col-2 col-sm-1">
                                                    <button type="button" class="btn btn-sm btn-secondary float-right btn-lfm-open-modal"
                                                            data-id="#lfm-data-fill"
                                                            data-obj="image"
                                                            data-set='["url", "slug", "thumb_url"]'
                                                            data-img='.img_thumb_url'
                                                            data-title="title"
                                                            data-alt="alt">
                                                        <i class="fa fa-image"></i>
                                                    </button>
                                                </div>
                                            </div>
                                        </div>
                                    </div>

                                    <h4 class="mb-0 bg-light p-1">Fragen &amp; Antworten</h4>
                                    <hr class="mt-0">
                                    <div class="form-row mb-2">
                                        <div class="form-group col">
                                            <button type="button" class="btn btn-primary btn-sm float-right mb-2"
                                                    data-toggle="modal" data-target="#modals-load-content"
                                                    data-id="add"
                                                    data-model="tree"
                                                    data-action="add-answer-question"
                                                    data-request="{!! array_to_json(['tree_id'=>$model->id,'tree_node_id'=>$tree_node->id]) !!}"
                                                    data-route="{{ route('iq_content_modal_load') }}"><i
                                                        class="ion ion-ios-add-circle"></i> Eintrag hinzufügen
                                            </button>
                                            <table class="table table-striped border-bottom">
                                                <thead>
                                                <tr>
                                                    <th style="max-width: 60px;">&nbsp;</th>
                                                    <th>{{__('Frage')}}</th>
                                                    <th>{{__('sichtbar')}}</th>
                                                    <th>#</th>
                                                </tr>
                                                </thead>
                                                <tbody>
                                                @foreach($tree_node->iq_content_faqs as $iq_content_faq)
                                                    <tr>
                                                        <td style="width: 5%;">
                                                            <a href="{{ route('cms_answer_question_detail', [$iq_content_faq->answer_question->id]) }}"
                                                               class="btn icon-btn btn-sm btn-primary">
                                                                <span class="fa fa-edit"></span>
                                                            </a>
                                                        </td>
                                                        <td>{{$iq_content_faq->answer_question->question}}</td>
                                                        <td>
                                                            @if($iq_content_faq->answer_question->active)
                                                                <span class="badge badge-pill badge-success"><i
                                                                            class="fa fa-check"></i></span>
                                                            @else
                                                                <span class="badge badge-pill badge-danger"><i
                                                                            class="fa fa-times"></i></span>
                                                            @endif
                                                        </td>
                                                        <td>
                                                            <a class="text-danger"
                                                               href="{{ route('iq_content_tree_detail_remove', ['faq', $model->id, $tree_node->id, $iq_content_faq->answer_question->id, 'tree']) }}"
                                                               title="entfernen" data-placement="left" rel="tooltip" onclick="return confirm('{{__('Eintrag entfernen?')}}');">
                                                                <i class="fa fa-reply"></i>
                                                            </a>
                                                        </td>
                                                    </tr>
                                                @endforeach
                                                </tbody>
                                            </table>

                                        </div>
                                    </div>

                                    <h4 class="mb-0 bg-light p-1">Meta</h4>
                                    <hr class="mt-0">
                                    <div class="form-row mb-2">
                                        <div class="form-group col">
                                            <label for="identifier" class="form-label">Slug</label>
                                            {{ Form::text('identifier', $tree_node->identifier,  array('placeholder'=>'', 'class'=>'form-control')) }}
                                        </div>
                                    </div>
                                    <div class="form-row mb-2">
                                        <div class="form-group col">
                                            <label for="title" class="form-label">Title</label>
                                            {{ Form::text('title', $tree_node->title,  array('placeholder'=>'META-Titel', 'class'=>'form-control')) }}
                                        </div>
                                    </div>
                                    <div class="form-group mb-2">
                                        <label class="form-label" for="description">Description</label>
                                        {{ Form::textarea('description', $tree_node->description,  array('class'=>'form-control', 'rows'=>2)) }}
                                    </div>
                                </div>
                            @else
                                <div id="dragula-drag-handles" class="mt-2">
                                    @foreach($site_fields as $key => $site_field)
                                        <div class="dragula-example card card-condenced">
                                            <input type="hidden" name="iq_content_site_field[{{$key}}][id]"
                                                   value="{{ $site_field->id }}">
                                            <input type="hidden" name="iq_content_site_field[{{$key}}][site_id]"
                                                   value="{{$site_field->site_id}}">
                                            <input type="hidden" name="iq_content_site_field[{{$key}}][model_field_id]"
                                                   value="{{$site_field->model_field_id}}">
                                            <input type="hidden" name="iq_content_site_field[{{$key}}][field]"
                                                   value="{{$site_field->field}}">
                                            <input type="hidden" name="iq_content_site_field[{{$key}}][settings]"
                                                   value="{{ json_encode($site_field->settings) }}">
                                            <div class="card-body">
                                                <span class="handle fa fa-grip-vertical d-inline-block bg-light text-info p-2 mr-2 mb-1"></span>
                                                <i class="my-ui-icon-sm {{ $site_field->iq_content_model_field->fieldAsIcon() }} text-secondary mr-2"></i>
                                                <strong>{{ $site_field->iq_content_model_field->name }}</strong>
                                                <span class="text-muted ml-2">{{ $site_field->iq_content_model_field->identifier }}</span>
                                                <div class="float-right">
                                                    {!! get_switcher_input($site_field->active, 'iq_content_site_field['.$key.'][active]') !!}

                                                </div>
                                                <hr class="border-light my-2">
                                                <div class="form-group">
                                                    @if($site_field->field == "string")
                                                        {{ Form::text('iq_content_site_field['.$key.'][content]', $site_field->content,  array('class'=>'form-control')) }}
                                                    @endif
                                                    @if($site_field->field == "text")
                                                        @if($site_field->settings['editor'] == 'off')
                                                            {{ Form::textarea('iq_content_site_field['.$key.'][content]', $site_field->content , ['class' => 'form-control']) }}
                                                        @else
                                                            {{ Form::textarea('iq_content_site_field['.$key.'][content]', $site_field->content , ['class' => 'form-control summernote']) }}
                                                        @endif
                                                    @endif
                                                    @if($site_field->field == "media")
                                                        {{ Form::text('iq_content_site_field['.$key.'][content]', $site_field->content,  array('class'=>'form-control')) }}
                                                    @endif
                                                </div>
                                                <span class="text-muted ml-2">{{ $site_field->iq_content_model_field->fieldAsName() }}</span>
                                                <div class="float-left">
                                                    <i class="fa fa-search"></i> {!! get_switcher_input($site_field->search, 'iq_content_site_field['.$key.'][search]') !!}
                                                </div>
                                            </div>
                                        </div>
                                    @endforeach
                                </div>
                            @endif
                        </div>
                        {!! Form::close() !!}
                    </div>
                </div>
            @endif
        </div>
    </div>


@endsection

@section('scripts')
    <script>
    $(document).ready(function() {
        $('.table [rel="tooltip"]').tooltip({trigger: "hover"});
        IqLFileManager.init();
    });
    </script>
@endsection