<?php $__env->startSection('title', 'Tickets'); ?>
<?php $__env->startSection('content'); ?>
    <?php if($message = Session::get('success')): ?>
        <div class="alert alert-success">
            <p><?php echo e($message); ?></p>
        </div>
    <?php endif; ?>

    

<div class="row">
    <div class="span12">
    <div class="widget">
        <div class="widget-header"> <h2 class="mlft"> #<?php echo e($tickets[0]->id); ?>-<?php echo e($tickets[0]->shortname); ?>  :  <?php echo e($tickets[0]->subject); ?>.
        <a href="<?php echo str_replace('support/', '', $tickets[0]->base_url); ?>shop_index.php?domain=<?php echo e($shopdetails[0]->shop_domain); ?>&secret=<?php echo e($shopdetails[0]->shop_secret); ?>" target="_blank" class="btn btn-primary pull-right" style="margin: 7px;">Login to Shop</a></h2>
        
        </div>
    <div class="widget-content">
            <div class="label-1 item-container">
                <div class="span5">
                        <table>
                        <tr><td><strong>App</strong>:</td><td><?php echo e($tickets[0]->cname); ?></td></tr>
                        <tr><td><strong>Status</strong>:</td><td> <label class="name" style="display:inline-block;">
                                    <span style="color: <?php echo e($tickets[0]->scolor); ?>"><?php echo e($tickets[0]->sname); ?></span> &nbsp;
                                </label>
                                <?php if(auth()->guard()->check()): ?>
                                    <select name="sp_main_status" id='sp_main_status' class='com_text' style="display: none;">
                                        <?php $__currentLoopData = $statuses; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $status): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <option value="<?php echo e($status->name); ?>" data-id="<?php echo e($status->id); ?>"> <?php echo e($status->name); ?></option>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </select>
                                     <select id="time_main_durations" name="time_main_durations" style="display: none;">
                                         <option value="0" data-id="0">Select Duration</option>
                                            <?php $__currentLoopData = $time_durations; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $durations): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                <option value="<?php echo e($durations->id); ?>" data-id="<?php echo e($durations->id); ?>"> <?php echo e($durations->name); ?></option>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </select>
                                    <a href="javascript:void(0)" class='edit' style="color:#21a9ec;font-size: 17px;">
                                        <span class="icon-pencil"></span>
                                    </a>
                                    <a href="javascript:void(0)" class='save' style="display: none;font-size: 20px;">
                                        <span class="icon-ok"></span>
                                    </a>
                                    <a href="javascript:void(0)" class='cancel' style="display: none;color:#bd2b1f;font-size: 20px;">
                                        <span class="icon-remove"></span>
                                    </a>
                                <?php endif; ?></td></tr>
                        <tr><td><strong>Priority</strong>:</td><td><label class="pname" style="display:inline-block;">
                                    <span style="color: <?php echo e($tickets[0]->pcolor); ?>"><?php echo e($tickets[0]->pname); ?></span> &nbsp;
                                </label>
                                <?php if(auth()->guard()->check()): ?>
                                    <select id='text_2' class='pcom_text' style="display: none;">
                                        <?php $__currentLoopData = $priority; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $prty): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <option value="<?php echo e($prty->name); ?>" data-id="<?php echo e($prty->id); ?>"> <?php echo e($prty->name); ?></option>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </select>
                                    <a href="javascript:void(0)" class='pedit' style="color:#21a9ec;font-size: 17px;">
                                        <span class="icon-pencil"></span>
                                    </a>
                                    <a href="javascript:void(0)" class='psave' style="display: none;font-size: 20px;">
                                        <span class="icon-ok"></span>
                                    </a>
                                    <a href="javascript:void(0)" class='pcancel' style="display: none;color:#bd2b1f;font-size: 20px;">
                                        <span class="icon-remove"></span>
                                    </a>
                                <?php endif; ?></td></tr>
                        <tr><td><strong>Category</strong>:</td><td><?php echo e($tickets[0]->subname); ?></td></tr>
                        <tr><td><strong>Email</strong>:</td><td><?php echo e($tickets[0]->email); ?></td></tr>
                        <tr><td><strong>Created</strong>:</td><td><time title="<?php echo e($tickets[0]->created_at); ?>"><?php echo e(Carbon\Carbon::parse($tickets[0]->created_at)->diffForHumans()); ?></time></td></tr>
                        <tr><td><strong>Last Update</strong>:</td><td><time id="updatedt_at" title="<?php echo e($tickets[0]->updated_at); ?>"><?php echo e(Carbon\Carbon::parse($tickets[0]->updated_at)->diffForHumans()); ?></time></td></tr>
                    </table>
                </div>
                <div class="span6">
                    <table>
                    <tr><td> <strong>Store ID</strong>:</td><td><?php echo e($shopdetails[0]->shop_id); ?></td></tr>
                    <tr><td> <strong>Store Name</strong>:</td><td><?php echo e($shopdetails[0]->shop_name); ?></td></tr>
                    <tr><td> <strong>Store owner's Name</strong>:</td><td><?php echo e($shopdetails[0]->shop_owner_name); ?></td></tr>
                    <tr><td> <strong>Store owner's email</strong>:</td><td><?php echo e($shopdetails[0]->shop_owner_email); ?></td></tr>
                    <tr><td> <strong>Custom Domain</strong>:</td><td><?php echo e($shopdetails[0]->shop_domain); ?></td></tr>
                    <tr><td> <strong>Shopify Domain</strong>:</td><td><?php echo e($shopdetails[0]->shop_shopify_domain); ?></td></tr>
                    </table>
                </div>
            </div>

            <div class="span11"><br/>

                <fieldset>
                    <legend><strong>Description</strong></legend>
                <?php echo $tickets[0]->content; ?>

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

