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

/**
 * Admin / Dashboard — overview of the platform: stats, recent activity,
 * pending engagement items.
 */
#[\AllowDynamicProperties]
class Dashboard extends Admin_Controller {

	public function __construct()
	{
		parent::__construct();
		$this->load->model(array(
			'portfolio_model', 'talent_model', 'event_model',
			'application_model', 'inquiry_model', 'ticket_model',
			'blog_model', 'partner_model',
		));
	}

	public function index()
	{
		// Headline counts
		$stats = array(
			'portfolio' => $this->portfolio_model->count_all(),
			'talent'    => $this->talent_model->count_all(),
			'events'    => $this->event_model->count_all(),
			'partners'  => $this->partner_model->count_all(),
		);

		// Engagement pipeline
		$app_counts     = $this->application_model->status_counts();
		$inquiry_counts = $this->inquiry_model->status_counts();

		// Revenue from ticketing
		$revenue = $this->ticket_model->total_revenue();

		$data = array(
			'page_title'  => 'Dashboard',
			'stats'       => $stats,
			'app_counts'  => $app_counts,
			'inq_counts'  => $inquiry_counts,
			'revenue'     => $revenue,
			'pending_apps'=> $this->application_model->filtered('pending', NULL, 5),
			'new_inq'     => $this->inquiry_model->filtered(NULL, 'new', NULL, 5),
			'recent_acts' => $this->activity_model->recent(8),
			'upcoming'    => $this->event_model->upcoming(4),
			'nav_counts'  => array(
				'applications' => $app_counts['pending'],
				'inquiries'    => $inquiry_counts['new'],
			),
		);

		$this->render('dashboard/index', $data);
	}
}
