<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Dashboard extends CI_Controller {

    function __construct(){
        parent::__construct();
        if(!$this->session->userdata('login')){
            redirect('login');
        }
        $this->load->model('Dashboard_model');
        $this->load->model('Peminjaman_model'); 
    }

    public function index()
    {
        // Fetch data untuk setiap card
        $data['anggota'] = $this->Dashboard_model->jumlah('anggota');
        $data['buku'] = $this->Dashboard_model->jumlah('buku');
        $data['kategori'] = $this->Dashboard_model->jumlah('kategori');
        
        // Debugging: Periksa jumlah yang sedang dipinjam
        $data['dipinjam'] = $this->Dashboard_model->dipinjam();
        echo "Jumlah Sedang Dipinjam: " . $data['dipinjam'];  // Debug output
        
        $data['kembali'] = $this->Dashboard_model->dikembalikan();
        $data['pengunjung'] = $this->Dashboard_model->jumlah('pengunjung');
        $data['grafik'] = $this->Dashboard_model->grafik_pengunjung();
        $data['notif_count'] = $this->Peminjaman_model->count_notifikasi();

        // Load view dan kirimkan data
        $this->load->view('dashboard', $data);
    }
}

