<?php
if (session_status() === PHP_SESSION_NONE) {
    session_start();
}

$editor_type = $_SESSION['editor_type'] ?? '';
$editor_id   = isset($_SESSION['editor_id']) ? (int)$_SESSION['editor_id'] : 0;

$editor_name = '';
if (function_exists('getEditorName') && $editor_id > 0) {
    $editor_name = trim((string)getEditorName($editor_id));
}

$type_labels = [
    'superadmin' => 'Super Administrator',
    'admin'      => 'Administrator',
    'editor'     => 'Editor',
    'reader'     => 'Reader',
];
$type_label = $type_labels[$editor_type] ?? '';

$ed_site_name = isset($site_name) && $site_name !== '' ? $site_name : 'Green Submissions';
?><!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Editorial Suite · <?= htmlspecialchars($ed_site_name, ENT_QUOTES, 'UTF-8') ?></title>
  <link href="../styles.css" rel="stylesheet">
</head>
<body class="editor-body">

<header class="editor-head">
  <div class="editor-head__inner">
    <div class="editor-mast">
      <div class="editor-mast__kicker">Editorial Suite</div>
      <a class="editor-mast__title" href="editors-main.php"><?= htmlspecialchars($ed_site_name, ENT_QUOTES, 'UTF-8') ?></a>
    </div>
    <?php if ($editor_name !== '' || $type_label !== ''): ?>
      <div class="editor-mast__user">
        <?php if ($editor_name !== ''): ?>
          <span class="editor-mast__user-name"><?= htmlspecialchars($editor_name, ENT_QUOTES, 'UTF-8') ?></span><br>
        <?php endif; ?>
        <?php if ($type_label !== ''): ?>
          <span class="editor-mast__user-role"><?= htmlspecialchars($type_label, ENT_QUOTES, 'UTF-8') ?></span>
        <?php endif; ?>
        <a href="login.php?logout">Sign out</a>
      </div>
    <?php endif; ?>
  </div>
</header>

<main class="editor-main">
