<?php $__env->startSection('title', trans('communication.title.emails')); ?>

<?php $__env->startSection('page_stylesheets'); ?>
    <link href="<?php echo e(asset('assets/libs/sweetalert/sweetalert.css')); ?>" rel="stylesheet">
<?php $__env->stopSection(); ?>

<?php $__env->startSection('profile_bar'); ?>
        <div class="ui segment white right-bar-profile">
            <!-- client profile -->
            <div class="user-profile m-b-15">
                <?php if($recipient->profile_image_filename === 'default-profile.jpg'): ?>
                <div class="text-avatar" style="background-color:<?php echo e(collect(config('insura.colors'))->random()); ?>;"><?php echo e(strtoupper($recipient->first_name[0] . $recipient->last_name[0])); ?></div>
                <?php else: ?>
                <img src="<?php echo e(asset('uploads/images/users/' . $recipient->profile_image_filename)); ?>" alt="<?php echo e($recipient->first_name . ' ' . $recipient->last_name); ?>"/>
                <?php endif; ?>
                <h3><?php echo e($recipient->first_name . ' ' . $recipient->last_name); ?></h3>
                <span>
                    <?php if($recipient->status): ?>
                    <i class="ion-ios-circle-filled text-success"></i> <?php echo e(trans('communication.status.active', array(
                        'role'  => studly_case($recipient->role),
                    ))); ?>

                    <?php else: ?>
                    <i class="ion-ios-circle-filled text-danger"></i> <?php echo e(trans('communication.status.inactive', array(
                        'role'  => studly_case($recipient->role),
                    ))); ?>

                    <?php endif; ?>
                </span>
                <div class="m-t-25">
                    <?php if(in_array($user->role, array('super', 'admin')) && in_array($recipient->role, array('broker', 'client', 'staff'))): ?>
                    <a class="ui button positive" href="<?php echo e(action(studly_case($recipient->role) . 'Controller@getOne', array($recipient->id))); ?>"><i class="user outline icon"></i> <?php echo e(trans('communication.button.profile')); ?> </a>
                    <?php endif; ?>
                </div>
            </div>
            <div class="scrollbar">
                <div class="user-more-data">
                    <div class="divider m-t-0"></div>
                    <!-- client details -->
                    <div class="user-contact">
                        <div>
                            <span><?php echo e(trans('communication.label.email')); ?></span>
                            <p><?php echo e($recipient->email); ?></p>
                        </div>
                        <div>
                            <span><?php echo e(trans('communication.label.phone')); ?></span>
                            <p><?php echo e(isset($recipient->phone) ? $recipient->phone : '(---) ---- --- --'); ?></p>
                        </div>
                        <div>
                            <span><?php echo e(trans('communication.label.birthday')); ?></span>
                            <p><?php echo e(is_null($recipient->birthday) ? '---------- --, ----' : date('jS F Y', strtotime($recipient->birthday))); ?></p>
                        </div>
                        <div>
                            <span><?php echo e(trans('communication.label.address')); ?></span>
                            <p><?php echo e(isset($recipient->address) ? $recipient->address : '. . .'); ?></p>
                        </div>
                    </div>
                    <!-- end client details -->
                </div>
            </div>
        </div>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('content'); ?>
        @parent
        <div class="half-page-content">
            <?php echo $__env->make('global.status', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
            <div class="ui segment white fs-16">
                <div class="segment-header">
                    <h3><?php echo e(trans('communication.table.title.emails', array(
                        'name'  => $recipient->first_name
                    ))); ?></h3>
                    <button class="ui right floated button successish m-w-140" data-target="#newEmailModal" data-toggle="modal"><?php echo e(trans('communication.button.email')); ?></button>
                </div>
                <table class="ui celled striped table">
                    <thead>
                        <tr>
                            <th> <?php echo e(trans('communication.table.header.from')); ?> </th>
                            <th> <?php echo e(trans('communication.table.header.subject')); ?> </th>
                            <th> <?php echo e(trans('communication.table.header.date')); ?> </th>
                            <th class="center aligned"> <?php echo e(trans('communication.table.header.actions')); ?> </th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php $__empty_1 = true; foreach($emails as $email): $__empty_1 = false; ?>
                        <tr class="<?php echo e($email->status ? 'positive' : 'negative'); ?>">
                            <td><?php echo e($email->sender->id === $user->id ? 'You': $email->sender->first_name); ?></td>
                            <td class="text-ellipsis"><?php echo e($email->subject); ?></td>
                            <td><?php echo e(date('F d, Y', strtotime($email->created_at))); ?></td>
                            <td class="center aligned">
                                <a href="#" class="ui tiny grey label" data-target="#readEmail<?php echo e($email->id); ?>Modal" data-toggle="modal"> <?php echo e(trans('communication.table.data.action.read')); ?> </a>
                                <form action="<?php echo e(action('EmailController@delete', array($email->id))); ?>" method="POST" style="display:inline;">
                                    <?php echo e(csrf_field()); ?>

                                    <?php echo e(method_field('DELETE')); ?>

                                    <button href="#" class="ui red tiny label delete" style="cursor:pointer;" type="submit"> <?php echo e(trans('communication.table.data.action.delete')); ?> </button>
                                </form>
                            </td>
                        </tr>
                        <?php endforeach; if ($__empty_1): ?>
                        <tr>
                            <td class="text-center" colspan="4"><?php echo e(trans('communication.table.message.empty')); ?></td>
                        </tr>
                        <?php endif; ?>
                    </tbody>
                </table>
            </div>
        </div>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('modals'); ?>
    <!-- new email modal -->
    <div class="ui tiny modal" id="newEmailModal">
        <div class="header"><?php echo e(trans('communication.modal.header.email')); ?></div>
        <div class="content">
            <p><?php echo e(trans('communication.modal.instruction.send', array(
                'name'  => $recipient->first_name . ' ' . $recipient->last_name,
                'type'  => 'an email'
            ))); ?></p>
            <form action="<?php echo e(action('EmailController@add')); ?>" method="POST">
                <?php echo e(csrf_field()); ?>

                <input type="hidden" name="recipient" value="<?php echo e($recipient->id); ?>"/>
                <div class="ui form">
                    <div class="field required">
                        <label><?php echo e(trans('communication.input.label.subject')); ?></label>
                        <input type="text" name="subject" placeholder="<?php echo e(trans('communication.input.placeholder.subject')); ?>" required value="<?php echo e(old('subject')); ?>"/>
                    </div>
                    <div class="field required">
                        <label><?php echo e(trans('communication.input.label.message')); ?></label>
                        <textarea rows="5" name="message" placeholder="<?php echo e(trans('communication.input.placeholder.message')); ?>" required><?php echo e(session('text') ? '' : old('message')); ?></textarea>
                    </div>
                </div>
            </form>
        </div>
        <div class="actions">
            <div class="ui buttons">
                <button class="ui cancel button"><?php echo e(trans('communication.modal.button.cancel')); ?></button>
                <div class="or" data-text="<?php echo e(trans('communication.modal.button.or')); ?>"></div>
                <button class="ui positive primary button"><?php echo e(trans('communication.modal.button.confirm')); ?></button>
            </div>
        </div>
    </div>

    <?php foreach($emails as $email): ?>
    <div class="ui tiny modal" id="readEmail<?php echo e($email->id); ?>Modal">
        <div class="ui icon header">
            <i class="envelope open outline icon"></i>
            <?php echo e($email->subject); ?>

        </div>
        <div class="scrolling content">
            <p><?php echo e($email->message); ?></p>
            <p>
                <?php echo e(trans('communication.modal.content.yours')); ?>,<br/>
                <?php echo e($email->sender->first_name . ' ' . $email->sender->last_name); ?>

            </p>
        </div>
        <div class="actions">
            <div class="ui red cancel button">
                <i class="remove icon"></i>
                <?php echo e(trans('communication.modal.button.dismiss')); ?>

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

<?php $__env->startSection('page_scripts'); ?>
    <script src="<?php echo e(asset('assets/libs/sweetalert/sweetalert.min.js')); ?>" type="text/javascript"></script>
    <script type="text/javascript">
        (function($insura, $) {
            $(document).ready(function() {
                if ($(window).width() > 992) {
                    getVisible();
                }else{
                    $('div.right-bar-profile div.scrollbar').removeAttr("style");
                }

                $(window).resize(function(){
                    if ($(window).width() > 992) {
                        getVisible();
                    }else{
                        $('div.right-bar-profile div.scrollbar').removeAttr("style");
                    }
                });

                $insura.helpers.initModal('div.modal', true);
                $insura.helpers.initScrollbar('div.scrollbar');
                $insura.helpers.initSwal('form button.delete', {
                    confirmButtonText: '<?php echo e(trans('communication.swal.warning.delete.confirm')); ?>',
                    text: '<?php echo e(trans('communication.swal.warning.delete.text', array(
                        'type'  => 'email'
                    ))); ?>',
                    title: '<?php echo e(trans('communication.swal.warning.delete.title')); ?>'
                });
                $insura.helpers.listenForChats();
            });
        })(window.insura, window.jQuery);
    </script>
<?php $__env->stopSection(); ?>

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