<?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\Log\Log;
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
use Joomla\CMS\Uri\Uri;
use Joomla\CMS\MVC\View\HtmlView;

class SpmedicalViewAppointments extends HtmlView
{

	protected $items;
	protected $params;
	protected $layout_type;

	function display($tpl = null) {
		
		// Assign data to the view
		$app = Factory::getApplication();
		$doc = Factory::getDocument();
		$input = Factory::getApplication()->input;
		$this->params = $app->getParams();
		$menus = Factory::getApplication()->getMenu();
		$menu = $menus->getActive();
		$this->appointment_tac 		= $this->params->get('appointment_tac', 1);
		$this->appointment_tac_text = $this->params->get('appointment_tac_text', '
			I agree with the <a href="#">Terms of Use</a> and <a href="#">Privacy Policy</a> and I declare that I have read the information that is required in accordance with <a href="http://eur-lex.europa.eu/legal-content/EN/TXT/?uri=uriserv:OJ.L_.2016.119.01.0001.01.ENG&amp;toc=OJ:L:2016:119:TOC" target="_blank">Article 13 of GDPR.</a>
		');
		$this->choose_patient 		= $this->params->get('choose_patient', 0);
		$this->date_of_birth 		= $this->params->get('date_of_birth', 0);
		$this->appointments_address = $this->params->get('appointments_address', 0);
		$this->visiting_option 		= $this->params->get('visiting_option', 0);
		$this->patient_note 		= $this->params->get('patient_note', 1);
		
		if($menu) {
			//$this->params->merge($menu->params);
		}

		$doc->addScriptdeclaration('var spmedical_url="' . Uri::base() . 'index.php?option=com_spmedical";');

		$this->layout_type = str_replace('_', '-', $this->params->get('layout_type', 'default'));
		// Check for errors.
		if ($errors = $this->get('Errors') && count($errors = $this->get('Errors'))) {
			Log::add(implode('<br />', $errors), Log::WARNING, 'jerror');
			return false;
		}
		
		// Load Lessons model

		BaseDatabaseModel::addIncludePath(JPATH_SITE.'/components/com_spmedical/models');
		// Load Schedules model
		$model = BaseDatabaseModel::getInstance( 'Appointments', 'SpmedicalModel' );
		//Show Captcha or not
		$this->captcha = $this->params->get('appointment_captcha', '');

		// get Specialists
		$this->specialists = SpmedicalHelper::getSpecialists(true);
		
		// get departments
		$this->departments = SpmedicalHelper::getDepartments(true);

		parent::display($tpl);
	}

}
