@extends('layouts.admin')

@php
    if($create){
        $title = __('adminforms.pages.title_insert');
        $formpar = array('route' => 'admin.page.store');
    } else {
        $title = __('adminforms.pages.title_update');
        $formpar = array('route' => array('admin.page.update', $page->page_id), 'method' => 'PUT');
    }

    $tr = [
        'page gr id'  => __('adminforms.pages.page_gr_id'),
        'page name'   => __('adminforms.pages.page_name'),
        'page text'   => __('adminforms.pages.page_text'),
        'page desc'   => __('adminforms.pages.page_desc'),
        'page keyw'   => __('adminforms.pages.page_keyw'),
        'page act'    => __('adminforms.pages.page_act'),
        'page in nav' => __('adminforms.pages.page_in_nav'),
    ];
@endphp

@section('title'){{$title}}@endsection
@section('header'){{$title}}@endsection
@section('header_desc') @endsection
@section('breadcumbs') @endsection

@section('content')
    <!-- Main content -->
    <section class="content">



        <div class="row">

            <div class="col-xs-12">
                @if (session('error'))
                    <div class="alert alert-danger alert-dismissible">
                        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                        <i class="icon fa fa-exclamation-triangle"></i> <strong>Info: </strong> &nbsp;  &nbsp;
                        {{ session('error') }}
                    </div>
                @endif
            </div>

            {!! Form::open($formpar) !!}

            <div class="col-xs-12">



                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title"><i class="fa fa-list-alt"></i> {{$title}}</h3>
                    </div><!-- /. panel-heading -->

                    <div class="panel-body">
                        <div class="row">



                            <div class="col-xs-12 col-sm-6 col-md-3 pbb">
                                @php $pgId = old('page_gr_id', $page->page_gr_id); @endphp
                                {{Form::label('page_gr_id', ucfirst(__('adminforms.pages.page_gr_id').':'))}}
                                {{Form::select('page_gr_id', $pgroups, $pgId, ['placeholder' => __('adminforms.pages.select_group'), 'class' => 'form-control', 'id' => 'group-select'])}}
                                <small class="error">{{ strtr($errors->first('page_gr_id'),$tr) }}</small>
                            </div>

                            <div class="col-xs-12 col-sm-6 col-md-3 pbb">
                                {{Form::label('page_act', ucfirst(__('adminforms.pages.page_act').':'))}}<br>
                                @php
                                    $cv = old('page_act', $page->page_act);
                                    $actval = !is_null($cv) ? $cv : 1;
                                @endphp
                                <label class="radio-inline"><input type="radio" name="page_act" value="1" {{ $actval== 1 ? 'checked': ''}} > {{__('adminforms.common.true')}}</label>
                                <label class="radio-inline"><input type="radio" name="page_act" value="0" {{ $actval== 0 ? 'checked': ''}} > {{__('adminforms.common.false')}}</label>
                                <small class="error">{{ strtr($errors->first('page_act'),$tr) }}</small>
                            </div>

                            <div class="col-xs-12 col-sm-6 col-md-3 pbb">
                                {{Form::label('page_in_nav', ucfirst(__('adminforms.pages.page_in_nav').':'))}}<br>
                                @php
                                    $cv = old('page_in_nav', $page->page_in_nav);
                                    $actval = !is_null($cv) ? $cv : 1;
                                @endphp
                                <label class="radio-inline"><input type="radio" name="page_in_nav" value="1" {{ $actval== 1 ? 'checked': ''}} > {{__('adminforms.common.true')}}</label>
                                <label class="radio-inline"><input type="radio" name="page_in_nav" value="0" {{ $actval== 0 ? 'checked': ''}} > {{__('adminforms.common.false')}}</label>
                                <small class="error">{{ strtr($errors->first('page_in_nav'),$tr) }}</small>
                            </div>

                            <div class="col-xs-12">
                                <hr>
                            </div>


                            @foreach(config('app.languages') as $lang)

                                @php

                                    $t_page_name  = '';
                                    $t_page_desc  = '';
                                    $t_page_keyw  = '';
                                    $t_page_text  = '';
                                    $t_slug       = '';

                                    $translation = $page->translation($lang);
                                    if($translation){
                                        $t_page_name  = $translation->page_name;
                                        $t_page_desc  = $translation->page_desc;
                                        $t_page_keyw  = $translation->page_keyw;
                                        $t_page_text  = $translation->page_text;
                                    }

                                    $route = $page->route($lang);

                                    if($route){
                                        $t_slug             = $route->slug;
                                    }

                                @endphp

                                <div class="col-xs-12"><label class="lang-intro" for="">{{ucfirst(__('adminforms.common.'.$lang.'_version').':')}}</label></div>


                                <div class="col-xs-12 col-sm-6 col-md-6 pbb">
                                    {{Form::label($lang.'_'.'page_name', strtoupper($lang).' '.ucfirst(__('adminforms.pages.page_name').':'))}}
                                    {{Form::text($lang.'_'.'page_name', old($lang.'_'.'page_name', $t_page_name ), ['class' => 'form-control',  'id' => $lang.'name'])}}
                                    <small class="error">{{ strtr($errors->first($lang.'_'.'page_name'),$tr) }}</small>
                                </div>

                                <div class="col-xs-12 col-sm-6 col-md-6 pbb">
                                    {{Form::label($lang.'_'.'slug', strtoupper($lang).' '.ucfirst(__('adminforms.common.slug').__('adminforms.common.slug_info').':'))}}
                                    {{Form::text($lang.'_'.'slug', old($lang.'_'.'slug', $t_slug ), ['class' => 'form-control', 'id' => $lang.'slug'])}}
                                    <small class="error">{{ strtr($errors->first($lang.'_'.'slug'),$tr) }}</small>
                                </div>

                                <div class="col-xs-12 col-sm-6">
                                    {{Form::label($lang.'_'.'page_desc', strtoupper($lang).' '.ucfirst(__('adminforms.pages.page_desc').':'))}}
                                    {{Form::textarea ($lang.'_'.'page_desc', old($lang.'_'.'page_desc', $t_page_desc), ['class' => 'form-control', 'rows' => 3])}}
                                    <small class="error">{{ strtr($errors->first($lang.'_'.'page_desc'),$tr) }}</small>
                                </div>


                                <div class="col-xs-12 col-sm-6">
                                    {{Form::label($lang.'_'.'page_keyw', strtoupper($lang).' '.ucfirst(__('adminforms.pages.page_keyw').':'))}}
                                    {{Form::textarea ($lang.'_'.'page_keyw', old($lang.'_'.'page_keyw', $t_page_keyw), ['class' => 'form-control', 'rows' => 3])}}
                                    <small class="error">{{ strtr($errors->first($lang.'_'.'page_keyw'),$tr) }}</small>
                                </div>


                                <div class="col-xs-12">
                                    <hr>
                                </div>


                                <div class="col-xs-12">
                                    {{Form::label($lang.'_'.'page_text', strtoupper($lang).' '.ucfirst(__('adminforms.pages.page_text').':'))}}
                                    <br><small class="error">{{ strtr($errors->first($lang.'_'.'page_text'),$tr) }}</small>
                                    {{Form::textarea($lang.'_'.'page_text', old($lang.'_'.'page_text', $t_page_text), ['class' => 'form-control', 'id' => 'texteditor'.$lang])}}

                                </div>


                            @endforeach




                            <br clear="all">
                            <hr>
                            <div class="col-xs-12">
                                @php $btntext = ($create) ? __('adminforms.pages.btn_insert') : __('adminforms.pages.btn_update')@endphp
                                {{Form::submit($btntext, ['class' => 'btn btn-success pull-right'])}}
                            </div>

                        </div> <!-- /.row -->
                    </div> <!-- /.panel-body -->
                </div> <!-- /.panel panel-default-->

            </div> <!-- /.col -->



            {!! Form::close() !!}

        </div>
        <!-- /.row -->

    </section>
