<?php $__env->startSection('content'); ?>
<!-- <div class="card card-chat overflow-hidden">
         <div class="card-body d-flex p-0 h-100">
             <div class="chat-sidebar">
                 <div class="contacts-list scrollbar-overlay">
                     <div class="nav nav-tabs border-0 flex-column" role="tablist" aria-orientation="vertical">
                         <?php $__currentLoopData = $affiliate_publisher; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $affliate): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                             <div class="hover-actions-trigger chat-contact nav-item active"
                                 role="tab" id="<?php echo e($affliate->id . $affliate->id); ?>" data-bs-toggle="tab"
                                 data-bs-target="#<?php echo e($affliate->id); ?>" aria-controls="<?php echo e($affliate->id); ?>"
                                 aria-selected="true">
                                 <div class="d-md-none d-lg-block">
                                     <div class="dropdown dropdown-active-trigger dropdown-chat">
                                         <button
                                             class="hover-actions btn btn-link btn-sm text-400 dropdown-caret-none dropdown-toggle end-0 fs-0 mt-4 me-1 z-index-1 pb-2 mb-n2"
                                             type="button" data-boundary="viewport" data-bs-toggle="dropdown"
                                             aria-haspopup="true" aria-expanded="false"><span class="fas fa-cog"
                                                 data-fa-transform="shrink-3 down-4"></span></button>
                                         <div class="dropdown-menu dropdown-menu-end border py-2 rounded-2"><a
                                                 class="dropdown-item" href="#!">Mute</a>
                                             <div class="dropdown-divider"></div><a class="dropdown-item"
                                                 href="#!">Archive</a><a class="dropdown-item text-danger"
                                                 href="#!">Delete</a>
                                             <div class="dropdown-divider"></div><a class="dropdown-item"
                                                 href="#!">Mark as Unread</a><a class="dropdown-item"
                                                 href="#!">Something's Wrong</a><a class="dropdown-item"
                                                 href="#!">Ignore Messsages</a><a class="dropdown-item"
                                                 href="#!">Block Messages</a>
                                         </div>
                                     </div>
                                 </div>
                                  <a href="<?php echo e(route('publisher.chat',$affliate->id)); ?>" style="text-decoration: none;">
                                 <div class="d-flex p-3">
                                     <div class="avatar avatar-xl status-online">
                                         <img class="rounded-circle" src="<?php echo e($affliate->photourl); ?>" alt="" />

                                     </div>
                                     <div class="flex-1 chat-contact-body ms-2 d-md-none d-lg-block">
                                         <div class="d-flex justify-content-between">
                                             <h6 class="mb-0 chat-contact-title"><?php echo e($affliate->name); ?></h6><span
                                                 class="message-time fs--2">Tue</span>
                                         </div>
                                         <div class="min-w-0">
                                             <div class="chat-contact-content pe-3"><?php echo e($affliate->name); ?>

                                                    <?php if(!empty($total_unread)): ?>
                                                <?php echo e($total_unread); ?> Messages are recieved
                                                    <?php endif; ?>
                                             </div>
                                             <div class="position-absolute bottom-0 end-0 hover-hide">
                                             </div>
                                         </div>
                                     </div>
                                 </div>
                                      </a>
                             </div>
                    
                         <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>




                     </div>
                 </div>
                 <form class="contacts-search-wrapper">
                     <div class="form-group mb-0 position-relative d-md-none d-lg-block w-100 h-100">
                         <input class="form-control form-control-sm chat-contacts-search border-0 h-100" type="text"
                             placeholder="Search contacts ..." /><span class="fas fa-search contacts-search-icon"></span>
                     </div>
                     <button class="btn btn-sm btn-transparent d-none d-md-inline-block d-lg-none"><span
                             class="fas fa-search fs--1"></span></button>
                 </form>
             </div>
             <div class="tab-content card-chat-content">
                 <?php $__currentLoopData = $affiliate_publisher; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $affliate): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                     <div class="tab-pane card-chat-pane active" id="<?php echo e($affliate->id); ?>"
                         role="tabpanel" aria-labelledby="<?php echo e($affliate->id . $affliate->id); ?>">
                         <div class="chat-content-header">
                             <div class="row flex-between-center">
                                 <div class="col-6 col-sm-8 d-flex align-items-center"><a
                                         class="pe-3 text-700 d-md-none contacts-list-show" href="#!">
                                         <div class="fas fa-chevron-left"></div>
                                     </a>
                                     <div class="min-w-0">
                                         <h5 class="mb-0 text-truncate fs-0"><?php echo e($affliate->name); ?></h5>
                                         <div class="fs--2 text-400">Active On Chat
                                         </div>
                                     </div>
                                 </div>
                                 <div class="col-auto">
                                     <button class="btn btn-sm btn-falcon-primary me-2" type="button" data-index="0"
                                         data-bs-toggle="tooltip" data-bs-placement="top" title="Mark all as read"><span
                                             class="fas fa-eye"></span></button>
                                     <button class="btn btn-sm btn-falcon-primary me-2" type="button" data-index="0"
                                         data-bs-toggle="tooltip" data-bs-placement="top" title="Start a Video Call"><span
                                             class="fas fa-video"></span></button>
                                     <button class="btn btn-sm btn-falcon-primary btn-info" type="button" data-index="0"
                                         data-bs-toggle="tooltip" data-bs-placement="top"
                                         title="Conversation Information"><span class="fas fa-info"></span></button>
                                 </div>
                             </div>
                         </div>
                         <div class="chat-content-body" style="display: inherit;">
                             <div class="conversation-info" data-index="0">
                                 <div class="h-100 overflow-auto scrollbar">
                                     <div class="d-flex position-relative align-items-center p-3 border-bottom">
                                         <div class="avatar avatar-xl status-online">
                                             <img class="rounded-circle"
                                                 src="<?php echo e($affliate->photourl); ?>"
                                                 alt="" />

                                         </div>
                                         <div class="flex-1 ms-2 d-flex flex-between-center">
                                             <h6 class="mb-0"><a class="text-decoration-none stretched-link text-700"
                                                     href=""><?php echo e($affliate->name); ?></a></h6>
                                             <div class="dropdown z-index-1">
                                                 <button
                                                     class="btn btn-link btn-sm text-400 dropdown-toggle dropdown-caret-none me-n3"
                                                     type="button" id="profile-dropdown-0" data-bs-toggle="dropdown"
                                                     aria-haspopup="true" aria-expanded="false"><span
                                                         class="fas fa-cog"></span></button>
                                                
                                             </div>
                                         </div>
                                     </div>
                                    
                                    
                                 </div>
                             </div>
                             <div class="chat-content-scroll-area scrollbar">
                                 <div class="d-flex position-relative p-3 border-bottom mb-3 align-items-center">
                                     <div class="avatar avatar-2xl status-online me-3">
                                         <img class="rounded-circle" src="<?php echo e($affliate->photourl); ?>" alt="" />

                                     </div>
                                     <div class="flex-1">
                                         <h6 class="mb-0"><a class="text-decoration-none stretched-link text-700"
                                                 href="javascript:void(0)"><?php echo e($affliate->name); ?></a></h6>
                                         <p class="mb-0">You Affliate Manager <?php echo e($affliate->name); ?>. Say hi to start the
                                             conversation
                                         </p>
                                     </div>
                                 </div>
                                <?php $data=date('Y');?>
                                 <?php $__currentLoopData = $message; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $messag): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                 
                                 <?php if($data!=date_format(date_create($messag->created_at), 'd')): ?>
                                 <?php $data=date_format(date_create($messag->created_at), 'd');?>
                                  <div class="text-center fs--2 text-500"><span><?php echo e(date_format(date_create($messag->created_at), 'M d Y h:i a')); ?></span></div>
                                  <?php endif; ?>
                                     <?php if($messag->sender == 'affliate'): ?>
                                         <div class="d-flex p-3">
                                             <div class="avatar avatar-l me-2">
                                                 <img class="rounded-circle" src="<?php echo e($affliate->photourl); ?>"
                                                     alt="" />

                                             </div>
                                             <div class="flex-1">
                                                 <div class="w-xxl-75">
                                                     <div class="hover-actions-trigger d-flex align-items-center">
                                                         <div class="chat-message bg-200 p-2 rounded-2">
                                                            <p> <?php echo $messag->message; ?></p> 
                                                            <?php if(!empty($messag->photourl)): ?>
                                                            <a href="<?php echo e($messag->photourl); ?>" ><img src="<?php echo e($messag->photourl); ?>" width="100" height="100"></a>
                                                        <?php endif; ?></div>
                                                         <ul
                                                             class="hover-actions position-relative list-inline mb-0 text-400 ms-2">
                                                             <li class="list-inline-item"><a class="chat-option"
                                                                     href="#!" data-bs-toggle="tooltip"
                                                                     data-bs-placement="top" title="Edit"><span
                                                                         class="fas fa-edit"></span></a></li>
                                                             <li class="list-inline-item"><a class="chat-option"
                                                                     href="#!" data-bs-toggle="tooltip"
                                                                     data-bs-placement="top" title="Remove"><span
                                                                         class="fas fa-trash-alt"></span></a></li>
                                                         </ul>
                                                     </div>
                                                     <div class="text-400 fs--2">
                                                         <span><?php echo e(date_format(date_create($messag->created_at), ' H:i')); ?></span>
                                                     </div>
                                                 </div>
                                             </div>
                                         </div>
                                     <?php else: ?>
                                         <div class="d-flex p-3">
                                             <div class="flex-1 d-flex justify-content-end">
                                                 <div class="w-100 w-xxl-75">
                                                     <div class="hover-actions-trigger d-flex flex-end-center">
                                                         <ul
                                                             class="hover-actions position-relative list-inline mb-0 text-400 me-2">
                                                            
                                                             <li class="list-inline-item"><a class="chat-option"
                                                                     href="#!" data-bs-toggle="tooltip"
                                                                     data-bs-placement="top" title="Edit"><span
                                                                         class="fas fa-edit"></span></a></li>
                                                             <li class="list-inline-item"><a class="chat-option"
                                                                     href="#!" data-bs-toggle="tooltip"
                                                                     data-bs-placement="top" title="Remove"><span
                                                                         class="fas fa-trash-alt"></span></a></li>
                                                         </ul>
                                                         <div
                                                             class="bg-primary text-white p-2 rounded-2 chat-message light">
                                                             <p class="mb-0"><?php echo $messag->message; ?></p>
                                                             <?php if(!empty($messag->photourl)): ?>
                                                            <a href="<?php echo e($messag->photourl); ?>" ><img src="<?php echo e($messag->photourl); ?>" width="100" height="100"></a>
                                                            <?php endif; ?>

                                                         </div>
                                                     </div>
                                                     <div class="text-400 fs--2 text-end">
                                                        <?php echo e(date_format(date_create($messag->created_at), ' h:i a')); ?><span
                                                             class="fas fa-check ms-2 text-success"></span>
                                                     </div>
                                                 </div>
                                             </div>
                                         </div>
                                     <?php endif; ?>
                                 <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>


                             </div>
                         </div>
                     </div>
                        
                 <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    <form class="chat-editor-area" id="send_message_to_affliate" enctype="multipart/form-data">
                        <?php echo csrf_field(); ?>
                     <div class="emojiarea-editor outline-none scrollbar" contenteditable="true"></div>
                     <input class="d-none" name="file" type="file" id="chat-file-upload" />
                     <input class="d-none" name="affliate" type="hidden" value="affliate" id="chat-file-upload" />
                     <input class="d-none" name="message" type="hidden" value="" id="chat-message" />
                     <label class="chat-file-upload cursor-pointer" for="chat-file-upload"><span
                             class="fas fa-paperclip"></span></label>
                     <div class="btn btn-link emoji-icon" data-emoji-button="data-emoji-button"><span
                             class="far fa-laugh-beam"></span></div>
                     <button class="btn btn-sm btn-send" type="submit">Send</button>
                 </form>
            
             </div>
         </div>
     </div> -->