<div class="row">
    <div class="span12">

        <div class="widget">
            <div class="widget-header"> <i class="icon-file"></i>
                <h3> Comments</h3>
            </div>
            <!-- /widget-header -->
            <div class="widget-content">
                 <?php if($comments->isEmpty() ): ?>
                    <h3 style="text-align: center;" id="blankcomment">Be the first to comment.</h3>
                <?php endif; ?>
                <ul class="messages_layout">
                        <?php $__currentLoopData = $tickets_notifications; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $tnotify): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <?php if($tnotify->last_comments_id == 0): ?>
                                <?php if($tnotify->status_id != 1): ?>
                                <li class="left">
                                    <div class="message_wrap1 alert alert-info">
                                    <span class="status-notification">Status Set To <b><?php echo e($tnotify->status_name); ?></b>
                                    <?php if($tnotify->time_durations_id != 0): ?>
                                    On <b><?php echo e($tnotify->duration_name); ?></b>
                                    <?php endif; ?>
                                    , Updated By <b><?php echo e($tnotify->uname); ?></b></span></div></li>
                                <?php endif; ?>
                            <?php endif; ?>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    
                    <?php $__currentLoopData = $comments; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $cmnt): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <li class="from_user <?php echo e(($cmnt->commentable_type == 0) ? 'right' : 'left'); ?>"> <a href="#" class="avatar" title="<?php echo e($cmnt->uname); ?>"><figure><img src="<?php echo e(Gravatar::src($cmnt->uemail, 40)); ?>"><figcaption><?php echo e($cmnt->uname); ?></figcaption></figure></a>
                        <div class="message_wrap <?php echo e(($cmnt->support_team_display == 1) ? 'admincomments' : ''); ?>">
                            <div class="text"><?php echo $cmnt->content; ?>

                               <div class="row">
                            <?php $__currentLoopData = $tickets_attachements; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $attach): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                               
                                <?php if(($cmnt->id) == ($attach->comment_id)): ?>
                                            <div class="span2">
                                              <div class="thumbnail-attach">
                                            
                                                <?php if(in_array($attach->file_ext, ['png','jpeg','jpg'])): ?>
                                                    <img src="<?php echo e(url('img/atteach')); ?>/<?php echo e($attach->file_name); ?>" class="attach-img-tag" />
                                                <?php else: ?>
                                                    <img src="<?php echo e(url('img')); ?>/default-attachment.png" class="attach-img-tag" />
                                                <?php endif; ?>
                                                  <div class="caption">
                                                    <p><?php echo e($attach->file_name); ?></p>
                                                  </div>
                                            
                                              </div>
                                            </div>
                
                                             <?php endif; ?>
                
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                        </div>
                            </div>

                            <span class="arrow"></span>
                            <div class="info">
                                <span class="time"><i class=" icon-time"></i> <time title="<?php echo e($cmnt->updated_at); ?>"><?php echo e(Carbon\Carbon::parse($cmnt->updated_at)->diffForHumans()); ?></time> </span>
                            </div>

                        </div>
                    </li>
                        <?php $__currentLoopData = $tickets_notifications; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $tnotify): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <?php if(($cmnt->id) == ($tnotify->last_comments_id)): ?>
                                <?php if($tnotify->status_id != 1): ?>
                                <li class="left">
                                    <div class="message_wrap1 alert alert-info">
                                    <span class="status-notification">Status Set To <b><?php echo e($tnotify->status_name); ?></b>
                                    <?php if($tnotify->time_durations_id != 0): ?>
                                    On <b><?php echo e($tnotify->duration_name); ?></b>
                                    <?php endif; ?>
                                    , Updated By <b><?php echo e($tnotify->uname); ?></b></span>
                                </div>
                                </li>
                                <?php endif; ?>
                            <?php endif; ?>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </ul>
            </div>
            <!-- /widget-content -->
        </div>
        <!-- /widget -->
    </div>
