Skip to content

A plugin marketplace for GitHub Copilot and other AI agents that provides Power Platform development plugins, including reusable skills, agents, and commands for building and deploying solutions.

35.0 KB
Raw Blame
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src __ATTR_CSP_IMAGE_SOURCES__; connect-src __ATTR_CSP_CONNECT_SOURCES__; style-src 'unsafe-inline'; script-src 'nonce-__ATTR_CSP_NONCE__'">
  <title>Power Pages site creation status</title>
  <style>
    :root {
      --ink: #17213a;
      --muted: #69718a;
      --cobalt: #3454d1;
      --cobalt-dark: #263fae;
      --lavender: #eee9ff;
      --pale: #f7f8fc;
      --line: #dfe3ee;
      --success: #13795b;
      --warning: #a15c00;
      --danger: #b42318;
      --white: #fff;
      --shadow: 0 30px 80px rgba(31, 42, 80, .14);
    }

    * { box-sizing: border-box; }

    body {
      margin: 0;
      min-height: 100vh;
      color: var(--ink);
      background:
        radial-gradient(circle at 84% 8%, rgba(197, 185, 255, .58), transparent 26rem),
        linear-gradient(135deg, #f3f5fb, #fafaff 55%, #f0edff);
      font-family: "Segoe UI Variable", "Segoe UI", sans-serif;
    }

    button { font: inherit; }

    .shell {
      width: min(1440px, calc(100% - 48px));
      margin: 24px auto;
      min-height: calc(100vh - 48px);
      overflow: hidden;
      border: 1px solid rgba(119, 127, 160, .2);
      border-radius: 28px;
      background: rgba(255, 255, 255, .88);
      box-shadow: var(--shadow);
      backdrop-filter: blur(20px);
    }

    .topbar {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 24px;
      padding: 18px 28px;
      border-bottom: 1px solid var(--line);
      background: rgba(255, 255, 255, .78);
    }

    .brand { display: flex; align-items: center; gap: 12px; font-weight: 650; }
    .brand-mark {
      display: block;
      width: 34px;
      height: 34px;
      object-fit: contain;
    }

    .status-badge {
      padding: 7px 11px;
      border-radius: 999px;
      color: var(--cobalt-dark);
      background: var(--lavender);
      font-size: 12px;
      font-weight: 700;
      letter-spacing: .08em;
      text-transform: uppercase;
    }

    .preview-notice {
      display: flex;
      align-items: flex-start;
      gap: 10px;
      padding: 11px 28px;
      border-bottom: 1px solid #ead9ad;
      color: #654a0b;
      background: #fff8e7;
      font-size: 13px;
      line-height: 1.45;
    }
    .preview-notice strong {
      flex: 0 0 auto;
      padding: 2px 7px;
      border-radius: 999px;
      color: #fff;
      background: #8a5a00;
      font-size: 10px;
      letter-spacing: .08em;
      text-transform: uppercase;
    }

    .layout {
      display: grid;
      grid-template-columns: minmax(360px, .86fr) minmax(480px, 1.14fr);
      min-height: calc(100vh - 121px);
    }

    .preview-pane {
      display: flex;
      flex-direction: column;
      padding: 34px;
      border-right: 1px solid var(--line);
      background: linear-gradient(150deg, #f8f7ff, #f2f5fb);
    }

    .eyebrow {
      margin: 0 0 10px;
      color: var(--cobalt);
      font-size: 12px;
      font-weight: 750;
      letter-spacing: .13em;
      text-transform: uppercase;
    }

    .template-heading {
      display: flex;
      flex-wrap: wrap;
      align-items: center;
      gap: 12px;
    }

    .template-heading h1 {
      min-width: 0;
      overflow-wrap: anywhere;
    }

    h1 {
      margin: 0;
      max-width: 700px;
      font-family: Georgia, "Times New Roman", serif;
      font-size: clamp(34px, 4vw, 58px);
      font-weight: 400;
      line-height: 1.02;
      letter-spacing: -.035em;
    }

    .lede {
      margin: 15px 0 24px;
      max-width: 560px;
      color: var(--muted);
      font-size: 16px;
      line-height: 1.55;
    }

    .preview-card {
      position: relative;
      flex: none;
      aspect-ratio: 16 / 10;
      overflow: hidden;
      border: 1px solid #d9ddec;
      border-radius: 20px;
      background: #e9e5ff;
      box-shadow: 0 24px 50px rgba(60, 66, 110, .16);
    }

    .preview-card img {
      display: block;
      width: 100%;
      height: 100%;
      object-fit: contain;
      object-position: top;
      transition: opacity .25s ease, transform .4s ease;
    }

    .preview-card.mobile img {
      width: auto;
      max-width: 72%;
      margin: 0 auto;
      object-fit: contain;
    }

    .slide-controls {
      display: flex;
      flex-wrap: wrap;
      justify-content: center;
      gap: 8px;
      padding-top: 14px;
    }

    .slide-controls button {
      display: inline-flex;
      align-items: center;
      gap: 7px;
      max-width: 100%;
      overflow-wrap: anywhere;
      padding: 7px 10px;
      border: 1px solid transparent;
      border-radius: 999px;
      color: var(--muted);
      background: transparent;
      cursor: pointer;
      font-size: 12px;
      font-weight: 700;
    }

    .slide-controls button::before {
      content: "";
      width: 7px;
      height: 7px;
      border: 1.5px solid currentColor;
      border-radius: 50%;
    }

    .slide-controls button.active {
      border-color: #d9d5ee;
      color: var(--cobalt-dark);
      background: var(--white);
    }

    .slide-controls button.active::before { border-color: var(--cobalt); background: var(--cobalt); }

    .preview-controls {
      display: flex;
      justify-content: space-between;
      align-items: center;
      gap: 16px;
      padding-top: 18px;
    }

    .segmented {
      display: inline-flex;
      padding: 4px;
      border: 1px solid var(--line);
      border-radius: 12px;
      background: var(--white);
    }

    .segmented[hidden] { display: none; }

    .segmented button, .ghost {
      border: 0;
      border-radius: 8px;
      color: var(--muted);
      background: transparent;
      cursor: pointer;
      padding: 8px 13px;
      font-weight: 650;
    }

    .segmented button.active {
      color: var(--white);
      background: var(--cobalt);
    }

    .template-meta { color: var(--muted); font-size: 13px; text-align: right; }
    .template-meta-secondary { font-size: 12px; }

    .template-info {
      margin-top: 22px;
      padding: 19px 20px;
      border: 1px solid var(--line);
      border-radius: 16px;
      background: rgba(255,255,255,.75);
    }

    .template-info h2 { margin: 0 0 8px; font-size: 16px; }
    .template-category {
      display: inline-flex;
      flex: none;
      margin: 0;
      padding: 4px 9px;
      border: 1px solid #d8d0f0;
      border-radius: 999px;
      color: var(--cobalt-dark);
      background: var(--lavender);
      font-size: 10px;
      font-weight: 800;
      letter-spacing: .08em;
      text-transform: uppercase;
    }
    .template-info > p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
    .feature-list {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 8px 14px;
      margin: 14px 0;
      padding: 0;
      list-style: none;
    }
    .feature-list li {
      position: relative;
      padding-left: 17px;
      color: var(--ink);
      font-size: 12px;
      line-height: 1.4;
    }
    .feature-list li::before {
      content: "✓";
      position: absolute;
      left: 0;
      color: var(--success);
      font-weight: 800;
    }
    .template-notes { display: grid; gap: 7px; }
    .template-note {
      padding: 8px 10px;
      border-radius: 9px;
      color: #594100;
      background: #fff6d9;
      font-size: 11px;
      line-height: 1.4;
    }
    .template-note strong { color: #3f3100; }

    .status-pane {
      display: flex;
      flex-direction: column;
      padding: 40px 48px 32px;
    }

    .site-identity {
      display: grid;
      grid-template-columns: 1fr auto;
      gap: 24px;
      align-items: start;
      padding-bottom: 28px;
      border-bottom: 1px solid var(--line);
    }

    .site-identity h2 { margin: 0 0 8px; font-size: 25px; letter-spacing: -.025em; }
    .site-url { color: var(--muted); font-size: 14px; }

    .state-chip {
      display: inline-flex;
      align-items: center;
      gap: 8px;
      padding: 9px 13px;
      border-radius: 999px;
      color: #2349ae;
      background: #e9efff;
      font-size: 13px;
      font-weight: 700;
    }

    .pulse {
      width: 8px;
      height: 8px;
      border-radius: 50%;
      background: currentColor;
    }
    .state-chip.awaiting-input { color: #754a00; background: #fff1c2; }
    .state-chip.failed { color: var(--danger); background: #ffebe9; }
    .state-chip.canceled { color: #5d6478; background: #eceef4; }

    .input-notice {
      display: grid;
      grid-template-columns: 34px 1fr;
      gap: 14px;
      margin-top: 22px;
      padding: 16px 18px;
      border: 1px solid #e3b341;
      border-radius: 14px;
      color: #4d3700;
      background: #fff8df;
      box-shadow: 0 12px 28px rgba(117, 74, 0, .1);
    }
    .input-notice[hidden] { display: none; }
    .input-notice-mark {
      display: grid;
      place-items: center;
      width: 30px;
      height: 30px;
      border-radius: 50%;
      color: #fff;
      background: var(--warning);
      font-weight: 800;
    }
    .input-notice h3 { margin: 0 0 6px; font-size: 16px; }
    .input-notice p { margin: 0; font-size: 13px; line-height: 1.5; }
    .input-notice-location { margin-top: 7px !important; color: #6c5000; }
    .input-notice-location strong { color: #493600; }

    .timeline { display: grid; gap: 4px; margin: 24px 0 0; padding: 0; list-style: none; }
    .step {
      position: relative;
      display: grid;
      grid-template-columns: 34px 1fr auto;
      gap: 14px;
      align-items: center;
      min-height: 58px;
      padding: 8px 10px;
      overflow: hidden;
      border: 1px solid transparent;
      border-radius: 12px;
      transition: background .25s ease, border-color .25s ease, box-shadow .25s ease;
    }

    .step.working {
      border-color: rgba(52,84,209,.45);
      background: linear-gradient(90deg, #e9e7ff, #f8f9ff);
      transform: translateX(4px);
    }
    .step.working::before {
      content: "";
      position: absolute;
      inset: 0 auto 0 0;
      width: 5px;
      background: var(--cobalt);
    }
    .step.blocked { border-color: #e3b341; background: #fffaf0; }
    .step.blocked::before {
      content: "";
      position: absolute;
      inset: 0 auto 0 0;
      width: 5px;
      background: var(--warning);
    }
    .step.canceled { border-color: #cfd3df; background: #f6f7fa; }
    .step-marker {
      display: grid;
      place-items: center;
      width: 28px;
      height: 28px;
      border: 1.5px solid #cbd1e1;
      border-radius: 50%;
      color: #8790aa;
      font-size: 12px;
      font-weight: 800;
    }

    .step.complete .step-marker { border-color: var(--success); color: var(--white); background: var(--success); }
    .step.working .step-marker {
      border-color: rgba(52,84,209,.28);
      color: transparent;
      background: var(--white);
    }
    .step.working .step-marker::after {
      content: "";
      width: 12px;
      height: 12px;
      border: 2px solid rgba(52,84,209,.22);
      border-top-color: var(--cobalt);
      border-radius: 50%;
      animation: working-indicator .85s linear infinite;
    }
    @keyframes working-indicator { to { transform: rotate(360deg); } }
    .step.blocked .step-marker { border-color: var(--warning); color: var(--white); background: var(--warning); }
    .step.error .step-marker { border-color: var(--danger); color: var(--white); background: var(--danger); }
    .step.canceled .step-marker { border-color: #7a8297; color: var(--white); background: #7a8297; }
    .step-title { font-size: 14px; font-weight: 700; }
    .step-detail { margin-top: 3px; color: var(--muted); font-size: 12px; }
    .step-state { color: var(--muted); font-size: 12px; }
    .step.working .step-state,
    .step.blocked .step-state,
    .step.error .step-state,
    .step.canceled .step-state {
      padding: 5px 8px;
      border-radius: 999px;
      color: var(--white);
      font-weight: 800;
      letter-spacing: .04em;
      text-transform: uppercase;
    }
    .step.working .step-state { background: var(--cobalt); }
    .step.blocked .step-state { background: var(--warning); }
    .step.error .step-state { background: var(--danger); }
    .step.canceled .step-state { background: #6f778c; }

    .footer {
      display: flex;
      justify-content: space-between;
      align-items: center;
      gap: 20px;
      margin-top: auto;
      padding-top: 24px;
      border-top: 1px solid var(--line);
    }

    .footer-note { max-width: 470px; color: var(--muted); font-size: 12px; line-height: 1.5; }
    .footer-status { display: flex; align-items: center; gap: 12px; }
    .ai-disclaimer {
      flex: none;
      color: #50576b;
      font-size: 12px;
      font-weight: 650;
      line-height: 1.5;
      text-align: right;
    }
    .actions { display: flex; align-items: center; gap: 10px; }
    .primary, .secondary {
      min-height: 40px;
      padding: 0 16px;
      border-radius: 10px;
      cursor: pointer;
      font-weight: 700;
      white-space: nowrap;
    }
    .primary { border: 1px solid var(--cobalt); color: var(--white); background: var(--cobalt); }
    .primary:hover { background: var(--cobalt-dark); }
    .secondary { border: 1px solid var(--line); color: var(--ink); background: var(--white); }
    button:focus-visible { outline: 3px solid rgba(52,84,209,.3); outline-offset: 2px; }

    .result-card {
      display: none;
      margin-top: 20px;
      padding: 18px;
      border-radius: 16px;
      background: #eef9f4;
      border: 1px solid #b9e0d1;
    }
    .result-card.visible { display: block; }
    .result-card.visible:not(.warning) {
      box-shadow: 0 14px 32px rgba(19,121,91,.14);
    }
    .result-card.warning { background: #fff6e8; border-color: #f1d09d; }
    .result-card h4 { margin: 0 0 7px; }
    .result-card p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.45; }
    .result-card .next-action { margin-top: 10px; color: var(--ink); }
    .open-website {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      gap: 8px;
      min-height: 44px;
      margin-top: 16px;
      padding: 0 18px;
      border: 1px solid var(--cobalt);
      border-radius: 10px;
      color: var(--white);
      background: var(--cobalt);
      font-weight: 750;
      text-decoration: none;
      box-shadow: 0 9px 20px rgba(52,84,209,.2);
    }
    .open-website[hidden] { display: none; }
    .open-website:hover { background: var(--cobalt-dark); }
    .open-website:focus-visible {
      outline: 3px solid rgba(52,84,209,.3);
      outline-offset: 3px;
    }

    @media (max-width: 960px) {
      .shell { width: min(100% - 24px, 760px); }
      .layout { grid-template-columns: 1fr; }
      .preview-pane { min-height: 620px; border-right: 0; border-bottom: 1px solid var(--line); }
      .status-pane { padding: 34px; }
      .footer { align-items: flex-start; flex-direction: column; gap: 10px; }
      .footer-status { align-items: flex-start; flex-direction: column; }
      .ai-disclaimer { text-align: left; }
      .open-website { width: 100%; }
      .preview-notice { padding-inline: 22px; }
    }

    @media (prefers-reduced-motion: reduce) {
      *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
      .step.working .step-marker::after {
        width: 9px;
        height: 9px;
        border: 0;
        background: var(--cobalt);
        animation: none !important;
      }
    }
  </style>
</head>
<body>
  <main class="shell">
    <header class="topbar">
      <div class="brand"><img class="brand-mark" id="brandIcon" src="data:image/gif;base64,R0lGODlhAQABAAAAACw=" alt="" hidden>Power Pages</div>
      <span class="status-badge" id="statusBadge">Preparing site</span>
    </header>
    <aside class="preview-notice" id="previewNoticeBanner" role="note" aria-label="Preview experience">
      <strong>Preview</strong>
      <span id="previewNotice">This non-SPA site creation and customization experience is in preview. Review environments, plans, and local changes before approval or deployment.</span>
    </aside>

    <section class="layout">
      <aside class="preview-pane">
        <p class="eyebrow" id="templateEyebrow">Your selected starting point</p>
        <div class="template-heading">
          <h1 id="templateDisplayName"></h1>
          <span class="template-category" id="templateCategory">Non-SPA</span>
        </div>
        <p class="lede" id="templateDescription"></p>
        <div class="preview-card" id="previewCard" role="tabpanel" tabindex="0" data-focus-key="preview-panel">
          <img id="previewImage" src="data:image/gif;base64,R0lGODlhAQABAAAAACw=" alt="" hidden>
        </div>
        <div class="slide-controls" id="slideControls" role="tablist" aria-label="Template page preview"></div>
        <div class="preview-controls">
          <div class="segmented" id="previewViewControls" role="group" aria-label="Preview size">
            <button class="active" data-view="desktop" data-focus-key="view-desktop" aria-pressed="true">Desktop</button>
            <button data-view="mobile" data-focus-key="view-mobile" aria-pressed="false">Mobile</button>
          </div>
          <div class="template-meta" id="templateMeta">
            <span id="templateName"></span><br>
            <span id="modelVersion"></span> model · <span id="languageName"></span><br>
            <span class="template-meta-secondary"><span id="languageSource"></span> · LCID <span id="languageLcid"></span></span>
          </div>
        </div>
        <section class="template-info" aria-labelledby="templateInfoTitle">
          <h2 id="templateInfoTitle">About this template</h2>
          <p id="aboutDescription"></p>
          <ul class="feature-list" id="featureList"></ul>
          <div class="template-notes" id="templateNotes"></div>
        </section>
      </aside>

      <section class="status-pane" aria-live="polite">
        <div class="site-identity">
          <div>
            <p class="eyebrow" id="siteEyebrow">Creating your site</p>
            <h2 id="siteName"></h2>
            <div class="site-url" id="siteUrl"></div>
          </div>
          <div class="state-chip" id="stateChip"><span class="pulse"></span><span id="chipText"></span></div>
        </div>

        <section class="input-notice" id="inputNotice" role="alert" aria-labelledby="inputNoticeTitle" hidden>
          <span class="input-notice-mark" aria-hidden="true">!</span>
          <div>
            <h3 id="inputNoticeTitle">Your input is needed</h3>
            <p id="requiredAction"></p>
            <p class="input-notice-location"><strong>Where to respond:</strong> <span id="responseLocation"></span></p>
          </div>
        </section>

        <ol class="timeline" id="timeline"></ol>

        <div class="result-card" id="resultCard">
          <h4 id="resultTitle">Your site is ready</h4>
          <p id="resultMessage">The selected data model was verified, downloaded, and validated locally.</p>
          <p class="next-action" id="nextAction" hidden><strong>Next:</strong> <span id="nextActionText"></span></p>
          <a class="open-website" id="openWebsite" data-focus-key="open-website" target="_blank" rel="noopener noreferrer" aria-label="Open website in a new tab" hidden>
            Open website <span aria-hidden="true">↗</span>
          </a>
        </div>

        <footer class="footer">
          <div class="footer-status">
            <div class="footer-note" id="refreshNote">This page refreshes automatically as Power Pages advances through provisioning, registration, download, and validation.</div>
            <button class="secondary" id="refreshToggle" type="button" data-focus-key="refresh-toggle" aria-pressed="false">Pause auto-refresh</button>
          </div>
          <div class="ai-disclaimer">AI-generated content may be incorrect</div>
        </footer>
      </section>
    </section>
  </main>

  <script nonce="__CSP_NONCE__">
    const model = __JSON_MODEL__;
    const storageKey = `power-pages-create-site:${location.pathname}`;
    const saved = JSON.parse(sessionStorage.getItem(storageKey) || "{}");
    const hasMobilePreviews = model.template.previews.some((preview) => Boolean(preview.mobile));
    let currentView = saved.view === "mobile" && hasMobilePreviews ? "mobile" : "desktop";
    const allowRefreshPause = model.presentation?.allowRefreshPause !== false;
    let autoRefreshPaused = allowRefreshPause && saved.autoRefreshPaused === true;
    let refreshTimer;
    let currentSlide = model.template.previews.some((preview) => preview.name === saved.slide)
      ? saved.slide
      : model.template.previews[0]?.name;

    function saveState(overrides = {}) {
      sessionStorage.setItem(storageKey, JSON.stringify({
        view: currentView,
        slide: currentSlide,
        autoRefreshPaused,
        ...overrides
      }));
    }

    function setText(id, value) {
      document.getElementById(id).textContent = value || "";
    }

    function updatePreview() {
      const preview = model.template.previews.find((candidate) => candidate.name === currentSlide);
      if (!preview) {
        document.getElementById("previewCard").hidden = true;
        document.getElementById("slideControls").hidden = true;
        document.getElementById("previewViewControls").hidden = true;
        return;
      }

      document.getElementById("previewViewControls").hidden = false;
      if (!preview[currentView]) {
        currentView = preview.desktop ? "desktop" : "mobile";
      }
      const image = document.getElementById("previewImage");
      image.src = preview[currentView];
      image.alt = `${currentView} preview of ${model.template.displayName}: ${preview.displayName}`;
      image.hidden = false;
      document.getElementById("previewCard").classList.toggle("mobile", currentView === "mobile");
      document.querySelectorAll("[data-view]").forEach((button) => {
        const selected = button.dataset.view === currentView;
        button.classList.toggle("active", selected);
        button.setAttribute("aria-pressed", String(selected));
        button.hidden = button.dataset.view === "mobile" && !hasMobilePreviews;
        button.disabled = !preview[button.dataset.view];
      });
      document.querySelectorAll("[data-slide]").forEach((button) => {
        const selected = button.dataset.slide === currentSlide;
        button.classList.toggle("active", selected);
        button.setAttribute("aria-selected", String(selected));
        button.tabIndex = selected ? 0 : -1;
        if (selected) {
          document.getElementById("previewCard").setAttribute("aria-labelledby", button.id);
        }
      });
      saveState();
    }

    setText("templateDisplayName", model.template.displayName);
    setText("templateDescription", model.template.description);
    setText("aboutDescription", model.template.description);
    if (model.presentation?.showPreviewNotice === false) {
      document.getElementById("previewNoticeBanner").remove();
    } else if (model.presentation?.notice) {
      setText("previewNotice", model.presentation.notice);
    }
    setText("templateEyebrow", model.presentation?.templateEyebrow || "Your selected starting point");
    setText("templateCategory", model.presentation?.templateCategory || "Non-SPA");
    setText("siteEyebrow", model.presentation?.siteEyebrow || "Creating your site");
    setText("templateName", model.template.name);
    setText("modelVersion", model.site.modelVersion);
    setText(
      "languageName",
      model.site.language.code
        ? `${model.site.language.name} (${model.site.language.code})`
        : model.site.language.name
    );
    setText("languageSource", model.site.language.source);
    setText("languageLcid", model.site.language.lcid);
    setText("siteName", model.site.name);
    setText("siteUrl", model.site.url);
    if (!model.site.language.name) {
      document.getElementById("templateMeta").hidden = true;
    }
    document.getElementById("brandIcon").src = model.brandIcon;
    document.getElementById("brandIcon").hidden = false;
    setText("statusBadge", model.presentation?.statusBadge || "Live creation status");

    document.getElementById("featureList").replaceChildren(
      ...model.template.capabilities.map((capability) => {
        const item = document.createElement("li");
        item.textContent = capability;
        return item;
      })
    );

    const notes = [];
    if (model.template.requirements.length) {
      const requirement = document.createElement("div");
      requirement.className = "template-note";
      const heading = document.createElement("strong");
      heading.textContent = "Requires: ";
      requirement.append(heading, document.createTextNode(model.template.requirements.join(", ") + "."));
      notes.push(requirement);
    }
    if (model.template.warning) {
      const warning = document.createElement("div");
      warning.className = "template-note";
      const heading = document.createElement("strong");
      heading.textContent = "Editing note: ";
      warning.append(heading, document.createTextNode(model.template.warning));
      notes.push(warning);
    }
    document.getElementById("templateNotes").replaceChildren(...notes);

    const slideControls = document.getElementById("slideControls");
    slideControls.replaceChildren(...model.template.previews.map((preview, index) => {
      const button = document.createElement("button");
      button.type = "button";
      button.id = `previewTab-${index}`;
      button.dataset.slide = preview.name;
      button.dataset.focusKey = `preview-tab-${index}`;
      button.setAttribute("role", "tab");
      button.setAttribute("aria-controls", "previewCard");
      button.textContent = preview.displayName;
      button.addEventListener("click", () => {
        currentSlide = preview.name;
        updatePreview();
      });
      button.addEventListener("keydown", (event) => {
        const tabs = [...slideControls.querySelectorAll("[role=tab]")];
        const currentIndex = tabs.indexOf(event.currentTarget);
        let nextIndex;
        if (event.key === "ArrowRight") nextIndex = (currentIndex + 1) % tabs.length;
        if (event.key === "ArrowLeft") nextIndex = (currentIndex - 1 + tabs.length) % tabs.length;
        if (event.key === "Home") nextIndex = 0;
        if (event.key === "End") nextIndex = tabs.length - 1;
        if (nextIndex === undefined) return;
        event.preventDefault();
        currentSlide = tabs[nextIndex].dataset.slide;
        updatePreview();
        tabs[nextIndex].focus();
      });
      return button;
    }));

    document.querySelectorAll("[data-view]").forEach((button) => {
      button.addEventListener("click", () => {
        currentView = button.dataset.view;
        updatePreview();
      });
    });

    const timeline = document.getElementById("timeline");

    function renderStatus() {
      setText("chipText", model.status.chip);
      setText(
        "statusBadge",
        model.status.terminal
          ? model.status.chip
          : model.presentation?.statusBadge || "Live creation status"
      );
      const stateChip = document.getElementById("stateChip");
      stateChip.className = `state-chip ${model.status.activityState}`;
      const inputNotice = document.getElementById("inputNotice");
      inputNotice.hidden = !model.status.notification;
      if (model.status.notification) {
        setText("inputNoticeTitle", model.status.notification.title);
        setText("requiredAction", model.status.notification.requiredAction);
        setText("responseLocation", model.status.notification.responseLocation);
      }

      timeline.replaceChildren(...model.timeline.map((step, index) => {
        const complete = index < model.status.step || model.status.key === "ready";
        const current = index === model.status.step;
        const working = current && model.status.activityState === "working";
        const blocked = current && model.status.activityState === "awaiting-input";
        const failed = current && model.status.activityState === "failed";
        const canceled = current && model.status.activityState === "canceled";
        const item = document.createElement("li");
        item.className = `step ${failed ? "error" : canceled ? "canceled" : blocked ? "blocked" : complete ? "complete" : working ? "working" : ""}`;
        const marker = document.createElement("span");
        marker.className = "step-marker";
        marker.setAttribute("aria-hidden", "true");
        marker.textContent = complete ? "✓" : failed ? "!" : canceled ? "×" : blocked ? "!" : working ? "" : String(index + 1).padStart(2, "0");
        const copy = document.createElement("div");
        const title = document.createElement("div");
        title.className = "step-title";
        title.textContent = step[0];
        const detail = document.createElement("div");
        detail.className = "step-detail";
        detail.textContent = blocked
          ? model.status.notification.requiredAction
          : working || failed || canceled
            ? model.status.message
            : step[1];
        copy.append(title, detail);
        const state = document.createElement("span");
        state.className = "step-state";
        state.textContent = complete
          ? "Complete"
          : failed
            ? "Stopped"
            : canceled
              ? "Canceled"
              : blocked
                ? "Your input needed"
                : working
                  ? "Working"
                  : "Waiting";
        item.append(marker, copy, state);
        return item;
      }));

      const resultCard = document.getElementById("resultCard");
      resultCard.className = `result-card${model.status.result ? " visible" : ""}${model.status.error ? " warning" : ""}`;
      if (model.status.result) {
        setText("resultTitle", model.status.result.title);
        setText("resultMessage", model.status.result.message);
      }
      document.getElementById("nextAction").hidden = !model.status.result?.nextAction;
      if (model.status.result?.nextAction) {
        setText("nextActionText", model.status.result.nextAction);
      }
      const openWebsite = document.getElementById("openWebsite");
      openWebsite.hidden = !model.status.openWebsiteUrl;
      if (model.status.openWebsiteUrl) openWebsite.href = model.status.openWebsiteUrl;
    }

    renderStatus();

    const refreshToggle = document.getElementById("refreshToggle");
    if (!allowRefreshPause) refreshToggle.remove();

    function rememberFocusAndReload() {
      const focusKey = document.activeElement?.dataset?.focusKey;
      saveState(focusKey ? { focusKey } : {});
      location.reload();
    }

    function scheduleRefresh() {
      window.clearTimeout(refreshTimer);
      if (model.refresh && !model.statusFeed && !autoRefreshPaused) {
        refreshTimer = window.setTimeout(rememberFocusAndReload, 5000);
      }
    }

    function updateRefreshControl() {
      refreshToggle.textContent = autoRefreshPaused ? "Resume auto-refresh" : "Pause auto-refresh";
      refreshToggle.setAttribute("aria-pressed", String(autoRefreshPaused));
      if (autoRefreshPaused) {
        setText(
          "refreshNote",
          model.status.activityState === "awaiting-input"
            ? "Creation is paused for your response. Auto-refresh is paused until you resume it."
            : "Auto-refresh is paused. Resume it to keep this status page current."
        );
      } else if (model.status.activityState === "awaiting-input") {
        setText("refreshNote", "Creation is paused for your response. This page will update automatically after you reply.");
      } else {
        setText(
          "refreshNote",
          model.presentation?.refreshNote ||
            "This page refreshes automatically as Power Pages advances through provisioning, registration, download, and validation."
        );
      }
    }

    refreshToggle.addEventListener("click", () => {
      autoRefreshPaused = !autoRefreshPaused;
      saveState();
      updateRefreshControl();
      scheduleRefresh();
    });

    if (model.status.terminal) {
      refreshToggle.hidden = true;
      setText("refreshNote", model.status.footer || "This status is final.");
    } else {
      updateRefreshControl();
      scheduleRefresh();
    }

    function applyStatusFeed(status) {
      const phaseSteps = { solutions: 0, site: 1, siteAndSeed: 1, seed: 2, activation: 3 };
      const step = phaseSteps[status.phase] ?? model.status.step;
      const succeeded = status.state === "succeeded";
      const failed = status.state === "error";
      const awaitingInput = status.awaitingInput === true;
      const liveUrl = status.siteUrl || status.redirectUrl || null;
      model.status = {
        ...model.status,
        key: succeeded ? "ready" : status.phase || model.status.key,
        step: succeeded ? model.timeline.length : step,
        chip: succeeded ? "Ready" : failed ? "Action required" : awaitingInput ? "Input needed" : "Working",
        message: status.message || model.status.message,
        activityState: succeeded ? "complete" : failed ? "failed" : awaitingInput ? "awaiting-input" : "working",
        terminal: succeeded || failed,
        error: failed,
        notification: awaitingInput
          ? {
              title: "Your input is needed",
              requiredAction: status.inputPrompt || "Return to the site creation conversation.",
              responseLocation: "Return to the site creation conversation and provide your response.",
            }
          : null,
        result: succeeded
          ? {
              title: "Template site is ready",
              message: "The SPA template was installed, uploaded, and activated.",
            }
          : failed
            ? {
                title: "Template setup needs attention",
                message: status.message || "The SPA template workflow stopped before completion.",
              }
            : null,
        openWebsiteUrl: succeeded ? liveUrl : null,
        footer: succeeded
          ? "Creation is complete. Use the website button when you are ready to open the live site."
          : failed
            ? "Review the error in the site creation conversation before retrying."
            : null,
      };
      if (status.siteName) setText("siteName", status.siteName);
      if (liveUrl) setText("siteUrl", liveUrl);
      renderStatus();
      if (model.status.terminal) {
        window.clearInterval(refreshTimer);
        refreshToggle.hidden = true;
        setText("refreshNote", model.status.footer);
      }
    }

    async function pollStatusFeed() {
      if (!model.statusFeed || autoRefreshPaused || model.status.terminal) return;
      try {
        const response = await fetch(model.statusFeed.url, { cache: "no-store" });
        if (!response.ok) return;
        applyStatusFeed(await response.json());
      } catch {
        // The local status server can briefly race the first poll while starting.
      }
    }

    if (model.statusFeed) {
      window.clearTimeout(refreshTimer);
      refreshTimer = window.setInterval(
        pollStatusFeed,
        Math.max(500, Number(model.statusFeed.intervalMs) || 1500)
      );
      pollStatusFeed();
    }

    updatePreview();
    if (saved.focusKey) {
      document.querySelector(`[data-focus-key="${CSS.escape(saved.focusKey)}"]`)?.focus();
      saveState({ focusKey: undefined });
    }
  </script>
</body>
</html>