<!-- Start Content-->
<div class="container-fluid">

    <!-- start page title -->
    <div class="row">
        <div class="col-12">
            <div class="bg-flower">
                <img src="assets/images/flowers/img-3.png">
            </div>

            <div class="bg-flower-2">
                <img src="assets/images/flowers/img-1.png">
            </div>

            <div class="page-title-box">
                <div class="page-title-right">
                    <ol class="breadcrumb m-0">
                        <li class="breadcrumb-item"><a href="javascript: void(0);">Publisher</a></li>
                        <li class="breadcrumb-item active">Chat</li>
                    </ol>
                </div>
                <h4 class="page-title">Chat</h4>
            </div>
        </div>
    </div>
    <!-- end page title -->

    <div class="row">
        <!-- start chat users-->
        <div class="col-xl-3 col-lg-4">
            <div class="card">
                <div class="card-body">
                    <div class="d-flex align-items-start mb-3">
                        <img src="<?php echo e($affliate->photourl); ?>" class="me-2 rounded-circle" height="42" alt="Brandon Smith">
                        <div class="w-100">
                            <h5 class="mb-0">
                                <a href="javascript: void(0);" class="text-reset lh-base"><?php echo e($affliate->name); ?></a>
                            </h5>
                            <p class="mb-0 text-muted">
                                <small class="ri-checkbox-blank-circle-fill text-success"></small> Online
                            </p>
                        </div>
                        <a href="javascript: void(0);" class="text-reset fs-20">
                            <i class="ri-settings-5-line"></i>
                        </a>
                    </div>
                </div> <!-- end card-body-->

            </div> <!-- end card-->
        </div>
        <!-- end chat users-->

        <!-- chat area -->
        <div class="col-xl-9 col-lg-8">

            <div class="card">
                <div class="card-body py-2 px-3 border-bottom border-light">
                    <div class="row justify-content-between py-1">
                        <div class="col-sm-7">
                            <div class="d-flex align-items-start">
                                <img src="<?php echo e($affliate->photourl); ?>" class="me-2 rounded-circle" height="36" alt="Brandon Smith">
                                <div>
                                    <h5 class="my-0 font-15">
                                        <a href="pages-profile.html" class="text-reset"><?php echo e($affliate->name); ?></a>
                                    </h5>
                                    <p class="mt-1 mb-0 text-muted fs-12">
                                        <small class="ri-checkbox-blank-circle-fill text-success"></small> Online
                                    <p>You Affliate Manager <?php echo e($affliate->name); ?>. Say hi to start theconversation</p>
                                    </p>
                                </div>
                            </div>
                        </div>
                        <div class="col-auto">
                            <div id="tooltips-container">
                                <a href="javascript: void(0);" class="text-reset fs-20 p-1 d-inline-block">
                                    <i class="ri-phone-line" data-bs-container="#tooltips-container" data-bs-toggle="tooltip" data-bs-placement="top" title="Voice Call"></i>
                                </a>
                                <a href="javascript: void(0);" class="text-reset fs-20 p-1 d-inline-block">
                                    <i class="ri-vidicon-line" data-bs-container="#tooltips-container" data-bs-toggle="tooltip" data-bs-placement="top" title="Video Call"></i>
                                </a>
                                <a href="javascript: void(0);" class="text-reset fs-20 p-1 d-inline-block">
                                    <i class="ri-group-line" data-bs-container="#tooltips-container" data-bs-toggle="tooltip" data-bs-placement="top" title="Add Users"></i>
                                </a>
                                <a href="javascript: void(0);" class="text-reset fs-20 p-1 d-inline-block">
                                    <i class="ri-delete-bin-line" data-bs-container="#tooltips-container" data-bs-toggle="tooltip" data-bs-placement="top" title="Delete Chat"></i>
                                </a>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="card-body p-0">
                    <ul class="conversation-list p-3" data-simplebar style="max-height: 520px;">
                        <?php $data=date('Y');?>
                        <?php $__currentLoopData = $message; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $messag): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <?php if($data != date_format(date_create($messag->created_at), 'd')): ?>
                        <?php $data=date_format(date_create($messag->created_at), 'd');?>
                        <div class="text-center fs--2 text-500">
                            <span><?php echo e(date_format(date_create($messag->created_at), 'M d Y h:i a')); ?></span>
                        </div>
                        <?php endif; ?>
                        <?php if($messag->sender == 'affliate'): ?>
                        <li class="clearfix">
                            <div class="chat-avatar">
                                <img src="<?php echo e($affliate->photourl); ?>" class="rounded" alt="<?php echo e($affliate->name); ?>" />
                                <i><?php echo e(date_format(date_create($messag->created_at), ' H:i')); ?></i>
                            </div>
                            <div class="conversation-text">
                                <div class="ctext-wrap">
                                    <i><?php echo e($affliate->name); ?></i>
                                    <p>
                                        <?php echo $messag->message; ?>

                                    </p>
                                </div>
                            </div>
                            <div class="conversation-actions dropdown">
                                <button class="btn btn-sm btn-link fs-18" data-bs-toggle="dropdown" aria-expanded="false"><i class="ri-more-2-fill"></i></button>

                                <div class="dropdown-menu dropdown-menu-end">
                                    <a class="dropdown-item" href="#">Copy Message</a>
                                    <a class="dropdown-item" href="#">Edit</a>
                                    <a class="dropdown-item" href="#">Delete</a>
                                </div>
                            </div>
                        </li>
                        <?php else: ?>
                        <li class="clearfix odd">
                            <div class="chat-avatar">
                                <img src="<?php echo e($messag->photourl); ?>" class="rounded" alt="Geneva M">
                                <i><?php echo e(date_format(date_create($messag->created_at), ' H:i')); ?></i>
                            </div>
                            <div class="conversation-text">
                                <div class="ctext-wrap">
                                    <i>Your Name</i>
                                    <p>
                                        <?php echo $messag->message; ?>

                                    </p>
                                    <?php if(!empty($messag->photourl)): ?>
                                        <a href="<?php echo e($messag->photourl); ?>"><img src="<?php echo e($messag->photourl); ?>" width="100" height="100"></a>
                                    <?php endif; ?>
                                </div>
                            </div>
                            <div class="conversation-actions dropdown">
                                <button class="btn btn-sm btn-link fs-18" data-bs-toggle="dropdown" aria-expanded="false"><i class="ri-more-2-fill"></i></button>

                                <div class="dropdown-menu">
                                    <a class="dropdown-item" href="#">Copy Message</a>
                                    <a class="dropdown-item" href="#">Edit</a>
                                    <a class="dropdown-item" href="#">Delete</a>
                                </div>
                            </div>
                        </li>
                        <?php endif; ?>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </ul>

                    <div class="row">
                        <div class="col">
                            <div class="bg-light p-3 rounded">
                                <form class="needs-validation" novalidate="" id="send_message_to_affliate" enctype="multipart/form-data">
                                    <?php echo csrf_field(); ?>
                                    <div class="row">
                                        <div class="col mb-2 mb-sm-0">
                                            <div class="emojiarea-editor outline-none scrollbar form-control border-0" contenteditable="true"></div>
                                        </div>
                                        <div class="col-sm-auto">
                                            <input class="d-none" name="file" type="file" id="chat-file-upload" />
                                            <input class="d-none" name="affliate" type="hidden" value="affliate" id="chat-file-upload" />
                                            <input class="d-none" name="message" type="hidden" value="" id="chat-message" />
                                            <div class="btn-group">
                                                <label for="chat-file-upload" class="btn btn-light"><i class="ri-attachment-2"></i></label>
                                                <button type="submit" class="btn btn-success chat-send w-100"><i class="ri-send-plane-2-line"></i></button>
                                            </div>
                                        </div>
                                        <!-- end col -->
                                    </div>
                                    <!-- end row-->
                                </form>
                            </div>
                        </div>
                        <!-- end col-->
                    </div>
                    <!-- end row -->
                </div>
                <!-- end card-body -->
            </div> <!-- end card -->
        </div>
        <!-- end chat area-->

    </div> <!-- end row-->

