<?php

use PHPMailer\PHPMailer\PHPMailer;

class Utils {
	public static bool $DEBUG = false;

    public static string $base_url = "/";
    public static string $url = "https://www.sierunion.com/";

    public static string $mail_sender = "iedutu@gmail.com";
    public static string $mail_sender_name = "sierunion.com mailbot";
    public static string $mail_recipient = "cristian.ungureanu@gmail.com";
    // public static string $mail_recipient = "contact@mariuspitigoi.ro";

    public static int $team_members = 3;
    public static string $HASH = 'sha256';
    public static string $DATETIME_FORMAT = 'Y-m-d H:i:s';
    public static array $eu_language_codes = [
/*
    'bg', // Bulgarian
    'cs', // Czech
    'da', // Danish
    'de', // German
    'el', // Greek
*/
    'en', // English
/*
    'es', // Spanish
    'et', // Estonian
    'fi', // Finnish
    'fr', // French
    'ga', // Irish
    'hr', // Croatian
    'hu', // Hungarian
    'it', // Italian
    'lt', // Lithuanian
    'lv', // Latvian
    'mt', // Maltese
    'nl', // Dutch
    'pl', // Polish
    'pt', // Portuguese
*/
    'ro', // Romanian
/*
    'sk', // Slovak
    'sl', // Slovenian
    'sv' // Swedish
*/
    ];

    public static array $languages = array(
            'bg' => 'Български',
            'cs' => 'Čeština',
            'da' => 'Dansk',
            'de' => 'Deutsch',
            'el' => 'Ελληνικά',
            'en' => 'English',
            'es' => 'Español',
            'et' => 'Eesti',
            'fi' => 'Suomi',
            'fr' => 'Français',
            'ga' => 'Gaeilge',
            'hr' => 'Hrvatski',
            'hu' => 'Magyar',
            'it' => 'Italiano',
            'lt' => 'Lietuvių',
            'lv' => 'Latviešu',
            'mt' => 'Malti',
            'nl' => 'Nederlands',
            'pl' => 'Polski',
            'pt' => 'Português',
            'ro' => 'Română',
            'sk' => 'Slovenčina',
            'sl' => 'Slovenščina',
            'sv' => 'Svenska'
    );

    public static array $flags = array(
        'bg' => 'bulgaria.svg',
        'cs' => 'czech-republic.svg',
        'da' => 'denmark.svg',
        'de' => 'germany.svg',
        'el' => 'greece.svg',
        'en' => 'united-kingdom.svg',
        'es' => 'spain.svg',
        'et' => 'estonia.svg',
        'fi' => 'finland.svg',
        'fr' => 'france.svg',
        'ga' => 'ireland.svg',
        'hr' => 'croatia.svg',
        'hu' => 'hungary.svg',
        'it' => 'italy.svg',
        'lt' => 'lithuania.svg',
        'lv' => 'latvia.svg',
        'mt' => 'malta.svg',
        'nl' => 'netherlands.svg',
        'pl' => 'poland.svg',
        'pt' => 'portugal.svg',
        'ro' => 'romania.svg',
        'sk' => 'slovakia.svg',
        'sl' => 'slovenia.svg',
        'sv' => 'sweden.svg'
    );

	public static function isPast($time): bool
    {
		return (strtotime($time) < time());
	}

	public static function isFuture($time): bool
    {
		return (strtotime($time) > time());
	}

	public static function logout(): void
    {
		session_destroy();
		$_SESSION = array();
	}

    /**
     * @throws \PHPMailer\PHPMailer\Exception
     */
    public static function sendEmail($message): void
    {
		if (!empty($message["email"])) {
			$mail = new PHPMailer();
            include "mail-settings.php";

			$mail->setFrom ( Utils::$mail_sender, Utils::$mail_sender_name );
			$mail->addReplyTo ( $message["email"], $message["name"] );
			$mail->Subject = $message["subject"];
			$mail->addAddress ($message["recipient"]);

			ob_start ();
			include_once ("assets/templates/email.html");
			$body = ob_get_clean ();
			$mail->msgHTML ( $body, dirname ( __FILE__ ), true ); // Create message bodies and embed images
		                                                      
			// send the message, check for errors
			if (! $mail->send ()) {
				error_log('Error sending e-mail.');
			}
		}
	}

}