<?php echo $__env->make("messages", \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
<input type="hidden" id="assigned_output" name="assigned_output" value="" />
<?php
$roles = Config::get('params.roles');
$required = "";
//d($roles,1);
//$currency = $currencies[Config::get('params.currency_default')]['symbol'];
?>
<div id="errors"></div>
<div class="row">
    <div class="col-sm-12">
        <div class="form-group">
            <?php echo Form::label('Title'); ?>

            <?php echo Form::text('Title', null , array('class' => 'form-control',$required) ); ?>

        </div>
    </div>
</div>
 <div class="row">
    <div class="col-md-6 col-xs-6 col-lg-6">
        <div class="col-md-12 col-xs-12 col-lg-12">
            <div class="form-group">
                <?php echo Form::label('Page'); ?>

                <select name="pages" id='pages' class="form-control select2" >
                    <?php $__currentLoopData = $pages; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key=>$page): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <option value="<?php echo e($page['ID']); ?>"  ><?php echo e($page['Title']); ?></option>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </select>
            </div>
        </div>
        <div class="dd col-md-12 col-xs-12 col-lg-12">
            <a href="javascript:void(0);" class="btn btn-outline-primary add">Add</a>
        </div>
    </div>
    <div class="col-md-6 col-xs-6 col-lg-6">
        <div class="cf nestable-lists">
            <div class="dd col-md-12 col-xs-12 col-lg-12" id="unassigned_menus">
                 <ol id="parent" class="dd-list dark">

                    <?php $__currentLoopData = $navigations; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $rec): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <li id="<?php echo e($rec['id']); ?>" class="dd-item dd3-item" data-id="<?php echo e($rec['id']); ?>" data-name="<?php echo e($rec['name']); ?>" data-url="<?php echo e($rec['url']); ?>" data-type="<?php echo e($rec['type']); ?>">
                        <div class="dd-handle dd3-handle"></div>
                        <input type="hidden" id="p_id" name="p_id[]" value="<?php echo e($rec['id']); ?>">
                        <input type="hidden" id="p_link" name="p_link[]" value="<?php echo e($rec['url']); ?>">
                        <div class="dd3-content">
                            <div class="accordion accordianpanel" aria-expanded="false">
                                <div class="accordion-group">
                                    <div class="accordion-heading"> 
                                        <a href="#collapse<?php echo e($rec['id']); ?>" data-toggle="collapse" class="accordion-toggle collapsed"><?php echo e($rec['name']); ?><i class="fa fa-plus"></i> </a> 
                                    </div>
                                    <div class="accordion-body collapse" id="collapse<?php echo e($rec['id']); ?>" style="height: 0px;">
                                        <div class="accordion-inner">
                                            <div class="form-group">
                                                <label class="form-label">Title</label>
                                                <div class="controls"><?php echo $rec['name']?></div>
                                            </div>
                                            <div class="accordion-body collapse" id="collapse<?php echo e($rec['id']); ?>" style="height: 0px;">
                                                <div class="accordion-inner"><div class="form-group">
                                                        <label class="form-label">URL</label>
                                                        <div class="controls">
                                                            <?php echo e($rec['url']); ?>

                                                        </div>
                                                    </div>
                                                    <div class="control-button">
                                                        <a href="javascript:void(0);" onclick="remove('<?php echo $rec['id']; ?>')" data-id="<?php echo $rec['id']; ?>" class="remove-nav">Remove</a><!--<a data-id="' + num + '" class="cancel-nav">Close</a>-->
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        
                        <!-- children --->
                        <?php 
                            $children = $rec['children']; 
                        ?>
                        
                        <?php if(isset($children)>0): ?>
                        <ol class="dd-list dark">
                            <?php $__currentLoopData = $children; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $val): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <li  id="<?php echo $val['id']?>" class="dd-item" data-id="<?php echo $val['id']?>" data-id="<?php echo e($val['id']); ?>" data-name="<?php echo e($val['name']); ?>" data-url="<?php echo e($val['url']); ?>" data-type="<?php echo e($val['type']); ?>">
                                <div class="dd-handle dd3-handle"></div>
                                <div class="dd3-content">
                                    <div class="accordion accordianpanel" aria-expanded="false">
                                        <div class="accordion-group">
                                           
                                            <div class="accordion-heading"> 
                                                <a href="#collapse<?php echo e($val['id']); ?>" data-toggle="collapse" class="accordion-toggle collapsed"><?php echo e($val['name']); ?><i class="fa fa-plus"></i> </a> 
                                            </div>
                                            <div class="accordion-body collapse" id="collapse<?php echo e($val['id']); ?>" style="height: 0px;">
                                                <div class="accordion-inner">
                                                    <div class="form-group">
                                                        <label class="form-label">Title</label>
                                                       
                                                          <div class="controls"><?php echo $val['name']?></div>
                                                    </div>
                                                    <div class="accordion-body collapse" id="collapse<?php echo e($val['id']); ?>" style="height: 0px;">
                                                        <div class="accordion-inner"><div class="form-group">
                                                                <label class="form-label">URL</label>
                                                                <div class="controls">
                                                                    <?php echo e($val['url']); ?>    
                                                                </div>
                                                            </div>
                                                            <div class="control-button">
                                                                <a href="javascript:void(0);" onclick="remove('<?php echo $val['id']; ?>')" data-id="<?php echo $val['id']; ?>" class="remove-nav">Remove</a><!--<a data-id="' + num + '" class="cancel-nav">Close</a>-->
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </li>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </ol>
                        <?php endif; ?>

                    </li>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </ol>                                           
            </div>
        </div>
    </div>
