<?php
    if($create){
        $title = __('adminforms.carousels.title_insert');
        $formpar = array('route' => 'admin.carousel.store', 'autocomplete' => 'off');
    } else {
        $title = __('adminforms.carousels.title_update');
        $formpar = array('route' => array('admin.carousel.update', $carousel->car_id), 'method' => 'PUT', 'autocomplete' => 'off');
    }

    $tr = [
        'car id'     => __('adminforms.carousels.car_id'),
        'car title'  => __('adminforms.carousels.car_title'),
        'car type'   => __('adminforms.carousels.car_type'),
        'car order'  => __('adminforms.carousels.car_order'),
        'car limit'  => __('adminforms.carousels.car_limit'),
        'cg id'      => __('adminforms.carousels.cg_id'),
        'cat id'     => __('adminforms.carousels.cat_id'),
        'brand id'   => __('adminforms.carousels.brand_id'),
        'pos id'     => __('adminforms.carousels.pos_id'),
        'car active' => __('adminforms.carousels.car_active'),
        'prod id'    => __('adminforms.carousels.prod_id'),
    ];
?>

<?php $__env->startSection('title'); ?><?php echo e($title); ?><?php $__env->stopSection(); ?>
<?php $__env->startSection('header'); ?><i class="fa fa-th-large"></i> <?php echo e($title); ?><?php $__env->stopSection(); ?>
<?php $__env->startSection('header_desc'); ?> <?php $__env->stopSection(); ?>
<?php $__env->startSection('breadcumbs'); ?> <?php $__env->stopSection(); ?>

