<?php
use Orchard\Feature\FeatureUtils;
use Orchard\Service\GrassAuth;
use Orchard\Service\Ows\Grass as OwsGrass;
use Orchard\Service\StaticAsset as StaticAssetService;

// Get static asset locations.
$staticAssetService = new StaticAssetService($this->awsConfig);

$frontendDistroAppName = 'frontend-distribution-oa-components';

$manifestData = $staticAssetService->loadStaticAssetsManifestJson($frontendDistroAppName, 'manifest.json');
$version = $staticAssetService->getStaticAssetVersionFromJson($manifestData);
$projectManagerCss = $staticAssetService->getStaticAssetUrl(
    $frontendDistroAppName,
    $version,
    'oa-components.css'
);
$frontendDistroCommonScriptsFile = $staticAssetService->getStaticAssetUrl(
    $frontendDistroAppName,
    $version,
    'commons.bundle.js'
);
$frontendDistroLoadUserFeaturesBeforeScriptsFile = $staticAssetService->getStaticAssetUrl(
    $frontendDistroAppName,
    $version,
    'load-user-features-before-scripts.bundle.js'
);
$frontendDistroMarketingHighlightsScriptsFile = $staticAssetService->getStaticAssetUrl(
    $frontendDistroAppName,
    $version,
    'oa-marketing-highlights.bundle.js'
);

// Grab the GRASS session.
$grassAuth = new GrassAuth(new OwsGrass(logger: \Zend_Registry::get('applicationLoggerOA')));
$grassRefreshUrl = OwsGrass::OA_REFRESH_URI;
$grassBaseUrl = OwsGrass::PROXY_PATH;
$grassSession = $grassAuth->fetchGrassToken()->getJSTokenManagerServiceFormat($grassRefreshUrl, $grassBaseUrl);

$bundleOptions = array(
    'grassSession' => $grassSession,
    'userFeatures' => FeatureUtils::toArray(array('user' => array('username' => $_SESSION['S_USERID']))),
    'userId'=> $_SESSION['S_USERID']
);
?>

<div id="oa-marketing-highlights"></div>

<link type="text/css" rel="stylesheet" href="/css/global-redesign.css"/>
<link type="text/css" rel="stylesheet" href="<?=$projectManagerCss?>"/>
<script type="text/javascript" src="<?=$frontendDistroCommonScriptsFile?>"></script>
<script type="text/javascript" src="<?=$frontendDistroLoadUserFeaturesBeforeScriptsFile?>"></script>
<script type="text/javascript">
    var marketingHighlightsRootElement = document.getElementById('oa-marketing-highlights');

    window.loadUserFeaturesBeforeScripts(
        <?php echo json_encode($bundleOptions);?>,
        ['<?=$frontendDistroMarketingHighlightsScriptsFile?>'],
        function () { initOAMarketingHighlights(marketingHighlightsRootElement); }
    );
</script>
