<?php

use Snaatch\Typo3\Backend\FilesControlContainer;
use TYPO3\CMS\Core\Imaging\IconProvider\SvgIconProvider;
use TYPO3\CMS\Core\Imaging\IconRegistry;
use TYPO3\CMS\Core\Information\Typo3Version;
use TYPO3\CMS\Core\Log\LogManager;
use TYPO3\CMS\Core\Utility\GeneralUtility;

defined('TYPO3') or die();

if (!defined('TYPO3_EXT_NUM_SNAATCH')) {
  define('TYPO3_EXT_NUM_SNAATCH', 1754937800);
}

$GLOBALS['TYPO3_CONF_VARS']['SYS']['locallangXMLOverride']['de']['EXT:snaatch_typo3/Resources/Private/Language/locallang_be.xlf'][] = 'EXT:snaatch_typo3/Resources/Private/Language/de.locallang_be.xlf';


$version = GeneralUtility::makeInstance(Typo3Version::class)->getMajorVersion();

if ($version < 12) {
    GeneralUtility::makeInstance(LogManager::class)
        ->getLogger('snaatch_typo3')
        ->critical('The snaatch extension is not compatible with TYPO3 v' . $version . '. Please upgrade to TYPO3 v12 or newer.');
    die();
}

if ($version == 12) {
    $GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'][TYPO3_EXT_NUM_SNAATCH] = [
        'nodeName' => 'file',
        'priority' => 55,
        'class' => FilesControlContainer::class,
    ];
}

// Add the icon for the button
$iconRegistry = GeneralUtility::makeInstance(IconRegistry::class);
$iconRegistry->registerIcon(
    'actions-snaatch-show-modal',
    SvgIconProvider::class,
    ['source' => 'EXT:snaatch_typo3/Resources/Public/Icons/Extension.svg']
);
unset($iconRegistry);
