<?php

namespace Bdp\Modules\EventParticipants\Controllers;

use function Bdp\Modules\EventParticipants\Views\registrationForm;

class EventSignupPageController
{
    public static function print_signup_page($content) : string {
		// Der zu ersetzende String
		$pattern = '/{{event-(\d+)}}/';

		if (preg_match($pattern, $content, $matches)) {
			if (isset($_POST['eventId'])) {
				$content = preg_replace($pattern,  ParticipationSignupController::saveRegistration($_POST), $content);
			} else {
				$eventId = $matches[1];
                $url = str_replace(get_site_url(), '', get_permalink());
				$content = preg_replace( $pattern, registrationForm( $eventId, $url ), $content );
			}
		}
		return $content;
	}
}