<?php
if (class_exists('Moto\System\PluginManager', false) && Moto\System\PluginManager::isActivated('moto_team@advanced_contact_form')) {
    if (method_exists('Moto\System', 'removeInjector')) {
        Moto\System::removeInjector('@plugins/moto_team/advanced_contact_form/inject.php');
    }

    return;
}
try {
    if (class_exists('Moto\System\PluginManager', false) && method_exists('Moto\System\PluginManager', 'activate') && method_exists('Moto\System\PluginManager', 'bootPlugin')) {
        Moto\System\PluginManager::activate('moto_team@advanced_contact_form');
        Moto\System\PluginManager::bootPlugin('moto_team@advanced_contact_form');

        return;
    }
} catch (\Exception $e) {
}

Moto\System\Widgets\Factory::addWidget(array(
    'name' => 'moto_team@advanced_contact_form',
    'renderClass' => 'MotoPlugin\\MotoTeam\\AdvancedContactForm\\Widget',
    'renderFile' => '@plugins/moto_team/advanced_contact_form/library/Widget.php',
));

Moto\Json\Server::getInstance()->assignClass('MotoPlugin\MotoTeam\AdvancedContactForm\Service', 'MotoTeam.AdvancedContactForm');

Moto\Hook::on('application.plugins', function ($event, $value) {
    $value[] = 'moto_team@advanced_contact_form.backend';
    return $value;
});

Moto\Hook::on('render.admin.head.top', function ($event, $value) {
    $twig = Moto\Render::getInstance();
    $motoAsset = $twig->getExtension('motoAsset');
    $value .= $motoAsset->assetJavaScript('@plugins/moto_team/advanced_contact_form/js/backend.min.js');
    $value .= $motoAsset->assetJavaScript('@plugins/moto_team/advanced_contact_form/js/templates.min.js');
    $value .= $motoAsset->assetJavaScript('@plugins/moto_team/advanced_contact_form/js/translations/en_US.min.js');
    $value .= $motoAsset->assetStyleSheet('@plugins/moto_team/advanced_contact_form/css/backend.min.css');
    return $value;
});

Moto\Hook::on('website.plugins', function ($event, $value) {
    $value[] = 'moto_team@advanced_contact_form.frontend';
    return $value;
});

Moto\Hook::on('website_head_bottom', function ($event, $value) {
    $twig = Moto\Render::getInstance();
    $motoAsset = $twig->getExtension('motoAsset');

    if (Moto\System\Request::getQuery('mode') == 'preview') {
        $value .= $motoAsset->assetStyleSheet('@plugins/moto_team/advanced_contact_form/css/editor.min.css');
    }

    return $value;
});

if (Moto\System\Request::getQuery('mode') != 'preview') {
    Moto\Hook::on('website_body_bottom', function ($event, $value) {
        $twig = Moto\Render::getInstance();
        $motoAsset = $twig->getExtension('motoAsset');
        $value .= $motoAsset->assetJavaScript('@plugins/moto_team/advanced_contact_form/js/frontend.min.js');
        return $value;
    });
}
