<?php $__env->startSection('content'); ?>
<div class="master-main mainContent mobile maincontent-design2 middlebackground background-design5">
    <div class="container">
        <div class="row multi">
            <div class="hidden"></div>
            
            <div class="col-xs-12 col-single tabbed main-content">
                <div class="content-inner-container memo-content">
                    <h2 class="main-content-page-title">Memo</h2>
                    
                    
                    <?php if(session('success')): ?>
                        <div class="alert alert-success" style="margin-bottom: 15px;"><?php echo e(session('success')); ?></div>
                    <?php endif; ?>
                    <?php if($errors->any()): ?>
                        <div class="alert alert-danger" style="margin-bottom: 15px;">
                            <ul style="margin: 0; padding-left: 15px;"><?php $__currentLoopData = $errors->all(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $err): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?> <li><?php echo e($err); ?></li> <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?></ul>
                        </div>
                    <?php endif; ?>

                    <div class="well">
                        
                        <div class="btn-group-md">
                            <button type="button" class="btn btn-default alignbtn <?php echo e(!$isSent ? 'active' : ''); ?>" onclick="clickTab('<?php echo e(url('/mobile/account/memo')); ?>')">INBOX</button>
                            <button type="button" class="btn btn-default alignbtn" onclick="clickTab('<?php echo e(url('/mobile/account/memocompose')); ?>')">COMPOSE</button>
                            <button type="button" class="btn btn-default alignbtn <?php echo e($isSent ? 'active' : ''); ?>" onclick="clickTab('<?php echo e(url('/mobile/account/memo?sent=1')); ?>')">SEND</button>
                        </div>
                        
                        <div id="MainContent_PanelMail" style="margin-top: 15px;">
                            
                            
                            <form action="<?php echo e(route('account.memo.action', ['device' => $device ?? 'mobile'])); ?>" method="POST" id="memoForm">
                                <?php echo csrf_field(); ?>
                                <input type="hidden" name="memo_ids" id="MainContent_HiddenField2" />
                                <input type="hidden" name="action_type" id="action_type" />

                                <div class="table-responsive">
                                    <table class="table table-bordered table-mailbox" style="font-size: 12px;">
                                        <thead>
                                            <tr class="table-header-st">
                                                <th style="width: 40px; text-align: center; vertical-align: middle;">
                                                    <input type="checkbox" id="MainCheckbox" onclick="ClickCheckbox($(this))"/>
                                                </th>
                                                <th class="mail-msg" style="vertical-align: middle;">
                                                    <button type="submit" onclick="return setAction('read') && CheckRead() && CheckRepeat();" class="btn btn-default btn-xs alignbtn">Set to read</button>
                                                    <button type="submit" onclick="return setAction('delete') && ConfirmDelete() && CheckRepeat();" class="btn btn-danger btn-xs alignbtn" style="color: white; border-color: transparent;">Delete</button>
                                                </th>
                                                <th style="width: 100px; text-align: center; vertical-align: middle;">Tanggal</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            
                                            
                                            <?php $__empty_1 = true; $__currentLoopData = $memos; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $memo): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                                                <tr class="table-row-st" style="<?php echo e($memo->status_baca == 0 ? 'background-color: rgba(255,255,255,0.05);' : ''); ?>">
                                                    <td style="text-align: center; vertical-align: middle;">
                                                        <input type="checkbox" name="<?php echo e($memo->id); ?>" class="memo-chk" onclick="UpdateCheckbox()" />
                                                    </td>
                                                    <td class="mail-msg" style="vertical-align: middle;">
                                                        
                                                        <a href="javascript:;" onclick="openMemoModal('<?php echo e(addslashes($memo->judul)); ?>', '<?php echo e(date('d-m-Y H:i', strtotime($memo->created_at))); ?>', '<?php echo e(addslashes($memo->pesan)); ?>')" style="text-decoration: none; display: block; <?php echo e($memo->status_baca == 0 ? 'font-weight: bold; color: #f3c300;' : 'color: #ccc;'); ?>">
                                                            <?php if($memo->pengirim == 'admin'): ?>
                                                                <span style="color: #ff6600;">[Operator]</span>
                                                            <?php else: ?>
                                                                <span style="color: #00bcd4;">[Anda]</span>
                                                            <?php endif; ?>
                                                            <?php echo e(\Illuminate\Support\Str::limit($memo->judul, 25, '...')); ?>

                                                        </a>
                                                        
                                                        <?php if($memo->status_baca == 0): ?>
                                                            <span class="label label-danger" style="margin-top: 5px; display: inline-block;">NEW</span>
                                                        <?php endif; ?>
                                                    </td>
                                                    <td style="text-align: center; vertical-align: middle; font-size: 11px;">
                                                        <?php echo e(date('d-m-Y', strtotime($memo->created_at))); ?><br>
                                                        <?php echo e(date('H:i', strtotime($memo->created_at))); ?>

                                                    </td>
                                                </tr>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                                                <tr>
                                                    <td colspan="3" class="text-center" style="padding: 20px; color: #aaa;">
                                                        Tidak ada pesan <?php echo e($isSent ? 'terkirim' : 'masuk'); ?>.
                                                    </td>
                                                </tr>
                                            <?php endif; ?>
                                            
                                        </tbody>
                                    </table>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


