<?php

namespace App\Cells;

class NotificationCell
{
    public function render()
    {
        $db = \Config\Database::connect();
        $userId = session()->get('id');

        if (!$userId) return '';

        $count = $db->table('notifikasi')
            ->where('user_id', $userId)
            ->where('is_read', 0)
            ->countAllResults();

        $notif = $db->table('notifikasi')
            ->where('user_id', $userId)
            ->where('is_read', 0)
            ->orderBy('created_at', 'DESC')
            ->select('judul,pesan,created_at')
            ->limit(10)
            ->get()->getResultArray();

        return view('components/notification_cell', ['notif' => $notif, 'count' => $count]);
    }
}