@endsection

@push('css')
@endpush


@push('scripts')
    <script src="{{asset('assets/js/equalpbb.js')}}"></script>
    <script src="{{asset('ckeditor/ckeditor.js')}}"></script>
    <script>
        // omogucavanje na mobilnim uredjajima
        //CKEDITOR.env.isCompatible = true;
    </script>
    <script src="{{asset('ckeditor/ckeditor_autogrow.js')}}"></script>
    <script src="{{asset('ckeditor/adapters/jquery.js')}}"></script>
    <script>
        CKEDITOR.config.jqueryOverrideVal = true;
        CKEDITOR.config.extraPlugins = "ckeditor_autogrow";
        CKEDITOR.config.baseFloatZIndex = 102000;
    </script>
    <script type="text/javascript">
        $(document).ready(function(){
            //alert('ready');
            @foreach(config('app.languages') as $lang)
            if($("#texteditor{{$lang}}").length) {
                $("#texteditor{{$lang}}").ckeditor({toolbar: 'Basic', minHeight: 250, width: "100%"});
            }
            @endforeach
        });
    </script>
    <script>
        $(document).ready(function(){
            @foreach(config('app.languages') as $lang)
            $('#{{$lang}}name').keyup(function () {
                var cval = $.trim($(this).val());
                var cslug = cval.replace(/\s/g, '-').toLowerCase();
                $('#{{$lang}}slug').val(cslug);
            });
            $('#{{$lang}}name').blur(function () {
                var cval = $.trim($(this).val());
                var cslug = cval.replace(/\s/g, '-').toLowerCase();
                $('#{{$lang}}slug').val(cslug);
            });
            @endforeach
        });
    </script>
@endpush