<?php

declare(strict_types=1);

require_once dirname(__DIR__, 3) . '/system/bootstrap.php';

$currentUser = myronRequireDesignAccess();
$fragment = myronLoadLegacyWorkspaceFragment(dirname(__DIR__, 2) . '/specimens/design/tokens.html');

$fragment = str_replace(
    '<h1 class="mc-workspace__title">Tokens</h1>',
    '<h1 class="mc-workspace__title">Primitives</h1>',
    $fragment
);
$fragment = str_replace(
    'The Style Guide branch now owns token reference, templates, and design-system management under Design. This surface is focused on the token layer only.',
    'Low-level reference gallery for primitives, controls, CMS primitives, composites, patterns, and extension packs. This is the observable assembly layer between atoms and larger component systems.',
    $fragment
);
$fragment = str_replace(
    'Style guide reference navigation',
    'Primitives reference navigation',
    $fragment
);
$fragment = str_replace(
    '<span class="sg-nav__section-label">Components</span>',
    '<span class="sg-nav__section-label">Primitives</span>',
    $fragment
);

$patterns = [
    '~\\s*<li><span class="sg-nav__section-label">Reference</span></li>\\s*<li class="sg-nav__item"><a class="sg-nav__link" href="#tokens">Tokens</a></li>\\s*<li class="sg-nav__item"><a class="sg-nav__link" href="#states">States</a></li>~s',
    '~\\s*<section class="sg-section" id="tokens">.*?</section>~s',
    '~\\s*<section class="sg-section" id="states">.*?</section>~s',
];

foreach ($patterns as $pattern) {
    $updated = preg_replace($pattern, '', $fragment, 1);
    if (!is_string($updated)) {
        throw new RuntimeException('Unable to compose the Primitives reference surface from the governed specimen source.');
    }

    $fragment = $updated;
}

myronRenderAdminShellStart($currentUser, [
    'title' => 'Primitives',
    'titleContext' => 'Primitives',
    'activeItem' => 'primitives',
]);
?>
<div class="mc-page-canvas mc-page-canvas--site">
<?php echo $fragment; ?>
</div>
<?php myronRenderAdminShellEnd(); ?>
