<?php
use TYPO3\CMS\Extbase\Utility\ExtensionUtility;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;

defined('TYPO3') or die();

ExtensionUtility::registerPlugin(
    'IgReservations',
    'CalendarList',
    'Reservations: List of Calendars'
);

$publicCalendarCtype = ExtensionUtility::registerPlugin(
    'IgReservations',
    'PublicCalendar',
    'Reservations: Public Calendar'
);

ExtensionUtility::registerPlugin(
    'IgReservations',
    'Ajax',
    'Reservations: Ajax'
);

ExtensionUtility::registerPlugin(
    'IgReservations',
    'EventTodo',
    'Reservations: Events Approval List'
);

ExtensionUtility::registerPlugin(
    'IgReservations',
    'Overview',
    'Reservations: Overview'
);

$eventListCtype = ExtensionUtility::registerPlugin(
    'IgReservations',
    'EventList',
    'Reservations: Event List'
);

ExtensionUtility::registerPlugin(
    'IgReservations',
    'FeUserManagement',
    'Reservations: User Management'
);

ExtensionUtility::registerPlugin(
    'IgReservations',
    'LocationManagement',
    'Reservations: Location Management'
);

$locationListCtype = ExtensionUtility::registerPlugin(
    'IgReservations',
    'LocationList',
    'Reservations: Location List'
);

ExtensionUtility::registerPlugin(
    'IgReservations',
    'MyReservations',
    'Reservations: My Reservations'
);

ExtensionUtility::registerPlugin(
    'IgReservations',
    'Alarm',
    'Reservations: Alarm'
);

ExtensionUtility::registerPlugin(
    'IgReservations',
    'Statistics',
    'Reservations: Statistics'
);

// FlexForms
$flexformMapping = [
    $publicCalendarCtype => 'FILE:EXT:ig_reservations/Configuration/FlexForms/flexform_publiccalendar.xml',
    $eventListCtype => 'FILE:EXT:ig_reservations/Configuration/FlexForms/flexform_eventlist.xml',
    $locationListCtype => 'FILE:EXT:ig_reservations/Configuration/FlexForms/flexform_locationlist.xml',
];

foreach ($flexformMapping as $ctypeKey => $flexFormPath) {
    ExtensionManagementUtility::addToAllTCAtypes(
        'tt_content',
        '--div--;Plugin,pi_flexform,',
        $ctypeKey,
        'after:subheader',
    );
    ExtensionManagementUtility::addPiFlexFormValue(
        '*',
        $flexFormPath,
        $ctypeKey
    );
}