</div> <!---container -->
<?php $__env->stopSection(); ?>
<?php $__env->startSection('js'); ?>
<script type="text/javascript">
    $(function() {
        $('.emojiarea-editor').keyup(function() {
            var msg = $('.emojiarea-editor').text();
            $('#chat-message').val(msg);
        });
        $('#chat-file-upload').change(function(e) {
            e.preventDefault();

            var form = $('#send_message_to_affliate')[0];
            var data = new FormData(form);
            $.ajax({
                url: "<?php echo e(route('publisher.send_message_to_affliate')); ?>",
                type: 'post',
                dataType: 'JSON',
                data: data,
                cache: false,
                contentType: false,
                processData: false,
                success: function(result) {
                    $('.loader').fadeOut();
                    // console.log(result);
                    if (!result.status) {
                        Swal.fire('Failed', result.message, 'error');

                    } else {

                        location.reload();


                    }
                },
                error: function(xhr) {
                    $('.loader').fadeOut();
                    if (xhr.status == 422) {
                        $.each(xhr.responseJSON.errors, function(k, v) {
                            form.find('[name="' + k + '"]').after(
                                '<div class="text-danger">' + v[
                                    0] +
                                '</div>');
                        });
                    } else if (xhr.status == 419) {
                        window.location.href = "";
                    }
                    // console.log(xhr);
                }
            });

        });
        $('#send_message_to_affliate').submit(function(e) {
            e.preventDefault();
            let data = new FormData(this);
            $.ajax({
                url: "<?php echo e(route('publisher.send_message_to_affliate')); ?>",
                type: 'post',
                dataType: 'JSON',
                data: data,
                cache: false,
                contentType: false,
                processData: false,
                success: function(result) {
                    $('.loader').fadeOut();
                    // console.log(result);
                    if (!result.status) {
                        Swal.fire('Failed', result.message, 'error');

                    } else {


                        location.reload();

                    }
                },
                error: function(xhr) {
                    $('.loader').fadeOut();
                    if (xhr.status == 422) {
                        $.each(xhr.responseJSON.errors, function(k, v) {
                            form.find('[name="' + k + '"]').after(
                                '<div class="text-danger">' + v[
                                    0] +
                                '</div>');
                        });
                    } else if (xhr.status == 419) {
                        window.location.href = "";
                    }
                    // console.log(xhr);
                }
            });

        });
    })
</script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('publisher.layout.dashboard', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/fiverrbdbse/public_html/backend/resources/views/publisher/chat.blade.php ENDPATH**/ ?>