<?php
    if($create){
        $title = __('adminforms.products.title_insert');
        $formpar = array('route' => 'admin.product.store', 'files' => true, 'id' => 'prodform');
    } else {
        $title = __('adminforms.products.title_update');
        $formpar = array('route' => array('admin.product.update', $product->prod_id), 'method' => 'PUT', 'files' => true, 'id' => 'prodform');
    }

    $tr = [
        'prod id'       => __('adminforms.products.prod_id'),
        'brand id'      => __('adminforms.products.brand_id'),
        'brand name'    => __('adminforms.products.brand_name'),
        'cat id'        => __('adminforms.products.cat_id'),
        'cat name'      => __('adminforms.products.cat_name'),
        'prod name'     => __('adminforms.products.prod_name'),
        'prod sku'      => __('adminforms.products.prod_sku'),
        'prod price'    => __('adminforms.products.prod_price'),
        'prod weight'   => __('adminforms.products.prod_weight'),
        'prod timg'     => __('adminforms.products.prod_timg'),
        'prod simg'     => __('adminforms.products.prod_simg'),
        'prod mimg'     => __('adminforms.products.prod_mimg'),
        'prod bimg'     => __('adminforms.products.prod_bimg'),
        'prod sdesc'    => __('adminforms.products.prod_sdesc'),
        'prod atdes'    => __('adminforms.products.prod_atdes'),
        'prod status'   => __('adminforms.products.prod_status'),
        'pos id'        => __('adminforms.products.pos_id'),
        'pos name'      => __('adminforms.products.pos_name'),
        'prod admin'    => __('adminforms.products.prod_admin'),
        'prod desc'     => __('adminforms.products.prod_desc'),
        'prod mdesc'    => __('adminforms.products.prod_mdesc'),
        'pd name'       => __('adminforms.products.pd_name'),
        'pd path'       => __('adminforms.products.pd_path'),
        'pd type'       => __('adminforms.products.pd_type'),
        'prod title'    => __('adminforms.products.prod_title'),
        'prod metadesc' => __('adminforms.products.prod_metadesc'),
        'prod keyw'     => __('adminforms.products.prod_keyw'),
        'prod video'    => __('adminforms.products.prod_video'),
        'images'        => __('adminforms.products.images'),
        'slug'             => __('adminforms.common.slug'),
    ];
?>

