@extends('adminpanel.layouts.app')

@section('title')Переводы@endsection

@section('content')
    <div class="content">
        <div class="card" style="width: 100%;">
            <div class="card-header pb-0">
                <nav class="nav nav-pills float-left" id="nav-tab" role="tablist">
                    @foreach($translations as $tabIndex=>$value)
                        @if(($pages->where('id',$tabIndex)->first() !==null))
                            <a class="nav-item nav-link m-2 @if($tabIndex==0)active @endif"
                               id="nav-{!! $tabIndex !!}-tab"
                               data-toggle="tab" href="#nav-{!! $tabIndex !!}"
                               role="tab"
                               aria-controls="nav-{!! $tabIndex !!}"
                               aria-selected="@if($tabIndex==0)true @else false @endif">@if($tabIndex==0) Все
                                страницы @else {!! $pages->where('id',$tabIndex)->first()->title_ru !!} @endif </a>
                        @endif
                    @endforeach
                </nav>
                <button type="button" class="btn btn-info float-right m-2" data-toggle="modal"
                        data-target="#ModalTranslate-new">Добавить перевод
                </button>
                <button type="submit" class="btn btn-success float-right m-2" form="ServicesSave">Сохранить
                    изменения
                </button>
                <div class="modal fade" id="ModalTranslate-new" tabindex="-1"
                     role="dialog" aria-labelledby="ModalTranslate-newTitle"
                     aria-hidden="true">
                    <div class="modal-dialog modal-dialog-centered" role="document">
                        <div class="modal-content">
                            <form method="POST" action="{{route('createTranslations')}}"
                                  enctype="multipart/form-data">
                                @csrf
                                <div class="modal-header">
                                    <h5 class="modal-title"
                                        id="ModalNewsCategory-newTitle">Создать перевод</h5>
                                    <button type="button" class="close"
                                            data-dismiss="modal" aria-label="Close">
                                        <span aria-hidden="true">&times;</span>
                                    </button>
                                </div>
                                @php
                                    $table_name = (new \App\Models\Translate())->getTable();
                                @endphp
                                <div class="modal-body">
                                    <div class="form-group">
                                        <label for="translate-new-key">Ключ</label>
                                        <input type="text" class="form-control"
                                               id="translate-new-key"
                                               name="{{$table_name}}[new][key]"
                                               value="">
                                    </div>
                                    <div class="form-group">
                                        <label for="translate-new-ru_text">Перевод (Рус)</label>
                                        <input type="text" class="form-control"
                                               id="translate-new-ru_text"
                                               name="{{$table_name}}[new][ru_text]"
                                               value="">
                                    </div>
                                    <div class="form-group">
                                        <label for="translate-new-en_text">Перевод (Анг)</label>
                                        <input type="text" class="form-control"
                                               id="translate-new-en_text"
                                               name="{{$table_name}}[new][en_text]"
                                               value="">
                                    </div>
                                    <div class="form-group">
                                        <label for="translate-new-model_id">Страница перевода</label>
                                        <select class="form-control chzn-select" tabindex="2"
                                                id="translate-new-model_id"
                                                name="{{$table_name}}[new][model_id]"
                                                data-placeholder="Выберите значение...">
                                            <option value="0">Все страницы</option>
                                            @foreach($pages as $page)
                                                <option value="{{$page->id}}">{!! $page->title_ru !!} ({{$page->type}}
                                                    )
                                                </option>
                                            @endforeach
                                        </select>
                                    </div>
                                </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-secondary"
                                            data-dismiss="modal">Закрыть
                                    </button>
                                    <button type="submit" class="btn btn-success">
                                        Сохранить изменения
                                    </button>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
            <div class="card-body">
                <form method="POST" action="{{route('ServicesSave')}}" id="ServicesSave">
                    @csrf
                    <div class="tab-content" id="nav-tabContent">
                        @foreach($translations as $key=>$translates)
                            <div class="tab-pane fade @if($key == 0 )show active @endif" id="nav-{!! $key !!}"
                                 role="tabpanel" aria-labelledby="nav-{!! $key !!}-tab">
                                <div class="content">
                                    <div class="row">
                                        <div class="col-3 form-group">
                                            <p class="h5 text-center">Ключ</p>
                                            <hr>
                                        </div>
                                        <div class="col-4 form-group">
                                            <p class="h5 text-center">Рус</p>
                                            <hr>
                                        </div>
                                        <div class="col-4 form-group">
                                            <p class="h5 text-center">Анг</p>
                                            <hr>
                                        </div>
                                        <div class="col-1 form-group">
                                        </div>
                                    </div>
                                    <div class="row">
                                        @foreach($translates as $translation)
                                            <div class="col-3 form-group">
                                                <p class="h5 text-center">{!! $translation->key !!}</p>
                                                <input type="hidden" class="hide" id="translation_key"
                                                       name="translations[{{$translation->id}}][{!! $translation->key !!}]"
                                                       value="{!! $translation->key !!}" hidden>
                                            </div>
                                            <div class="col-4 form-group">
                                                <input type="text" class="form-control" id="translation_ru_text"
                                                       name="translations[{{$translation->id}}][{!! $translation->key !!}][ru_text]"
                                                       value="{!! $translation->ru_text !!}">
                                            </div>
                                            <div class="col-4 form-group">
                                                <input type="text" class="form-control" id="translation_en_text"
                                                       name="translations[{{$translation->id}}][{!! $translation->key !!}][en_text]"
                                                       value="{!! $translation->en_text !!}">
                                            </div>
                                            <div class="col-1 form-group text-center mt-2">
                                                <a class="btn btn-danger btn-sm"
                                                   href="{{route('deleteTranslations',['translate'=>$translation->id])}}">Удалить</a>
                                            </div>
                                        @endforeach
                                    </div>
                                </div>
                            </div>
                        @endforeach
                    </div>
                </form>
            </div>
        </div>
    </div>
@endsection