<?php $__env->startSection('content'); ?>
    <!-- Main content -->
    <section class="content">



        <div class="row">

            <div class="col-xs-12">
                <?php 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;
                        <?php echo e(session('error')); ?>

                    </div>
                <?php endif; ?>

                    <?php if($errors->any()): ?>
                        <div style="font-weight: bold; color: #9e0505"><?php echo e(__('adminforms.common.correct_errors')); ?></div>
                        <?php $__currentLoopData = $errors->all(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $error): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <div style="color: #9e0505;"><?php echo e(strtr($error, $tr)); ?></div>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        <br>
                    <?php endif; ?>
            </div>

            <?php echo Form::open($formpar); ?>


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


                <!-- /.box-header -->
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            <h3 class="panel-title"><i class="fa fa-list-alt"></i> <?php echo e(__('adminforms.carousels.general_block')); ?></h3>
                        </div>
                        <div class="panel-body">


                            <div class="row">



                                <div class="col-xs-12 col-sm-6 col-md-3 pbb">
                                    <?php $cgId = old('car_type', $carousel->car_type); ?>
                                    <?php echo e(Form::label('car_type', ucfirst(__('adminforms.carousels.car_type').':'))); ?>

                                    <?php echo e(Form::select('car_type', $types, $cgId, ['placeholder' => __('adminforms.common.select'), 'class' => 'form-control', 'id' => 'car-type-select'])); ?>

                                    <small class="error"><?php echo e(strtr($errors->first('car_type'),$tr)); ?></small>
                                </div>


                                <div class="col-xs-12 col-sm-6 col-md-3 pbb">
                                    <?php $cgId = old('car_order', $carousel->car_order); ?>
                                    <?php echo e(Form::label('car_order', ucfirst(__('adminforms.carousels.car_order').':'))); ?>

                                    <?php echo e(Form::select('car_order', $sorts, $cgId, ['class' => 'form-control', 'id' => 'car-order-select'])); ?>

                                    <small class="error"><?php echo e(strtr($errors->first('car_order'),$tr)); ?></small>
                                </div>

                                <div class="col-xs-12 col-sm-6 col-md-3 pbb">
                                    <?php $cgId = old('car_limit', $carousel->car_limit); ?>
                                    <?php echo e(Form::label('car_limit', ucfirst(__('adminforms.carousels.car_limit').':'))); ?>

                                    <?php echo e(Form::selectRange('car_limit', 6, 18, $cgId, [ 'class' => 'form-control', 'id' => 'car-limit-select'])); ?>

                                    <small class="error"><?php echo e(strtr($errors->first('car_limit'),$tr)); ?></small>
                                </div>

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


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


                                <div class="col-xs-12" id="itemsblock">
                                    <div class="row">

                                        <?php
                                            $oldType = old('car_type',$carousel->car_type);
                                        ?>


                                        <?php $style = ($oldType == 'b' || $oldType == 'cb') ? ' style="display: block;"' : ''; ?>
                                        <div class="col-xs-12 col-sm-6 col-md-3 pbb caroptsel" id="type_b" <?php echo $style; ?>>
                                            <?php $cgId = old('brand_id', $carousel->brand_id); ?>
                                            <?php echo e(Form::label('brand_id', ucfirst(__('adminforms.carousels.brand_id').':'))); ?>

                                            <?php echo e(Form::select('brand_id', $brands, $cgId, ['placeholder' => __('adminforms.common.select'), 'class' => 'form-control', 'id' => 'group-select'])); ?>

                                            <small class="error"><?php echo e(strtr($errors->first('brand_id'),$tr)); ?></small>
                                        </div>

                                        <?php $style = ($oldType == 'c' || $oldType == 'cb') ? ' style="display: block;"' : ''; ?>
                                        <div class="col-xs-12 col-sm-6 col-md-3 pbb caroptsel" id="type_c" <?php echo $style; ?>>
                                            <?php $cgId = old('cat_id', $carousel->cat_id); ?>
                                            <?php echo e(Form::label('cat_id', ucfirst(__('adminforms.carousels.cat_id').':'))); ?>

                                            <?php echo e(Form::select('cat_id', $categories, $cgId, ['placeholder' => __('adminforms.common.select'), 'class' => 'form-control', 'id' => 'group-select'])); ?>

                                            <small class="error"><?php echo e(strtr($errors->first('cat_id'),$tr)); ?></small>
                                        </div>

                                        <?php $style = ($oldType == 'cg') ? ' style="display: block;"' : ''; ?>
                                        <div class="col-xs-12 col-sm-6 col-md-3 pbb caroptsel" id="type_cg" <?php echo $style; ?>>
                                            <?php $cgId = old('cg_id', $carousel->cg_id); ?>
                                            <?php echo e(Form::label('cg_id', ucfirst(__('adminforms.carousels.cg_id').':'))); ?>

                                            <?php echo e(Form::select('cg_id', $cgroups, $cgId, ['placeholder' => __('adminforms.common.select'), 'class' => 'form-control', 'id' => 'group-select'])); ?>

                                            <small class="error"><?php echo e(strtr($errors->first('cg_id'),$tr)); ?></small>
                                        </div>

                                        <?php $style = ($oldType == 'pos') ? ' style="display: block;"' : ''; ?>
                                        <div class="col-xs-12 col-sm-6 col-md-3 pbb caroptsel" id="type_pos" <?php echo $style; ?>>
                                            <?php $cgId = old('pos_id', $carousel->pos_id); ?>
                                            <?php echo e(Form::label('pos_id', ucfirst(__('adminforms.carousels.pos_id').':'))); ?>

                                            <?php echo e(Form::select('pos_id', $positions, $cgId, ['placeholder' => __('adminforms.common.select'), 'class' => 'form-control', 'id' => 'group-select'])); ?>

                                            <small class="error"><?php echo e(strtr($errors->first('pos_id'),$tr)); ?></small>
                                        </div>

                                        <?php $style = ($oldType == 'p') ? ' style="display: block;"' : ''; ?>
                                        <div class="col-xs-12 caroptsel"  id="products" <?php echo $style; ?>>
                                            <label><?php echo e(ucfirst(__('adminforms.carousels.type_p').':')); ?></label>
                                            <?php $oldValues = session()->getOldInput(); ?>
                                            <?php if(isset($oldValues['prod_id'])): ?>
                                                <?php $__currentLoopData = $oldValues['prod_id']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $i => $v): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                    <input type="text" name="prod_id[<?php echo e($i); ?>]" value="<?php echo e($v); ?>" class="prod_id" />
                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                            <?php elseif(count($products)): ?>
                                                <?php $__currentLoopData = $products; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $p): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                    <input type="text" name="prod_id[<?php echo e($p->prod_id); ?>]" value="<?php echo e($p->prod_name); ?>" class="prod_id" />
                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                            <?php else: ?>

                                                <input class="prod_id" type="text" value=""  name="prod_id[]">
                                            <?php endif; ?>
                                            <small class="error"><?php echo e(strtr($errors->first('prod_id'),$tr)); ?></small>

                                        </div>
                                        
                                    </div>
                                </div>


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

                                <?php $__currentLoopData = config('app.languages'); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $lang): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>

                                    <?php

                                        $t_car_title = '';

                                        $translation = $carousel->translation($lang);



                                        if($translation){
                                            $t_car_title = $translation->car_title;
                                        }

                                    ?>
                                    <div class="col-xs-12"><label class="lang-intro" for=""><?php echo e(ucfirst(__('adminforms.common.'.$lang.'_version').':')); ?></label></div>

                                    <div class="col-xs-12 col-sm-6 col-md-3 pbb">
                                        <?php echo e(Form::label($lang.'_'.'car_title', ucfirst(__('adminforms.carousels.car_title').':'))); ?>

                                        <?php echo e(Form::text($lang.'_'.'car_title', old($lang.'_'.'car_title', $t_car_title), ['class' => 'form-control'])); ?>

                                        <small class="error"><?php echo e(strtr($errors->first($lang.'_'.'car_title'),$tr)); ?></small>
                                    </div>

                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

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

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





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

            <div class="col-xs-12">
                <?php $btntext = ($create) ? __('adminforms.carousels.btn_insert') : __('adminforms.carousels.btn_update')?>
                <?php echo e(Form::submit($btntext, ['class' => 'btn btn-success pull-right'])); ?>

            </div>

            <?php echo Form::close(); ?>


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

    </section>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('css'); ?>
    <!-- tags -->
    <link rel="stylesheet" href="<?php echo e(asset('assets/tags/jquery-ui-1.10.0.custom.css')); ?>">
    <link rel="stylesheet" href="<?php echo e(asset('assets/tags/jquery.tageditp.css')); ?>">
    <!-- /tags -->