<div class="modal fade" id="readMemoModal" tabindex="-1" role="dialog" aria-labelledby="readMemoModalLabel">
  <div class="modal-dialog modal-sm" role="document" style="margin-top: 20%;">
    <div class="modal-content" style="background: #1a1a1a; border: 1px solid #444; color: #fff;">
      <div class="modal-header" style="border-bottom: 1px solid #333;">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close" style="color: #fff; opacity: 1; text-shadow: none;"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="memoModalTitle" style="color: #f3c300; font-weight: bold; font-size: 16px;">Judul Memo</h4>
      </div>
      <div class="modal-body">
        <p style="font-size: 11px; color: #888; border-bottom: 1px dashed #444; padding-bottom: 10px;">Dikirim pada: <span id="memoModalDate"></span></p>
        <div id="memoModalBody" style="margin-top: 15px; line-height: 1.6; color: #ddd; word-wrap: break-word; font-size: 13px;">
            Isi pesan...
        </div>
      </div>
      <div class="modal-footer" style="border-top: 1px solid #333; text-align: center;">
        <button type="button" class="btn btn-default" data-dismiss="modal" style="width: 100%;">Tutup Pesan</button>
      </div>
    </div>
  </div>
</div>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('script'); ?>
<script>
    var isClickTab = false;
    function clickTab(tab) {
        if (isClickTab) return;
        isClickTab = true;
        location.href = tab;
    }
    
    var submit = 0;
    function CheckRepeat() {
        if (++submit > 1) { return false; }
        return true;
    }

    // Mengatur Action (Read / Delete) sebelum submit form
    function setAction(actionStr) {
        $('#action_type').val(actionStr);
        return true;
    }

    // Fungsi membuka modal untuk membaca memo
    function openMemoModal(judul, tanggal, pesan) {
        $('#memoModalTitle').text(judul);
        $('#memoModalDate').text(tanggal);
        // Memasukkan format HTML (pesan yang berisi <br>, <b>, dll) ke dalam modal
        $('#memoModalBody').html(pesan); 
        $('#readMemoModal').modal('show');
    }

    // Centang Semua
    function ClickCheckbox(obj) {
        var isChecked = obj.is(':checked');
        $(".memo-chk").each(function () {
            $(this).prop('checked', isChecked);
        });
        UpdateCheckbox();
    }

    // Menampung ID checkbox yang dicentang ke input hidden
    function UpdateCheckbox() {
        var checkboxStr = "";
        $(".memo-chk:checked").each(function () {
            if ($(this).attr("name") != null) {
                if (checkboxStr != "") checkboxStr += "|";
                checkboxStr += $(this).attr("name"); // Mengambil ID Memo dari nama checkbox
            }
        });
        document.getElementById("MainContent_HiddenField2").value = checkboxStr;
    }

    function CheckRead() {
        if (document.getElementById("MainContent_HiddenField2").value == "") {
            alert("Pilih setidaknya satu pesan terlebih dahulu.");
            submit = 0; // Reset submit lock
            return false;
        }
        return true;
    }

    function ConfirmDelete() {
        if (document.getElementById("MainContent_HiddenField2").value == "") {
            alert("Pilih setidaknya satu pesan yang ingin dihapus.");
            submit = 0;
            return false;
        }
        var confirmAct = confirm("Apakah Anda yakin ingin menghapus pesan yang dipilih?");
        if(!confirmAct) submit = 0;
        return confirmAct;
    }
</script>
<?php $__env->stopPush(); ?>
<?php echo $__env->make('frontend.mobile.pages.account.layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /www/wwwroot/website/sewa/dragon158/resources/views/frontend/mobile/pages/account/pages/memo.blade.php ENDPATH**/ ?>