<?php require 'header.php'; ?>
<div class="container-fluid" style="padding: 20px;">
    <div class="row">
        <div class="col-md-4">
            <div class="card" style="border:1px solid #ddd; padding:15px;">
                <h4>Send Note</h4>
                <select id="client_id" class="form-control">
                    <?php foreach($clients as $c): ?>
                        <option value="<?= $c['client_id'] ?>"><?= $c['username'] ?></option>
                    <?php endforeach; ?>
                </select>
                <textarea id="note_text" class="form-control mt-3" rows="4" placeholder="Message..."></textarea>
                <button onclick="sendNote()" class="btn btn-primary mt-3">Send Now</button>
            </div>
        </div>
        <div class="col-md-8">
            <div class="card" style="border:1px solid #ddd; padding:15px;">
                <h4>History</h4>
                <table class="table">
                    <thead><tr><th>User</th><th>Message</th><th>Status</th><th>Action</th></tr></thead>
                    <tbody>
                        <?php foreach($notes_history as $n): ?>
                        <tr>
                            <td><?= $n['username'] ?></td>
                            <td><?= $n['note_text'] ?></td>
                            <td><?= $n['is_seen'] ? 'SEEN' : 'PENDING' ?></td>
                            <td><a href="<?= site_url('admin/user-note/delete/'.$n['id']) ?>" class="btn btn-danger btn-sm">Delete</a></td>
                        </tr>
                        <?php endforeach; ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
<script>
function sendNote() {
    var cid = document.getElementById('client_id').value;
    var txt = document.getElementById('note_text').value;
    $.post('', {client_id: cid, note_text: txt}, function(res) {
        location.reload();
    });
}
</script>
<?php require 'footer.php'; ?>