<?php

use MintyPHP\Buffer;
use MintyPHP\Support\Flash;
use MintyPHP\Support\Guard;
use MintyPHP\Router;
use MintyPHP\Service\Access\PermissionService;
use MintyPHP\Service\Mail\MailServicesFactory;

Guard::requireLogin();
Guard::requirePermission(PermissionService::MAIL_LOG_VIEW);

$currentUserId = (int) ($_SESSION['user']['id'] ?? 0);
if ($currentUserId > 0) {
    permissionGateway()->getUserPermissions($currentUserId);
}

$mailLogId = (int) ($id ?? 0);
$mailLogService = (new MailServicesFactory())->createMailLogService();
$mailLog = $mailLogId > 0 ? $mailLogService->find($mailLogId) : null;
if (!$mailLog) {
    Flash::error('Mail log not found', 'admin/mail-log', 'mail_log_not_found');
    Router::redirect('admin/mail-log');
}

Buffer::set('title', t('View mail log'));
