<?php

use MintyPHP\Http\Request;
use MintyPHP\Router;
use MintyPHP\Session;
use MintyPHP\Support\Flash;

$target = Request::safeReturnTarget(requestInput()->bodyAll()['return'] ?? '');
$errorBag = formErrors();

if (requestInput()->method() !== 'POST') {
    Router::redirect($target);
}

if (!Session::checkCsrfToken()) {
    $errorBag->addGlobal(t('Form expired, please try again'));
    flashFormErrors($errorBag, null, 'flash_dismiss');
    Router::redirect($target);
}

$flashId = isset($id) ? trim((string) $id) : '';
if ($flashId !== '') {
    Flash::dismiss($flashId);
}
Router::redirect($target);