</div>



    <div class="panel-body">
        <div class="msgsuccess"></div>
        <div class="form-horizontal">
            <input name="ticket_id" id="ticket_id" type="hidden" value="<?php echo e($tickets[0]->id); ?>">
            <input name="user_ids" id="user_ids" type="hidden" value="<?php echo e($tickets[0]->user_id); ?>">
            <fieldset>
                <legend>Reply</legend>
                <div class="form-group">
                    <div class="col-lg-12">
                        <textarea class="ckeditor" name="content" cols="30" id="content" placeholder="Describe your issue here in details"></textarea>
                        <span class="text-danger contenterror"></span>
                    </div>
                </div>
                <br/>
                <div class="form-group">
                    <div class="col-lg-12">
                          <form action="<?php echo e(url('/updatemultipleimages')); ?>" enctype="multipart/form-data" class="dropzone" id="image-upload"></form>
                    </div>
                </div>
                                                        <table class="status-container pull-right"><tr><td><strong>Status</strong>:</td><td> <label class="status_name" style="display:inline-block;">
                                    <span style="color: <?php echo e($tickets[0]->scolor); ?>"><?php echo e($tickets[0]->sname); ?></span> &nbsp;
                                </label>
                               
                                    <select name="sp_status" id='sp_status' class='status_com_text' style="display: none;">
                                        <?php $__currentLoopData = $statuses; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $status): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <option value="<?php echo e($status->name); ?>" data-id="<?php echo e($status->id); ?>"> <?php echo e($status->name); ?></option>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </select>
                                    <select id="time_durations" name="time_durations" style="display: none;">
                                        <option value="0" data-id="0">Select Duration</option>
                                            <?php $__currentLoopData = $time_durations; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $durations): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                <option value="<?php echo e($durations->id); ?>" data-id="<?php echo e($durations->id); ?>"> <?php echo e($durations->name); ?></option>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </select>           
                                    <a href="javascript:void(0)" class='status_edit' style="color:#21a9ec;font-size: 17px;">
                                        <span class="icon-pencil"></span>
                                    </a>
                                    <a href="javascript:void(0)" class='status_save' style="display: none;font-size: 20px;">
                                        <span class="icon-ok"></span>
                                    </a>
                                    <a href="javascript:void(0)" class='status_cancel' style="display: none;color:#bd2b1f;font-size: 20px;">
                                        <span class="icon-remove"></span>
                                    </a>
                             </td></tr></table>
                             
                <div class="form-group">
                    <div class="col-lg-12">
                        <span class="text-danger imagevalueerror"></span>
                    </div>
                </div>
                <div class="form-group">
                 <div class="col-lg-12">
                    <b>Note:</b> You can upload maximum 5 files. File size should not exceed 5MB.
                 </div>
                </div>
                <?php if(auth()->guard()->guest()): ?>
                    <input type="hidden" id="commentable_type" name="commentable_type" class="form-control" value="0">
                    <input type="hidden" id="support_team_display" name="support_team_display" value="0" id="support_team_display">
                <?php else: ?>
                    <div class="form-group">
                        <div class="col-lg-12">
                            <label><input type="checkbox" name="support_team_display" value="1" id="support_team_display"> Visible only to Support Team</label>
                        </div>
                    </div>
                    <input type="hidden" name="commentable_type" id="commentable_type" class="form-control" value="1">
                <?php endif; ?>
                <input class="btn btn-primary btn-save" type="submit" value="Submit"><span id="loading" style="display:none;"><img src="<?php echo e(asset('img')); ?>/loading.gif" height="50" width="100" /></span>
            </fieldset>
        </div>
    </div>

    <link rel="stylesheet" type="text/css" href="<?php echo e(asset('css/custom.css')); ?>" >


    <script src="//ajax.microsoft.com/ajax/jquery.validate/1.7/jquery.validate.min.js"></script>
    <script src="//sdk.ckeditor.com/vendor/ckeditor/4.11.1/ckeditor.js"></script>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/dropzone/4.0.1/min/dropzone.min.css" rel="stylesheet">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/dropzone/4.2.0/min/dropzone.min.js"></script>
    <script src="<?php echo e(asset('js/simple-lightbox.min.js')); ?>"></script>

