<?php

declare(strict_types=1);

/**
 * @param array<string, mixed> $currentUser
 * @param array<string, mixed> $options
 */
function myronRenderPublicShellHeader(array $currentUser, array $options = []): void
{
    $manageSiteHref = trim((string) ($options['manageSiteHref'] ?? myronBuildAdminUrl('dashboard')));
    $manageSiteLabel = trim((string) ($options['manageSiteLabel'] ?? 'Manage Site'));
    $utilityPrimary = is_array($options['utilityPrimary'] ?? null)
        ? $options['utilityPrimary']
        : myronPublicShellUtilityPrimary($currentUser);
    $logoutReturnTo = myronSanitizePublicReturn((string) ($options['logoutReturnTo'] ?? ($_SERVER['REQUEST_URI'] ?? '')))
        ?? myronBuildPublicPageUrl('/');

    ?>
    <div class="mc-public-shell">
      <?php myronRenderAuthenticatedUtilityChrome($currentUser, [
          'context' => 'public',
          'centerAction' => [
              'href' => $manageSiteHref,
              'label' => $manageSiteLabel,
              'className' => 'mc-public-shell__manage',
          ],
          'utilityPrimary' => $utilityPrimary,
          'showUpdateNotice' => (bool) ($options['showUpdateNotice'] ?? true),
          'logoutReturnTo' => $logoutReturnTo,
      ]); ?>
      <?php myronRenderFlashToastRegion(null, ['shellOffset' => true]); ?>
    </div>
    <?php
}

/**
 * @param array<string, mixed> $currentUser
 * @return array<string, string>
 */
function myronPublicShellUtilityPrimary(array $currentUser): array
{
    if (!myronUserCanManageContent($currentUser)) {
        return [];
    }

    return [
        'href' => myronBuildAdminUrl('content.pageEditor', ['mode' => 'create']),
        'label' => 'Create page',
        'title' => 'Create page',
        'icon' => 'plus-lg',
    ];
}
