@extends('layouts.admin')

@php
    if($create){
        $title = 'Dodavanje grupe kategorija';
        $formpar = array('route' => 'admin.categorygroup.store');
    } else {
        $title = 'Izmena grupe kategorija';
        $formpar = array('route' => array('admin.categorygroup.update', $group->cg_id), 'method' => 'PUT');
    }

    $tr = [
        'cg name'  => __('adminforms.categorygroups.cg_name'),
        'cg feat'  => __('adminforms.categorygroups.cg_feat'),
        'cg img'   => __('adminforms.categorygroups.cg_img'),
        'cg icon'  => __('adminforms.categorygroups.cg_icon'),
        'cg title' => __('adminforms.categorygroups.cg_title'),
        'cg desc'  => __('adminforms.categorygroups.cg_desc'),
        'cg keyw'  => __('adminforms.categorygroups.cg_keyw'),
        'slug'     => __('adminforms.common.slug'),
    ];
@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="box">


                <!-- /.box-header -->
                    <div class="box-body">
                        <div class="row tp30">




                            <div class="col-xs-12 col-sm-6 col-md-3 pbb">
                                {{Form::label('cg_img', __('adminforms.categorygroups.cg_img').':')}}
                                {{Form::text('cg_img', old('cg_img', $group->cg_img), ['class' => 'form-control', 'onclick' => "openKCFinder('images',this, 'images/cgimages')"])}}
                                <small class="error">{{ strtr($errors->first('cg_img'),$tr) }}</small>
                            </div>

                            <div class="col-xs-12 col-sm-6 col-md-3 pbb">
                                {{Form::label('cg_icon', __('adminforms.categorygroups.cg_icon').':')}}
                                {{Form::text('cg_icon', old('cg_icon', $group->cg_icon), ['class' => 'form-control', 'onclick' => "openKCFinder('images',this, 'images/cgimages')"])}}
                                <small class="error">{{ strtr($errors->first('cg_icon'),$tr) }}</small>
                            </div>


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




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

                                @php

                                    $t_cg_name  = '';
                                    $t_cg_title = '';
                                    $t_cg_desc  = '';
                                    $t_cg_keyw  = '';
                                    $t_slug     = '';

                                    $translation = $group->translation($lang);
                                    if($translation){
                                        $t_cg_name  = $translation->cg_name;
                                        $t_cg_title = $translation->cg_title;
                                        $t_cg_desc  = $translation->cg_desc;
                                        $t_cg_keyw  = $translation->cg_keyw;
                                    }

                                    $route = $group->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.'_'.'cg_name', strtoupper($lang).' '.__('adminforms.categorygroups.cg_name').':')}}
                                    {{Form::text($lang.'_'.'cg_name', old($lang.'_'.'cg_name', $t_cg_name), ['class' => 'form-control',  'id' => $lang.'name'])}}
                                    <small class="error">{{ strtr($errors->first($lang.'_'.'cg_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">
                                    <hr>
                                </div>

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


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


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


                            @endforeach



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




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

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

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

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

    </section>
@endsection

@push('css')
@endpush


@push('scripts')
    <script type="text/javascript">
        function openKCFinder(type,field,dir) {
            //field = document.getElementById(field);//type : files / images / flash
            window.KCFinder = {  callBack: function(url) {  window.KCFinder = null;   field.value = url;}};
            window.open("/ckeditor/kcfinder/browse.php?type="+type+"&dir="+dir, "kcfinder_textbox","status=0, toolbar=0, location=0, menubar=0, directories=1,  " + "resizable=1, scrollbars=0, width=800, height=600");}
    </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