<?php $__env->startSection('body_class', 'depositpage'); ?>

<?php $__env->startSection('content'); ?>
<div class="master-main mainContent maincontent-design2 middlebackground background-design5">
    <div class="container">
        <div class="row multi">
            <div class="col-sm-3 main-sidebar">
                <div class="main-sidebar-container sidebar-design1">
                    <ul>
                        <li><a href="/desktop/account/profile"><span class="glyphicon glyphicon-list-alt"></span>Profil</a></li>
                        <li><a href="/desktop/account/deposit"><span class="glyphicon glyphicon-transfer"></span>Depo/Withdraw</a></li>
                        <li><a href="/desktop/account/walletsummary"><span class="glyphicon glyphicon-stats"></span>Transaksi</a></li>
                        <li><a href="/desktop/account/memo"><span class="glyphicon glyphicon-bell"></span>Memo</a></li>
                        <li><a href="/desktop/account/referral"><span class="glyphicon glyphicon-tags"></span>Referral</a></li>
                        <li><a href="/desktop/account/promo"><span class="glyphicon glyphicon-thumbs-up"></span>Promosi</a></li>
                        <li><a href="https://cutt.ly/rtpsuster1" target="_blank"><span class="glyphicon glyphicon-flash"></span>RTP</a></li>
                        <li><a href="/download/apk"><span class="glyphicon glyphicon-cloud-download"></span>APK</a></li>
                        <li><a href="javascript:;" onclick="showLiveChat();"><span class="glyphicon glyphicon-user"></span>Livechat</a></li>
                    </ul>
                </div>
            </div>
            
            <div class="col-xs-12 col-sm-9 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"><?php echo e(session('success')); ?></div>
                    <?php endif; ?>
                    <?php if($errors->any()): ?>
                        <div class="alert alert-danger">
                            <ul style="margin: 0;"><?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('/desktop/account/memo')">INBOX</button>
                            <button type="button" class="btn btn-default alignbtn" onclick="clickTab('/desktop/account/memocompose')">COMPOSE</button>
                            <button type="button" class="btn btn-default alignbtn <?php echo e($isSent ? 'active' : ''); ?>" onclick="clickTab('/desktop/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 ?? 'desktop'])); ?>" 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" />

                                <table class="table table-bordered table-mailbox">
                                    <thead>
                                        <tr class="table-header-st">
                                            <th style="width: 50px; text-align: center;">
                                                <input type="checkbox" id="MainCheckbox" onclick="ClickCheckbox($(this))"/>
                                            </th>
                                            <th class="mail-msg">
                                                <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: 200px; text-align: center;">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;">
                                                    <input type="checkbox" name="<?php echo e($memo->id); ?>" class="memo-chk" onclick="UpdateCheckbox()" />
                                                </td>
                                                <td class="mail-msg">
                                                    
                                                    <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; <?php echo e($memo->status_baca == 0 ? 'font-weight: bold; color: #f3c300;' : 'color: #ccc;'); ?>">
                                                        <?php if($memo->pengirim == 'admin'): ?>
                                                            [Operator]
                                                        <?php else: ?>
                                                            [Anda]
                                                        <?php endif; ?>
                                                        <?php echo e($memo->judul); ?>

                                                    </a>
                                                    
                                                    <?php if($memo->status_baca == 0): ?>
                                                        <span class="label label-danger pull-right">NEW</span>
                                                    <?php endif; ?>
                                                </td>
                                                <td style="text-align: center;"><?php echo e(date('d-m-Y H:i:s', 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>
                            </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" role="document">
    <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;"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="memoModalTitle" style="color: #f3c300; font-weight: bold;">Judul Memo</h4>
      </div>
      <div class="modal-body">
        <p style="font-size: 12px; color: #888; border-bottom: 1px dashed #444; padding-bottom: 10px;">Tanggal: <span id="memoModalDate"></span></p>
        <div id="memoModalBody" style="margin-top: 15px; line-height: 1.6; color: #ddd; word-wrap: break-word;">
            Isi pesan...
        </div>
      </div>
      <div class="modal-footer" style="border-top: 1px solid #333;">
        <button type="button" class="btn btn-default" data-dismiss="modal">Tutup</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);
        // Menggunakan .html() agar tag format seperti <br>, <b>, dll. dirender
        $('#memoModalBody').html(pesan); 
        $('#readMemoModal').modal('show');
    }

    // Fungsi checkbox bawaan yang telah disesuaikan
    function ClickCheckbox(obj) {
        var isChecked = obj.is(':checked');
        $(".memo-chk").each(function () {
            $(this).prop('checked', isChecked);
        });
        UpdateCheckbox();
    }

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

    function CheckRead() {
        if (document.getElementById("MainContent_HiddenField2").value == "") {
            alert("Tidak ada memo yang dicentang.");
            submit = 0; // Reset submit lock
            return false;
        }
        return true;
    }

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