<?php $__env->startSection('title'); ?><?php echo e($title); ?><?php $__env->stopSection(); ?>
<?php $__env->startSection('header'); ?><?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; ?>
            </div>

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


            <div class="col-xs-12">
                <?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(); ?>
                        <?php
                        $error = strtr($error, $tr);
                        $error = preg_replace('/(images)\.(\d+)/i', $tr['images'], $error);
                        $error = preg_replace('/\.(\d+)/i', '', $error);
                        ?>
                        <div style="color: #9e0505;"><?php echo e($error); ?></div>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    <br>
                <?php endif; ?>

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

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

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

                                <br clear="all">
                                <hr>
                            </div>

                            <div class="col-xs-12 col-sm-6 col-md-6 pbb">
                                <?php echo e(Form::label('prod_name', ucfirst(__('adminforms.products.prod_name').':'))); ?>

                                <?php echo e(Form::text('prod_name', old('prod_name', $product->prod_name ), ['class' => 'form-control', 'id' => 'prodname'])); ?>

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


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

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

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

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

                                <?php echo e(Form::select('cat_id', $catergories, $pgId, ['placeholder' => __('adminforms.products.select_category'), 'class' => 'form-control', 'id' => 'catid'])); ?>

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

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

                                <?php
                                    $t_slug             = '';

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

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

                                ?>

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

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

                                    <small class="error"><?php echo e(strtr($errors->first($lang.'_'.'slug'),$tr)); ?></small>
                                </div>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

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

                                <?php echo e(Form::text('prod_sku', old('prod_sku', $product->prod_sku ), ['class' => 'form-control'])); ?>

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

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

                                <?php echo e(Form::text('prod_price', old('prod_price', $product->prod_price ), ['class' => 'form-control', 'id' => 'prodprice'])); ?>

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

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

                                <?php echo e(Form::text('prod_weight', old('prod_weight', $product->prod_weight ), ['class' => 'form-control', 'id' => 'prodweight'])); ?>

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

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

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

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

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

                            






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



                <div class="box">

                    <div class="panel panel-default">

                        <div class="panel-heading">
                            <h3 class="panel-title"><i class="fa fa-google"></i> <?php echo e(__('adminforms.products.meta_block')); ?> - <small><?php echo e(__('adminforms.products.meta_block_info')); ?></small></h3>
                        </div>

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

                                <div class="col-xs-12 col-sm-6 col-md-4">
                                    <?php echo e(Form::label('prod_title', ucfirst(__('adminforms.products.prod_title').':'))); ?>

                                    <?php echo e(Form::textarea('prod_title', old('prod_title', isset($product->metatags->prod_title) ? $product->metatags->prod_title : ''), ['class' => 'form-control', 'rows' => 3])); ?>

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

                                <div class="col-xs-12 col-sm-6 col-md-4">
                                    <?php echo e(Form::label('prod_metadesc', ucfirst(__('adminforms.products.prod_metadesc').':'))); ?>

                                    <?php echo e(Form::textarea('prod_metadesc', old('prod_metadesc', isset($product->metatags->prod_metadesc) ? $product->metatags->prod_metadesc : ''), ['class' => 'form-control', 'rows' => 3])); ?>

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

                                <div class="col-xs-12 col-sm-6 col-md-4">
                                    <?php echo e(Form::label('prod_keyw', ucfirst(__('adminforms.products.prod_keyw').':'))); ?>

                                    <?php echo e(Form::textarea('prod_keyw', old('prod_keyw', isset($product->metatags->prod_keyw) ? $product->metatags->prod_keyw : ''), ['class' => 'form-control', 'rows' => 3])); ?>

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




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


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


                <div class="box">

                    <div class="panel panel-default">

                        <div class="panel-heading">
                            <h3 class="panel-title"><i class="fa fa-picture-o"></i> <?php echo e(__('adminforms.products.images_block')); ?></h3>
                        </div>

                        <div class="panel-body">

                            <?php echo $__env->make('admin.products.prodimages', ['prodimages' => $prodimages, 'prodatrdata' => $prodatrdata ], \Illuminate\Support\Arr::except(get_defined_vars(), array('__data', '__path')))->render(); ?>

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


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


                <div class="box">

                    <div class="panel panel-default">

                        <div class="panel-heading">
                            <h3 class="panel-title"><i class="fa fa-file-pdf"></i> <?php echo e(__('adminforms.products.documents_block')); ?></h3>
                        </div>

                        <div class="panel-body">

                            <?php echo $__env->make('admin.products.proddocuments', ['documents' => $documents ], \Illuminate\Support\Arr::except(get_defined_vars(), array('__data', '__path')))->render(); ?>

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


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




                <div class="row">
                    <div class="col-md-9">

                        <div class="box">

                            <div class="panel panel-default">

                                <div class="panel-heading">
                                    <h3 class="panel-title"><i class="fa fa-list-alt"></i> <?php echo e(__('adminforms.products.descriptions_block')); ?></h3>
                                </div>

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

                                        <div class="col-xs-12">
                                            <?php echo e(Form::label('prod_mdesc', ucfirst(__('adminforms.products.prod_mdesc').':'))); ?>

                                            <br><small class="error"><?php echo e(strtr($errors->first('prod_mdesc'),$tr)); ?></small>
                                            <?php echo e(Form::textarea('prod_mdesc', old('prod_mdesc', isset($product->description->prod_mdesc) ? $product->description->prod_mdesc : ''), ['class' => 'form-control editor', 'id' => 'prodmdesc'])); ?>

                                        </div>

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

                                        <div class="col-xs-12">
                                            <?php echo e(Form::label('prod_desc', ucfirst(__('adminforms.products.prod_desc').':'))); ?>

                                            <br><small class="error"><?php echo e(strtr($errors->first('prod_desc'),$tr)); ?></small>
                                            <?php echo e(Form::textarea('prod_desc', old('prod_desc', isset($product->description->prod_desc) ? $product->description->prod_desc : ''), ['class' => 'form-control editor', 'id' => 'prodspec'])); ?>

                                        </div>



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


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




                    </div><!-- / left column -->
                    <div class="col-md-3">

                        <div class="box">

                            <div class="panel panel-default">

                                <div class="panel-heading">
                                    <h3 class="panel-title"><i class="fa fa-youtube-play"></i> <?php echo e(__('adminforms.products.video_block')); ?></h3>
                                </div>

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

                                        <div class="col-xs-12">
                                            <?php echo e(Form::label('prod_video', ucfirst(__('adminforms.products.prod_video').':'))); ?>

                                            <?php echo e(Form::textarea('prod_video', old('prod_video', isset($product->video->prod_video) ? $product->video->prod_video : ''), ['class' => 'form-control', 'rows' => 3])); ?>

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

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


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


                        <div class="box">

                            <div class="panel panel-default">

                                <div class="panel-heading">
                                    <h3 class="panel-title"><i class="fa fa-list-ul"></i> <?php echo e(__('adminforms.products.attributes_block')); ?></h3>
                                </div>

                                <div class="panel-body">
                                    <div class="row">
                                        <div id="filters" style="padding: 10px;">
                                            <?php echo $__env->make('admin.products.attributesselects', ['catatrids' => $catatrids, 'prodatrdata' => $prodatrdata ], \Illuminate\Support\Arr::except(get_defined_vars(), array('__data', '__path')))->render(); ?>
                                        </div>

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


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


                    </div><!-- / right column -->
                </div>




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


            <br clear="all">
            <hr>
            <div class="col-xs-12">
                <?php $btntext = ($create) ? __('adminforms.products.btn_insert') : __('adminforms.products.btn_update')?>
                <?php echo e(Form::button($btntext, ['class' => 'btn btn-success pull-right', 'id' => 'prodsbmtbutt2'])); ?>

            </div>



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


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

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