</div>
<br clear="all" />
<br clear="all"/>
<h3>Add Custom Link</h3>
<div class="row">
  <div class="col-sm-6">
        <div class="form-group">
            <?php echo Form::label('Title'); ?>

            <?php echo Form::text('CustomTitle', null , array('class' => 'form-control',$required, 'id'=>'title', 'name'=>'title') ); ?>

        </div>
</div>  
</div>
<div class="row">
    <div class="col-sm-6">
        <div class="form-group">
            <?php echo Form::label('URL'); ?>

            <?php echo Form::text('URL', null , array('class' => 'form-control',$required, 'id'=>'urls', 'name'=>'urls') ); ?>

        </div>
    </div>
  
</div>
<div class="row">
    <div class="col-sm-6">
        <div id="error"></div>

    </div>
</div>
<div class="row">
    <div class="col-sm-6">
        <a href="javascript:void(0);" class="btn btn-outline-primary " id="add">Add</a>
    </div>
</div>
<br clear="all" />

<div class="row">
    <div class="col-md-8">
        <button type="submit" class="btn btn-primary mr-1 mb-1 waves-effect waves-light save">Save</button>
        <a href="<?php echo e(url('navigations')); ?>" class="btn btn-outline-warning mr-1 mb-1 waves-effect waves-light">Cancel</a>
    </div>
</div>
<br clear="all" />
<?php 
// echo json_encode($navigations); 
?>
<input type="hidden" name="links" id="nestable-output" value="<?php echo json_encode($navigations); ?>"></input>
<script>
    var pages =<?php echo json_encode($pages); ?>;
    var navigations =<?php echo json_encode($navigations); ?>;
</script>
 <script>

    var count = <?php echo count($navigations); ?>;
    
    $(document).ready(function () {

    $(".add").click(function () {
    var page = $("#pages").val();
    var page = pages[page];
    var pagtype = "Page";
    addPage(count, page['ID'], page['Title'], page['AccessURL'], pagtype);
    });
    $("#add").click (function () {
    var title = $("#title").val();
    var url = $("#urls").val();
    var pageid = 0;
    var pagetype = "Url";
    if (title == "" || url == "") {
    $("#error").html("<p>Title/URL is empty</p>");
    } else {
    $('#error').hide();
    $("#title").val('');
    $("#urls").val('');
    addCustomPage(count, pageid, title, url, pagetype);
    
    
    
    }
    });
    $(".save").click(function () {

    var url = $("#form").attr('action');
    var type = "POST";
    var dataType = "json";
    var data = $("form").serialize();
    //alert(data);
    var callBack = function (response) {

    if (response.error === 1) {
    displayErrors(response, "errors");
    } else
    {
    // window.top.location.href = '<?php echo e(url("admin/navigations/")); ?>';
    }
    };
    ajaxRequest(url, type, dataType, data, callBack, {});
    });
    var navigationsCount = Object.keys(navigations).length;
    
            });
			
			</script>

