<?php
/**
* @package com_spmedical
* @author JoomShaper http://www.joomshaper.com
* @copyright Copyright (c) 2010 - 2025 JoomShaper
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or later
*/
// No Direct Access
defined ('_JEXEC') or die('Restricted Access');

use Joomla\CMS\Factory;
use Joomla\CMS\Uri\Uri;
use Joomla\CMS\Language\Text;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\MVC\View\HtmlView;
use Joomla\CMS\Helper\ContentHelper;
use Joomla\CMS\Toolbar\ToolbarHelper;
use Joomla\CMS\MVC\View\GenericDataException;

class SpmedicalViewDashboard extends HtmlView
{

	public function display($tpl = null)
	{

		$model = $this->getModel('Dashboard');	
		$this->canDo = ContentHelper::getActions('com_spmedical');

		// Check for errors.
		$errors = $this->get('Errors');
		if ($errors && \count($errors))
		{
			throw new GenericDataException(implode("\n", $errors), 500);
		}

		HTMLHelper::_('jquery.framework');
		$doc = Factory::getDocument();
		$doc->addScript( Uri::root(true) . '/administrator/components/com_spmedical/assets/js/Chart.min.js' );

		// get datas
		$this->specialists = $model->getSpecialists();
		$this->departments = $model->getDepartments();
		$this->appointments = $model->getAppointments();
		$this->specialistsList = $model->getSpecialistsList();
		$this->appointmentsList = $model->getAppointmentList();
		$this->addToolBar();
		parent::display($tpl);

	}

	protected function addToolBar()
	{
		ToolbarHelper::title(Text::_('COM_SPMEDICAL_PAGE_HEADING') .  Text::_('COM_SPMEDICAL_MANAGER_DASHBOARD'));
		
		if ($this->canDo->get('core.admin'))
		{
			ToolbarHelper::preferences('com_spmedical');
		}
	}

}