<?php $__env->stopPush(); ?>


<?php $__env->startPush('scripts'); ?>
    <script src="<?php echo e(asset('assets/js/equalpbb.js')); ?>"></script>

    <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>


    <!-- tags -->

    <script src="<?php echo e(asset('assets/tags/jquery-ui.js')); ?>"></script>
    
    <script src="<?php echo e(asset('assets/tags/jquery.auto-grow-input.min.js')); ?>"></script>
    <script src="<?php echo e(asset('assets/tags/jquery.tagedit.js')); ?>"></script>
    <script src="<?php echo e(asset('assets/tags/jquery.tageditupdt.js')); ?>"></script>
    <script src="<?php echo e(asset('assets/tags/jquery.tageditwp.js')); ?>"></script>




    <script type="text/javascript" >
        $(function() {

            $("#products").find("input.prod_id").tagedit({
                autocompleteURL: "/panel/ajax-productsidname",
                additionalListClass: "form-control",
                allowEdit: false,
                allowAdd: false,
                autocompleteOptions: { minLength: 2 }
            });
        });

        $(".prod_id").autoGrowInput({ minWidth: 100, maxWidth: 20000, comfortZone: 15 }); // klase tagedit polja ne vrapera


        $(document).ready(function () {
            $('#car-type-select').on('change', function () {
                var val = $.trim($(this).val());


                $('.caroptsel').hide();

                switch(val) {
                    case 'p':
                        $('#products').show();
                        break;
                    case 'cb':
                        $('#type_c,#type_b').show();
                        break;
                    default:
                        $('#type_'+val).show();
                }


            })

        });


    </script>


    <!-- /tags -->

<?php $__env->stopPush(); ?>


<?php echo $__env->make('layouts.admin', \Illuminate\Support\Arr::except(get_defined_vars(), array('__data', '__path')))->render(); ?>