<?php $__env->startPush('css'); ?>

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


<?php $__env->startPush('scripts'); ?>
    <script src="<?php echo e(asset('assets/js/equalpbb.js')); ?>"></script>
    <script src="<?php echo e(asset('ckeditor/ckeditor.js')); ?>"></script>
    <script>
        // omogucavanje na mobilnim uredjajima
        //CKEDITOR.env.isCompatible = true;
    </script>
    <script src="<?php echo e(asset('ckeditor/ckeditor_autogrow.js')); ?>"></script>
    <script src="<?php echo e(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');
            if($(".editor").length) {
                $("#prodmdesc").ckeditor({toolbar: 'Basic', minHeight: 100, width: "100%"});
                $("#prodspec").ckeditor({toolbar: 'Basic', minHeight: 350, width: "100%"});
            }
        });
    </script>

    <script>

        function string_to_slug(str) {
            str = str.replace(/^\s+|\s+$/g, '');

            // Make the string lowercase
            str = str.toLowerCase();

            // Remove accents, swap ñ for n, etc
            var from = "ÁÄÂÀÃÅČÇĆĎÉĚËÈÊẼĔȆÍÌÎÏŇÑÓÖÒÔÕØŘŔŠŤÚŮÜÙÛÝŸŽáäâàãåčçćďéěëèêẽĕȇíìîïňñóöòôõøðřŕšťúůüùûýÿžþÞĐđßÆa·/_,:;čćžšđČĆŽŠĐ";
            var to   = "AAAAAACCCDEEEEEEEEIIIINNOOOOOORRSTUUUUUYYZaaaaaacccdeeeeeeeeiiiinnooooooorrstuuuuuyyzbBDdBAa------cczsdCCZSD";
            for (var i=0, l=from.length ; i<l ; i++) {
                str = str.replace(new RegExp(from.charAt(i), 'g'), to.charAt(i));
            }

            // Remove invalid chars
            str = str.replace(/[^a-z0-9 -]/g, '')
            // Collapse whitespace and replace by -
                .replace(/\s+/g, '-')
                // Collapse dashes
                .replace(/-+/g, '-');

            return str;
        }

        $(document).ready(function(){


            <?php
            $functions = '';
            ?>

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

            <?php
                $functions .= 'get'.$lang.'Route();'."\n";
            ?>

            function get<?php echo e($lang); ?>Route(){
                var cval = $.trim($('#prodname').val());
                var bname = $.trim($('#brandid').find('option:selected').text());
                var string = bname+' '+cval;
                var cslug = string.replace(/\s/g, '-').replace(/\//g, '-').replace(/-{2,}/g, '-').toLowerCase();
                var cslug = string_to_slug(cslug);
                $('#<?php echo e($lang); ?>slug').val(cslug);
            }
            
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

            

            $('#prodname').keyup(function () {
                <?php echo e($functions); ?>

            });
            $('#prodname').blur(function () {
                <?php echo e($functions); ?>

            });
            $('#brandid').change(function () {
                <?php echo e($functions); ?>

            });
        });
    </script>

    <script src="<?php echo e(asset('assets/js/bootstrap-filestyle.min.js')); ?>"></script>
    <?php echo $__env->make('admin.products.onpagescripts', \Illuminate\Support\Arr::except(get_defined_vars(), array('__data', '__path')))->render(); ?>
<?php $__env->stopPush(); ?>
<?php echo $__env->make('layouts.admin', \Illuminate\Support\Arr::except(get_defined_vars(), array('__data', '__path')))->render(); ?>