<?php
use Orchard\Service\SegmentAnalyticsTracking;
use Orchard\Feature\Feature;
use Orchard\FeatureFlags\FeatureService;
use Orchard\FeatureFlags\Context\AccountContext;

$sessionData = new Zend_Session_Namespace('Alw');
$vendorId = $sessionData->S_VENDOR_ID;
$alwBannerDisplay = Feature::isEnabled('alw_banner_display', 'enabled');

$alwCxt = AccountContext::fromLegacy((string)$sessionData->S_VEND_CONTACT_ID, 'alw', $sessionData->S_VENDOR_ID);
$logger = Zend_Registry::get('applicationLoggerWS');
$owsFeatureClient = new FeatureService($logger);
$isBrandingEnabled = $owsFeatureClient->isFeatureVariantActive('orchard_suite_use_branding', 'enabled', $alwCxt);
$isColorV2Enabled = $owsFeatureClient->isFeatureVariantActive('workstation_solfege_color_scheme_v2', 'enabled', $alwCxt);
$loadImage = new Alw_View_Helper_Loadingimage();
$faviconImagePath = $loadImage->getCdnImagePath('images/icons/favicon.ico');

echo $this->partial('partials/auth0-session-keepalive.phtml', [
    'configs' => yaml_parse_file(APPLICATION_PATH . '/configs/auth0.yml')
]);
?>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta charset="utf-8">
    <link rel="shortcut icon" href="<? echo $faviconImagePath ?>" type="image/x-icon">
    <title>The Orchard</title>
    <?php echo $this->headLink(); ?>
    <link href="https://fonts.googleapis.com/css?family=Rubik:400,500" media="screen" rel="stylesheet" type="text/css">
    <?php if ($alwBannerDisplay) { ?>
        <?php
            $loadjs = new Zend_View_Helper_loadjs();
            echo $this->headScript()->appendFile($loadjs->getCdnJsPath('jquery-1.8.2.min.js', 'workstation')); ?>
        <script type="text/javascript" src="/scripts/alw/top-banner.js"></script>
    <?php }

    echo $this->partial('partials/segment-analytics.phtml', array(
        'configs' => SegmentAnalyticsTracking::getTraitsFromSession($_SESSION, 'workstation')
    ));
    ?>
</head>
<body class="<?php echo ($isBrandingEnabled ? 'branded' : '') .($isColorV2Enabled ? ' SuiteColorSchemeV2' : '') ?>">
<?php
    echo $this->partial('partials/subaccount_impersonation_banner.phtml', ['session', $_SESSION]);
?>
<noscript>Javascript appears to be turned off. In order to use this page, you must have it turned on.</noscript>
<script type="text/json" id="appRoot">
    <?php echo json_encode($this->appRoot); ?>
</script>
<script type="text/json" id="features">
    <?php echo json_encode($this->features); ?>
</script>
<script type="text/json" id="user_data">
    <?php echo json_encode($this->user); ?>
</script>
<script type="text/json" id="i18n">
    <?php echo json_encode($this->i18n); ?>
</script>
<?php if ($this->grassTokenData) { ?>
    <script type="text/json" id="grass_token_data">
        <?php echo json_encode($this->grassTokenData) ?>
    </script>
<?php }
    echo $this->render('_header_redesign.phtml');
    echo $this->render('_chaplin_container.phtml');
    echo $this->render('_footer_redesign.phtml');
    echo $this->bottomScripts() . "\n";
?>
</body>
</html>