<script>
    function remove(id) {
        $("#" + id).remove();
        $($('#unassigned_menus')).trigger("change");
    }

    function addPage(num, id, title, url, pagetype) {
    var dd = '<li id="' + num + '" class="dd-item dd3-item" data-id="' + id + '" data-name="' + title + '" data-url="' + url + '" data-type="' + pagetype + '"><div class="dd-handle dd3-handle"></div><input type="hidden" id="p_id" name="p_id[]" value="' + id + '"><input type="hidden" id="p_link" name="p_link[]" value="' + pagetype + '"><div class="dd3-content"><div class="accordion accordianpanel" aria-expanded="false"><div class="accordion-group"><div class="accordion-heading"> <a href="#collapse' + num + '" data-toggle="collapse" class="accordion-toggle collapsed">' + title + '<i class="fa fa-plus"></i> </a> </div><div class="accordion-body collapse" id="collapse' + num + '" style="height: 0px;"><div class="accordion-inner"><div class="form-group"><label class="form-label">Title</label><div class="controls">' + title + '</div></div><div class="original-name"><p>Original : ' + title + ' </p></div><div class="control-button"><a href="javascript:void(0);" onclick="remove(' + num + ')" data-id="' + num + '" class="remove-nav">Remove</a><!--<a data-id="' + num + '" class="cancel-nav">Close</a>--></div></div></div></div></div></div></li>';
    $("#parent").append(dd);
    //updateOutput($('#unassigned_menus').data('output', $('#nestable-output')));
    $($('#unassigned_menus')).trigger("change");
count++;
}

function addCustomPage(num, id, title, url, pagetype) {

    var dd = '<li id="' + num + '" class="dd-item dd3-item" data-id="' + id + '" data-name="' + title + '" data-url="' + url + '" data-type="' + pagetype + '"><div class="dd-handle dd3-handle"></div><input type="hidden" id="p_id" name="p_id[]" value="' + id + '"><input type="hidden" id="p_link" name="p_link[]" value="' + pagetype + '"><div class="dd3-content"><div class="accordion accordianpanel" aria-expanded="false"><div class="accordion-group"><div class="accordion-heading"> <a href="#collapse' + num + '" data-toggle="collapse" class="accordion-toggle collapsed">' + title + '<i class="fa fa-plus"></i> </a> </div><div class="accordion-body collapse" id="collapse' + num + '" style="height: 0px;"><div class="accordion-inner"><div class="form-group"><label class="form-label">Title</label><div class="controls">' + title + '</div></div><div class="accordion-body collapse" id="collapse' + num + '" style="height: 0px;"><div class="accordion-inner"><div class="form-group"><label class="form-label">URL</label><div class="controls">' + url + '</div></div><div class="control-button"><a href="javascript:void(0);" onclick="remove(' + num + ')" data-id="' + num + '" class="remove-nav">Remove</a><!--<a data-id="' + num + '" class="cancel-nav">Close</a>--></div></div></div></div></div></div></li>';
count++;
$("#parent").append(dd);
//updateOutput($('#unassigned_menus').data('output', $('#nestable-output')));
$($('#unassigned_menus')).trigger("change");

}
</script>

<script>
    $( document ).ready(function() {

        if($( "#template" ).val()=="has_child"){
            
            $("#hasNochild").hide();
            $("#hasChild").show();
        }else{
             
            $("#hasNochild").show();
            $("#hasChild").hide();
        }

    $('#template').on('change', function() {
        var value = $(this).val();
        if($( "#template" ).val()=="has_child"){
            
            $("#hasNochild").hide();
            $("#hasChild").show();
        }else{
             
            $("#hasNochild").show();
            $("#hasChild").hide();
        }
    });
    });
</script>
<?php /**PATH /home/seolocaj/public_html/homefloltd/resources/views/admin/navigations/form.blade.php ENDPATH**/ ?>