<?php
/*
 * Software Name: Eorisis Pixels
 * Software URI: https://eorisis.com/shop/software/joomla/pixels
 * Author: Eorisis
 * Author URI: https://eorisis.com
 * Copyright: Copyright (C) 2011-2025 EORISIS. All Rights Reserved.
 * License: GNU General Public License version 2; See https://eorisis.com/gpl
 * Terms of Service: https://eorisis.com/tos
 */
namespace com_eorisis_pixels\framework\lib\core\model;
\defined('_JEXEC') or die;

use com_eorisis_pixels\framework\lib\core\app\config as app_config;
use com_eorisis_pixels\framework\lib\core\model\strip;
use com_eorisis_pixels\framework\lib\core\cms\session as cms_session;

class notifications
{
	private static $notifications = [];

	// --------------------------------------------------

	public function __construct() {}

	// --------------------------------------------------

	public static function add(string $message, string $type, bool $instant = false, bool $show_close = true) // void
	{
		$result = [
			'message' => strip::tags($message, ['<b>','<h3>','<a>','<br>','<br />']),
			'type' => '',
			'show_close' => $show_close
		];

		switch ($type)
		{
			case 'success':
			case 'warning':
			case 'error':
			case 'note':
				$result['type'] = $type;
				break;

			// notice
			default:
				$result['type'] = 'notice';
		}

		if ($instant)
		{
			self::$notifications[] = $result;
			return;
		}

		$notifications = cms_session::get('notifications', [], app_config::COMPONENT_ELEMENT);
		$notifications[] = $result;
		cms_session::set('notifications', $notifications, app_config::COMPONENT_ELEMENT);
	}

	// --------------------------------------------------

	public static function get_instant() : array
	{
		return self::$notifications;
	}
}
