<?php $__env->startSection('content'); ?>
<?php echo $__env->make('closer.closerheader', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>

   
<div class='container'>
    <div class="page-title-box">
                <div class="row align-items-center">
                    <div class="col-sm-6">
                        <h4 class="page-title">Business Profile</h4>
                    </div>
                    <div class="col-sm-6">
                        <ol class="breadcrumb float-right">
                            <li class="breadcrumb-item"><a href="javascript:void(0);">Closer</a></li>
                            <li class="breadcrumb-item active">Business Profile</li>
                        </ol>
                    </div>
                </div>
                <!-- end row -->
    </div>
         <?php $__currentLoopData = $orderdetail; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $detail): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <div class="row mt-2">
                <div class="col-md-12">
                    <div class="row">
                    <h2>Order #<?php echo e(strtoupper($detail->ordernumber)); ?></h2>
                                <hr>
                        <div class="col-md-7">
                            <div class="business-info-sec"> 
                            <h5><?php echo e($detail->bname); ?></h5>
                            <hr>
                                <div class='row'>
                                    <div class='col-md-6'>
                                        <p>Invoice #<?php echo e($detail->invoice_id); ?></p>
                                        <p><i class='fas fa-envelope'></i> <?php echo e($detail->bemail); ?></p>
                                        <p><i class='fas fa-phone-square'></i> <?php echo e($detail->bphone); ?></p>
                                    </div>
                                    <div class='col-md-6'>
                                        <p><i class='fab fa-bandcamp'></i> Category</p>
                                        <p><i class='fas fa-clock'></i> Timezone</p>
                                    </div>
                                </div>
                            </div>
                            <hr>
                            <div class="radius-detail">
                                <div class='row'>
                                    <div class='col-md-6'>
                                         <h5><?php echo e($detail->radius); ?> Miles</h5>
                                         <p><i class='fas fa-map-marked-alt'></i> <?php echo e($detail->radius_address); ?></p>
                                         <h5>Assist By</h5>
                                <p><i class='fas fa-user'></i> <?php echo e($detail->closer_name); ?></p>
                                    </div>
                                    <div class='col-md-6'>
                                        <h5><?php echo e($detail->productname); ?></h5>
                                        <p>$<?php echo e($detail->price); ?></p>
                                    </div>
                                </div>
                            </div>
                                                  
                        </div>
                        <div class="col-md-5">
                            <img style='width:100%;border-radius:5px;' src='<?php echo e($detail->radius_image); ?>'>
                    </div>
                </div>
            </div>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            <hr>
            <div class="row d-flex justify-content-center">
                <div class="col-md-12 py-2">
                <h4 class="mt-2">Campaign Comments</h4>
                    <div class="comment-div mt-3" id="style-7">
                     
                      
                    </div>
                    <div class="comment-box-form">
                       <form id="commentform">
                        
                            <div>
                                <?php $__currentLoopData = $orderdetail; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $ord): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <input type='hidden' name='order_id' value='<?php echo e($ord->order_id); ?>'>
                                <input type='hidden' id="userid" name='userid' value='<?php echo e($ord->userid); ?>'>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                <textarea class="form-control" id="comments" name="comments" rows="4" placeholder="Write details..."></textarea>
                                <button class="mt-2 btn btn-primary" type="submit">Add Follow Up</button>
                            </div>
                       </form>
                    </div>
                </div>
            </div>
</div>

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

    showcomments();

    function showcomments(){
        var clientid = $('#userid').val();
        $.ajax({
            type: 'GET',
            url: `<?php echo e(url('closer/showcomments')); ?>/${clientid}`,
            success: function(response){

                $("#style-7").empty();
                $.each(response,function(index,item){
                    let formattedDate = formatDate(item.created_at);
                    console.log(item.created_at);
                    document.getElementById("style-7")
                .innerHTML+=
                `<div class="comment-box">
                <span style="font-size: 16px;font-weight: 700;">`
                +item.first_name+
                ` `+item.last_name+`</span> &nbsp;&nbsp;&nbsp;.&nbsp;&nbsp;&nbsp; <span class="comment-date">`+formattedDate+ `</span><p class="mt-2">`+item.comments+`</p></div>`;
                });
            }
        });
    }

    // Helper function to format date
    function formatDate(dateString) {
        let now = new Date();
    let date = new Date(dateString);
    let seconds = Math.floor((now - date) / 1000);
    
    let interval = Math.floor(seconds / 31536000);
    if (interval >= 1) {
        return interval + " year" + (interval > 1 ? "s" : "") + " ago";
    }
    interval = Math.floor(seconds / 2592000);
    if (interval >= 1) {
        return interval + " month" + (interval > 1 ? "s" : "") + " ago";
    }
    interval = Math.floor(seconds / 86400);
    if (interval >= 1) {
        return interval + " day" + (interval > 1 ? "s" : "") + " ago";
    }
    interval = Math.floor(seconds / 3600);
    if (interval >= 1) {
        return interval + " hour" + (interval > 1 ? "s" : "") + " ago";
    }
    interval = Math.floor(seconds / 60);
    if (interval >= 1) {
        return interval + " minute" + (interval > 1 ? "s" : "") + " ago";
    }
    return Math.floor(seconds) + " second" + (seconds > 1 ? "s" : "") + " ago";
    }

    $('#commentform').on('submit', function(e) {
        e.preventDefault(); 
        var formData = $(this).serialize();
        $.ajax({
            headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            },
            type: 'post',
            url: '<?php echo e(route("add-comment")); ?>',
            data: formData, // Pass serialized form data
            success: function(response) {
              showcomments();
              $('#comments').val("");

         }
        });
        
      });
      
  });


</script>

<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /Applications/XAMPP/xamppfiles/htdocs/tprproject/get-myaio-app/resources/views/closer/orderdetails.blade.php ENDPATH**/ ?>