<script type="text/javascript">
$("#time_durations").hide();
$("#sp_status").on( 'change', function (event) {
    event.preventDefault();
    var appFilter = $("#sp_status option:selected").attr('data-id'); 
    //alert(appFilter);
        if(appFilter == 4 || appFilter == 5)
        {
            $("#time_durations").show();
        }
        else
        {
            $("#time_durations").hide();
        }                   
} );

$("#time_main_durations").hide();
$("#sp_main_status").on( 'change', function (event) {
    event.preventDefault();
    var appFilter = $("#sp_main_status option:selected").attr('data-id');  
    //alert(appFilter);
        if(appFilter == 4 || appFilter == 5)
        {
            $("#time_main_durations").show();
        }
        else
        {
            $("#time_main_durations").hide();
        }                   
} );

Dropzone.options.imageUpload = {
    maxFilesize:5,
    maxFiles: 5,
};
Dropzone.autoDiscover = false;

var myDropzone = $(".dropzone").dropzone({
 addRemoveLinks: true,
    params: {
        _token: '<?php echo e(csrf_token()); ?>',
        ticket_id : $('#ticket_id').val()
    },
    success: function(file, response){
        file.attachment_id = response;
    },
 removedfile: function(file) {
  var name = file.name; 
   
  $.ajax({
   type: 'POST',
   url: '<?php echo e(url('/updatemultipleimages')); ?>',
   data: {name: name,request: 2,_token: '<?php echo e(csrf_token()); ?>',atach_id:file.attachment_id},
   sucess: function(data){
    console.log('success: ' + data);
   }
  });
  var _ref;
  return (_ref = file.previewElement) != null ? _ref.parentNode.removeChild(file.previewElement) : void 0;
 }
});
    
            //ajax form submit with commented

        function time_ago(time) {

            switch (typeof time) {
                case 'number':
                    break;
                case 'string':
                    time = +new Date(time);
                    break;
                case 'object':
                    if (time.constructor === Date) time = time.getTime();
                    break;
                default:
                    time = +new Date();
            }
            var time_formats = [
                [60, 'seconds', 1], // 60
                [120, '1 minute ago', '1 minute from now'], // 60*2
                [3600, 'minutes', 60], // 60*60, 60
                [7200, '1 hour ago', '1 hour from now'], // 60*60*2
                [86400, 'hours', 3600], // 60*60*24, 60*60
                [172800, 'Yesterday', 'Tomorrow'], // 60*60*24*2
                [604800, 'days', 86400], // 60*60*24*7, 60*60*24
                [1209600, 'Last week', 'Next week'], // 60*60*24*7*4*2
                [2419200, 'weeks', 604800], // 60*60*24*7*4, 60*60*24*7
                [4838400, 'Last month', 'Next month'], // 60*60*24*7*4*2
                [29030400, 'months', 2419200], // 60*60*24*7*4*12, 60*60*24*7*4
                [58060800, 'Last year', 'Next year'], // 60*60*24*7*4*12*2
                [2903040000, 'years', 29030400], // 60*60*24*7*4*12*100, 60*60*24*7*4*12
                [5806080000, 'Last century', 'Next century'], // 60*60*24*7*4*12*100*2
                [58060800000, 'centuries', 2903040000] // 60*60*24*7*4*12*100*20, 60*60*24*7*4*12*100
            ];
            var seconds = (+new Date() - time) / 1000,
                token = 'ago',
                list_choice = 1;

            if (seconds == 0) {
                return 'Just now'
            }
            if (seconds < 0) {
                seconds = Math.abs(seconds);
                token = 'from now';
                list_choice = 2;
            }
            var i = 0,
                format;
            while (format = time_formats[i++])
                if (seconds < format[0]) {
                    if (typeof format[2] == 'string')
                        return format[list_choice];
                    else
                        return Math.floor(seconds / format[2]) + ' ' + format[1] + ' ' + token;
                }
            return time;
        }

        $(document).ready(function()
        {
            $(".attach-img-tag").simpleLightBox();
        
            $( ".btn-save" ).click(function() {
                for (instance in CKEDITOR.instances) {
                    CKEDITOR.instances[instance].updateElement();
                }

                if($('#content').val() == '')
                {
                    $(".contenterror").text("Enter Describe your issue here in details");
                }
                else{
                    
                    

            $(".btn-save").hide();
            $("#loading").show();
            

                    var form_data = new FormData();                  // Creating object of FormData class
                    
                   <?php if(Auth::user()): ?>
                        form_data.append("user_id", <?php echo e(Auth::user()->id); ?>);
                   <?php else: ?>
                        form_data.append("user_id", $('#user_ids').val());
                   <?php endif; ?>
                   
                    form_data.append("content", $('#content').val());
                    form_data.append("commentable_type", $('#commentable_type').val());
                    form_data.append("ticket_id", $('#ticket_id').val());
                    if($('#support_team_display').prop("checked") == true){
            
                        form_data.append("support_team_display", 1);
                        var superadmin = "admincomments";
                    }
                    else if($('#support_team_display').prop("checked") == false){
                        form_data.append("support_team_display", 0);
                        var superadmin = "123";
                    }
                    
                    form_data.append("_token", '<?php echo e(csrf_token()); ?>');


                    $.ajax({
                        type:"POST",
                        dataType:"json",
                        url:"<?php echo e(url('ticketcomments')); ?>",
                        cache: false,
                        contentType: false,
                        processData: false,
                        data: form_data,
                        success: function (data) {
                            
                            $('.dropzone')[0].dropzone.files.forEach(function(file) { 
                              file.previewElement.remove(); 
                            });

                            $('.dropzone').removeClass('dz-started');
                            
                            $('#content').val('');
                            $('#imagevalue').val('');
                            $(".contenterror").text("");
                            $(".imagevalueerror").text("");
                            $("#loading").hide();
                            $(".btn-save").show();
                            $("#blankcomment").hide();
                            CKEDITOR.instances.content.setData( '' );
                            $('#support_team_display').attr('checked',false);
                            if(data.comment[0].commentable_type == 0){
                                var side = "right";
                                var useradminicon="user";
                            }
                            else {
                                var side = "left";
                                var useradminicon="admin";
                            }
                            var updated_at= data.comment[0].updated_at;
                            var updated_final_at= time_ago(new Date(Date.now()));
                            var username = data.comment[0].uname;
                            var gravatar_img = "<?php echo e(Gravatar::src('admin@simprosys.net', 40)); ?>";
                            

                            var total_attach_files = data.tickets_attachements.length;
                            var total_attachements_str = '';
                            var ar_ext = ['jpg', 'gif', 'png', 'jpeg']; 
                            total_attachements_str += "<div class='row'>";
                             for(var i=0;i<total_attach_files;i++)
                             {
                                if (ar_ext.indexOf(data.tickets_attachements[i].file_ext) === -1) {
                                    total_attachements_str +="<div class='span2'><div class='thumbnail-attach'><img src='<?php echo e(url('img')); ?>/default-attachment.png' class='attach-img-tag'><div class='caption'><p>"+data.tickets_attachements[i].file_name+"</p></div></div></div>";

                                }
                                else {
                                 total_attachements_str +="<div class='span2'><div class='thumbnail-attach'><img src='<?php echo e(url('img/atteach')); ?>/"+data.tickets_attachements[i].file_name+"' class='attach-img-tag'><div class='caption'><p>"+data.tickets_attachements[i].file_name+"</p></div></div></div>";
                                }
                             }
                            total_attachements_str += "</div>";
                            
                            
                            $('time[id="updatedt_at"]').text(updated_final_at);
                            $(".messages_layout").append('<li class="from_user ' + side + '"> <a href="#" class="avatar" title="' + username + '"><figure><img src="'+ gravatar_img +'" /><figcaption>' + username + '</figcaption></figure></a> <div class="message_wrap"><div class="text">'+data.comment[0].content + total_attachements_str +'</div><span class="arrow"></span> <div class="info"><span class="time"><i class="icon-time"></i><time title="'+ updated_at +'"> '+ updated_final_at +' </time></span> </div> </div></li>');
                           // $(".messages_layout").append('<li class="from_user ' + side + '"> <a href="#" class="avatar" title="' + username + '"><img src="<?php echo e(asset('img')); ?>/'+ useradminicon +'.png" height="25" width="25" /></a> <div class="message_wrap"><div class="text">'+data.comment[0].content+'</div><span class="arrow"></span> <div class="info"> <span class="time"><i class="icon-time"></i><time title="'+ updated_at +'"> '+ updated_final_at +' </time></span> </div> </div></li>');
                            $(".message_wrap").last().addClass(superadmin);
                            $(".msgsuccess").html('<div class="alert alert-success msgsuccessdata">Comment has been added successfully</div>');
                            setTimeout(function() {
                                $(".msgsuccessdata").hide();
                            }, 3000);
                        },
                        error: function (data) {
                            console.log('Error:', data);
                            var obj = {
                            };
                        }
                    });
                }
            });
        });
    
        $(document).ready(function()
        {

            $('.com_text').click(function()
            {
                var com_text = $(this).attr('id');
            });

            $('.pcom_text').click(function()
            {
                var pcom_text = $(this).attr('id');
            });

            //Edit
            $('.edit').click(function()
            {
                $(this).hide();
                var itemWrapper = $(this).closest('.item-container'),
                    currentItemLabel = itemWrapper.find('.name').text().trim();

                itemWrapper.find('.name').hide();
                itemWrapper.find('.save,.cancel').show();
                itemWrapper.find('.com_text').val(currentItemLabel);
                itemWrapper.find('.com_text').show();
            });

            $('.pedit').click(function()
            {
                $(this).hide();
                var itemWrapper = $(this).closest('.item-container'),
                    currentItemLabel = itemWrapper.find('.pname').text().trim();

                itemWrapper.find('.pname').hide();
                itemWrapper.find('.psave,.pcancel').show();
                itemWrapper.find('.pcom_text').val(currentItemLabel);
                itemWrapper.find('.pcom_text').show();
            });

            //Cancel
            $('.cancel').click(function()
            {
                $(this).hide();
                var itemWrapper = $(this).closest('.item-container');

                itemWrapper.find('.name,.edit').show();
                itemWrapper.find('.save').hide();
                itemWrapper.find('.com_text').hide();
                itemWrapper.find('.com_text').val('');
                $("#time_main_durations").hide();

            });

            $('.pcancel').click(function()
            {
                $(this).hide();
                var itemWrapper = $(this).closest('.item-container');

                itemWrapper.find('.pname,.pedit').show();
                itemWrapper.find('.psave').hide();
                itemWrapper.find('.pcom_text').hide();
                itemWrapper.find('.pcom_text').val('');

            });

            //Save
            $('.save').click(function()
            {
                var itemWrapper = $(this).closest('.item-container');
                var sname = itemWrapper.find('.com_text').val().trim();
                var ticket_id = $("input[name=ticket_id]").val();
                var status_id = itemWrapper.find('.com_text').find(':selected').attr('data-id');
                var dataobj = {};
                // dataobj.sid = $(this).attr('data-id');
                dataobj.status_id = status_id.trim();
                dataobj.sname = sname.trim();
                dataobj.ticket_id = ticket_id.trim();
                
                dataobj.time_durations = $('#time_main_durations option:selected').val();
                dataobj.user_id = $('#user_ids').val();
                
                dataobj._token = '<?php echo e(csrf_token()); ?>';
                // alert(JSON.stringify(dataobj));
                // Your Ajax Code Here
                // Then run this on success to handle updating
                $.ajax(
                    {
                        type:"POST",
                        dataType:"json",
                        url:"<?php echo e(url('/updateStatus')); ?>",
                        cache: false,
                        data: dataobj,
                        success:function(response)
                        {

                            $(".name").css("color", response['color'][0].color);
                            itemWrapper.find
                            itemWrapper.find('.name').html(sname.trim());
                            itemWrapper.find('.name,.edit').show();
                            itemWrapper.find('.save,.cancel').hide();
                            itemWrapper.find('.com_text').hide();
                            itemWrapper.find('.com_text').val('');
                                                        itemWrapper.find('#time_main_durations').val('');
                            $("#time_main_durations").hide();

                            
                            var notifymessages = "";
                            if(response['notification'][0].time_durations_id != 0)
                            {
                                notifymessages += "On <b>"+response['notification'][0].duration_name+"</b>";
                            }
                            $(".messages_layout").append('<li class="left"><div class="message_wrap1 alert alert-info"><span class="status-notification">Status Set To <b>'+response['notification'][0].status_name+'</b>On <b>'+notifymessages+'</b>, Updated By <b>'+response['notification'][0].uname+'</b></span></div></li>');
                        }
                    });



            });

            //Save
            $('.psave').click(function()
            {

                var itemWrapper = $(this).closest('.item-container');
                var pname = itemWrapper.find('.pcom_text').val().trim();
                var ticket_id = $("input[name=ticket_id]").val();
                var priority_id = itemWrapper.find('.pcom_text').find(':selected').attr('data-id')
                var dataobj = {};
                // dataobj.sid = $(this).attr('data-id');
                dataobj.priority_id = priority_id.trim();
                dataobj.pname = pname.trim();
                dataobj.ticket_id = ticket_id.trim();
                dataobj._token = '<?php echo e(csrf_token()); ?>';
                //  alert(JSON.stringify(dataobj));

                // Your Ajax Code Here
                // Then run this on success to handle updating
                $.ajax(
                    {
                        type:"POST",
                        dataType:"json",
                        url:"<?php echo e(url('/updatepriorities')); ?>",
                        cache: false,
                        data: dataobj,
                        success:function(response)
                        {

                            // ver rescolor = response['color'][0].color;

                            $(".pname").css("color", response['color'][0].color);

                            itemWrapper.find
                            itemWrapper.find('.pname').html(pname.trim());
                            itemWrapper.find('.pname,.pedit').show();
                            itemWrapper.find('.psave,.pcancel').hide();
                            itemWrapper.find('.pcom_text').hide();
                            itemWrapper.find('.pcom_text').val('');
                            $("#time_main_durations").hide();
                        }
                    });
            });
            
                        $('.status_com_text').click(function()
            {
                var status_com_text = $(this).attr('id');
            });


            //Edit
            $('.status_edit').click(function()
            {
                $(this).hide();
                var itemWrapper = $(this).closest('.status-container'),
                    currentItemLabel = itemWrapper.find('.name').text().trim();

                itemWrapper.find('.status_name').hide();
                itemWrapper.find('.status_save,.status_cancel').show();
                itemWrapper.find('.status_com_text').val(currentItemLabel);
                itemWrapper.find('.status_com_text').show();
            });
 
            //Cancel
            $('.status_cancel').click(function()
            {
                $(this).hide();
                var itemWrapper = $(this).closest('.status-container');

                itemWrapper.find('.status_name,.status_edit').show();
                itemWrapper.find('.status_save').hide();
                itemWrapper.find('.status_com_text').hide();
                itemWrapper.find('.status_com_text').val('');
                $("#time_durations").hide();

            });
            //Save
            $('.status_save').click(function()
            {
                var itemWrapper = $(this).closest('.status-container');
                var sname = itemWrapper.find('.status_com_text').val().trim();
                var ticket_id = $("input[name=ticket_id]").val();
                var status_id = itemWrapper.find('.status_com_text').find(':selected').attr('data-id')
                var dataobj = {};
                // dataobj.sid = $(this).attr('data-id');
                dataobj.status_id = status_id.trim();
                dataobj.sname = sname.trim();
                dataobj.ticket_id = ticket_id.trim();

                dataobj.time_durations = $('#time_durations option:selected').val();
                dataobj.user_id = $('#user_ids').val();

                dataobj._token = '<?php echo e(csrf_token()); ?>';
                // alert(JSON.stringify(dataobj));
                // Your Ajax Code Here
                // Then run this on success to handle updating
                $.ajax(
                    {
                        type:"POST",
                        dataType:"json",
                        url:"<?php echo e(url('/updateStatus')); ?>",
                        cache: false,
                        data: dataobj,
                        success:function(response)
                        {
                            console.log(response);
                            $(".status_name").css("color", response['color'][0].color);
                            itemWrapper.find
                            itemWrapper.find('.status_name').html(sname.trim());
                            itemWrapper.find('.status_name,.status_edit').show();
                            itemWrapper.find('.status_save,.status_cancel').hide();
                            itemWrapper.find('.status_com_text').hide();
                            itemWrapper.find('.status_com_text').val('');
                            itemWrapper.find('#time_durations').val('');
                            $("#time_durations").hide();

                            var notifymessages = "";
                            if(response['notification'][0].time_durations_id != 0)
                            {
                                notifymessages += "On <b>"+response['notification'][0].duration_name+"</b>";
                            }
                            $(".messages_layout").append('<li class="left"><div class="message_wrap1 alert alert-info"><span class="status-notification">Status Set To <b>'+response['notification'][0].status_name+'</b>On <b>'+notifymessages+'</b>, Updated By <b>'+response['notification'][0].uname+'</b></span></div></li>');
                        }
                    });



            });

            
 
               //deal with copying the ckeditor text into the actual textarea
        CKEDITOR.on('instanceReady', function () {
        $.each(CKEDITOR.instances, function (instance) {
            CKEDITOR.instances[instance].document.on("keyup", CK_jQ);
            CKEDITOR.instances[instance].document.on("paste", CK_jQ);
            CKEDITOR.instances[instance].document.on("keypress", CK_jQ);
            CKEDITOR.instances[instance].document.on("blur", CK_jQ);
            CKEDITOR.instances[instance].document.on("change", CK_jQ);
        });
        });
        
        function CK_jQ() {
        for (instance in CKEDITOR.instances) {
            CKEDITOR.instances[instance].updateElement();
        }
        }
        
        CKEDITOR.config.toolbar = [
            ['Bold','Italic','Underline','myCombo']

        ] ;
            
        CKEDITOR.replace( 'content', {
                extraPlugins: 'autogrow',
                toolbarGroups: [
                    { name: 'mode' },
                    { name: 'basicstyles' },
                    { name: 'styles' }        
               ],
                on: {        
                    pluginsLoaded: function() {
                        var editor = this,
                            config = editor.config;
                        
                        function parseSpan( color ) {
                           // return '<span style="color:' + color + '">' + color + '</span>';
                           //console.log(color);
                           return color;
                        }
                        function htmlDecode(input){
                          var e = document.createElement('div');
                          e.innerHTML = input;
                          return e.childNodes[0].nodeValue;
                        } 
                        
                        var acfRules = 'span{color}';
                     
                        editor.ui.addRichCombo( 'myCombo', {
                            label: 'Canned responses',
                            title: 'Canned responses',
                            toolbar: 'styles',
                            
                            allowedContent: acfRules,
                            
                            requiredContent: acfRules,
               
                            panel: {
                                css: [ CKEDITOR.skin.getPath( 'editor' ) ].concat( config.contentsCss ),
                                multiSelect: false
                            },
                
                            init: function() {
                                this.startGroup( 'Canned responses' );
                                
            
            
                                var items = JSON.parse(htmlDecode('<?php echo e($cannedresponses); ?>'));   
                                 
            
                                //var items =[{"title":"This is a test responses","content":"<p>This is a test responses<\/p>"},{"title":"second canned response","content":"<p>second canned response<\/p>"},{"title":"simple new responsed","content":"<p>simple new responsed&nbsp;simple new responsed&nbsp;simple new responsed&nbsp;simple new responsed&nbsp;simple new responsed&nbsp;simple new responsed&nbsp;simple new responsed&nbsp;simple new responsed&nbsp;simple new responsed&nbsp;simple new responsed&nbsp;simple new responsed<\/p>"}];
                                //console.log(items);
                                for ( var i = 0; i < items.length; i++ ) {
                                    var item = items[ i ];
                                    var content  = item.content.replace(/\n|\r/g, "");
                                    this.add(content, parseSpan( item.title), item.title );
                                }
                            },
            
                            onClick: function( value ) {
                                editor.focus();
                            
                                editor.fire( 'saveSnapshot' );
                               
                                editor.insertHtml( parseSpan( value ) );                    
                                
                                editor.fire( 'saveSnapshot' );
                            },
                            onRender: function() {
                            },
                            onOpen: function() {
                            },
                            refresh: function() {
                                if ( !editor.activeFilter.check( acfRules ) )
                                    this.setState( CKEDITOR.TRISTATE_DISABLED );
                            }
                        } );            
                    }
                }
            } );    
            
            
        });



        $("#form").validate({
            rules: {
                content: {
                    required: true,
                    minlength: 10
                }
            },
            messages: {
                content: {
                required: "Enter Describe your issue here in details",
                    minlength: "Minimum password length is 10"
            }
        },
            submitHandler: function(form) {
                form.submit();
            }
        });
        


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

<?php echo $__env->make('layouts.layout', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>