import { m as head, k as escape_html, t as derived, q as bind_props, d as attr_class, f as stringify, o as attr, n as ensure_array_like, w as clsx, r as spread_props } from './index-Cnl871UW.js';
import { g as goto } from './client2-BjxIYuno.js';
import { o as onDestroy } from './index-server-CUC9Jt7r.js';
import './markdown-W_mTBct0.js';
import { h as html, B as Button } from './Button-C7D5W6wV.js';
import './root-DhswcH6o.js';
import './index2-HA3VTH7y.js';
import './state.svelte-2Lellg7t.js';
import 'dompurify';
import 'marked';

function ModalAnimation($$renderer, $$props) {
  let {
    enable = true,
    align = "bottom",
    transitionType = "ALL",
    children
  } = $$props;
  let useFlyAnimation = derived(() => align === "top" || align === "bottom");
  let useOutTransition = derived(() => transitionType === "ALL");
  if (enable) {
    $$renderer.push("<!--[0-->");
    if (useFlyAnimation() && useOutTransition()) {
      $$renderer.push("<!--[0-->");
      $$renderer.push(`<div>`);
      children?.($$renderer);
      $$renderer.push(`<!----></div>`);
    } else if (useFlyAnimation()) {
      $$renderer.push("<!--[1-->");
      $$renderer.push(`<div>`);
      children?.($$renderer);
      $$renderer.push(`<!----></div>`);
    } else if (useOutTransition()) {
      $$renderer.push("<!--[2-->");
      $$renderer.push(`<div>`);
      children?.($$renderer);
      $$renderer.push(`<!----></div>`);
    } else {
      $$renderer.push("<!--[-1-->");
      $$renderer.push(`<div>`);
      children?.($$renderer);
      $$renderer.push(`<!----></div>`);
    }
    $$renderer.push(`<!--]-->`);
  } else {
    $$renderer.push("<!--[-1-->");
    children?.($$renderer);
    $$renderer.push(`<!---->`);
  }
  $$renderer.push(`<!--]-->`);
}
function OverlayAnimation($$renderer, $$props) {
  let { children } = $$props;
  $$renderer.push(`<div>`);
  children?.($$renderer);
  $$renderer.push(`<!----></div>`);
}
function Modal($$renderer, $$props) {
  $$renderer.component(($$renderer2) => {
    let backPressed = false;
    let {
      size = "fit-content",
      align = "center",
      showOverlay = true,
      supportHardwareBackPress = false,
      enableTransition = true,
      transitionType = "ALL",
      header = {},
      footer,
      debounceTime = 700,
      leftImageTestId,
      testId,
      content,
      footerSnippet,
      onclose,
      onheaderRightImageClick,
      onheaderLeftImageClick,
      onprimaryButtonClick,
      onsecondaryButtonClick,
      onoverlayClick,
      onkeydown,
      classes
    } = $$props;
    function handlePopstate() {
      backPressed = true;
      onclose?.();
    }
    function handlePrimaryButtonClick(event) {
      onprimaryButtonClick?.(event);
    }
    function handleSecondaryButtonClick(event) {
      onsecondaryButtonClick?.(event);
    }
    onDestroy(() => {
      if (typeof window !== "undefined") {
        document.body.style.overflow = "";
        if (supportHardwareBackPress) {
          if (!backPressed) {
            history.back();
          }
          window.removeEventListener("popstate", handlePopstate);
        }
      }
    });
    if (typeof content === "function") {
      $$renderer2.push("<!--[0-->");
      OverlayAnimation($$renderer2, {
        children: ($$renderer3) => {
          $$renderer3.push(`<div${attr_class(`modal ${stringify(align)} ${stringify(showOverlay ? "overlay-active" : "overlay-inactive")} ${stringify(classes ?? "")}`, "svelte-14ltpll")} role="button" tabindex="0"${attr("data-pw", testId)}>`);
          ModalAnimation($$renderer3, {
            enable: enableTransition,
            align,
            transitionType,
            children: ($$renderer4) => {
              $$renderer4.push(`<div${attr_class(`modal-content ${stringify(size)}`, "svelte-14ltpll")}>`);
              if (typeof header?.leftImage === "string" && header.leftImage.length > 0 || typeof header?.text === "string" && header.text.length > 0 || typeof header?.rightImage === "string" && header.rightImage.length > 0) {
                $$renderer4.push("<!--[0-->");
                $$renderer4.push(`<div class="header svelte-14ltpll">`);
                if (header.leftImage) {
                  $$renderer4.push("<!--[0-->");
                  $$renderer4.push(`<div role="button" tabindex="0"${attr("data-pw", leftImageTestId)}><img class="header-left-img svelte-14ltpll"${attr("src", header.leftImage)} alt=""/></div>`);
                } else {
                  $$renderer4.push("<!--[-1-->");
                }
                $$renderer4.push(`<!--]--> `);
                if (header.text) {
                  $$renderer4.push("<!--[0-->");
                  $$renderer4.push(`<div class="header-text svelte-14ltpll"${attr("data-pw", header.testId)}>${escape_html(header.text)}</div>`);
                } else {
                  $$renderer4.push("<!--[-1-->");
                }
                $$renderer4.push(`<!--]--> `);
                if (header.rightImage) {
                  $$renderer4.push("<!--[0-->");
                  $$renderer4.push(`<div role="button" tabindex="0"${attr("data-pw", header.buttonTestId)}><img class="header-right-img svelte-14ltpll"${attr("src", header.rightImage)} alt=""/></div>`);
                } else {
                  $$renderer4.push("<!--[-1-->");
                }
                $$renderer4.push(`<!--]--></div>`);
              } else {
                $$renderer4.push("<!--[-1-->");
              }
              $$renderer4.push(`<!--]--> <div class="slot-content svelte-14ltpll">`);
              content?.($$renderer4);
              $$renderer4.push(`<!----></div> `);
              if (typeof footerSnippet === "function") {
                $$renderer4.push("<!--[0-->");
                $$renderer4.push(`<div class="footer-content svelte-14ltpll">`);
                footerSnippet?.($$renderer4);
                $$renderer4.push(`<!----></div>`);
              } else if (typeof footer?.primaryButton === "object" || typeof footer?.secondaryButton === "object") {
                $$renderer4.push("<!--[1-->");
                $$renderer4.push(`<div class="footer-content svelte-14ltpll"><div class="footer-action-buttons svelte-14ltpll">`);
                if (footer.secondaryButton) {
                  $$renderer4.push("<!--[0-->");
                  $$renderer4.push(`<div class="footer-secondary-button svelte-14ltpll">`);
                  Button($$renderer4, spread_props([
                    footer.secondaryButton,
                    { onclick: handleSecondaryButtonClick }
                  ]));
                  $$renderer4.push(`<!----></div>`);
                } else {
                  $$renderer4.push("<!--[-1-->");
                }
                $$renderer4.push(`<!--]--> `);
                if (footer.primaryButton) {
                  $$renderer4.push("<!--[0-->");
                  $$renderer4.push(`<div class="footer-primary-button svelte-14ltpll">`);
                  Button($$renderer4, spread_props([footer.primaryButton, { onclick: handlePrimaryButtonClick }]));
                  $$renderer4.push(`<!----></div>`);
                } else {
                  $$renderer4.push("<!--[-1-->");
                }
                $$renderer4.push(`<!--]--></div></div>`);
              } else {
                $$renderer4.push("<!--[-1-->");
              }
              $$renderer4.push(`<!--]--></div>`);
            }
          });
          $$renderer3.push(`<!----></div>`);
        }
      });
    } else {
      $$renderer2.push("<!--[-1-->");
    }
    $$renderer2.push(`<!--]-->`);
  });
}
function Img($$renderer, $$props) {
  $$renderer.component(($$renderer2) => {
    let { src, alt, classes } = $$props;
    let currentSrc = derived(() => src);
    $$renderer2.push(`<img${attr_class(clsx(classes ?? ""), "svelte-1i92k5h")}${attr("src", currentSrc())}${attr("alt", alt)} onerror="this.__e=event"/>`);
  });
}
const SvelteMap = globalThis.Map;
function KeyboardInput($$renderer, $$props) {
  $$renderer.component(($$renderer2) => {
    let { keys, separator = "+", testId, onclick, classes } = $$props;
    const KEY_SYMBOLS = {
      cmd: "⌘",
      command: "⌘",
      ctrl: "⌃",
      control: "⌃",
      alt: "⌥",
      option: "⌥",
      shift: "⇧",
      enter: "↵",
      backspace: "⌫",
      delete: "⌦",
      tab: "⇥",
      escape: "Esc",
      esc: "Esc",
      up: "↑",
      down: "↓",
      left: "←",
      right: "→",
      space: "␣"
    };
    let keyList = derived(() => Array.isArray(keys) ? keys : keys.split(separator).map((k) => k.trim()));
    let interactive = derived(() => typeof onclick === "function");
    function getSymbol(key) {
      return KEY_SYMBOLS[key.toLowerCase()] ?? key;
    }
    $$renderer2.push(`<span${attr_class(`keyboard-input ${stringify(classes ?? "")}`, "svelte-xb2c7p")}${attr("data-pw", typeof testId === "string" ? testId : null)}${attr("role", interactive() ? "button" : null)}${attr("tabindex", interactive() ? 0 : null)}><!--[-->`);
    const each_array = ensure_array_like(keyList());
    for (let i = 0, $$length = each_array.length; i < $$length; i++) {
      let key = each_array[i];
      if (i > 0) {
        $$renderer2.push("<!--[0-->");
        $$renderer2.push(`<span class="separator svelte-xb2c7p">${escape_html(separator)}</span>`);
      } else {
        $$renderer2.push("<!--[-1-->");
      }
      $$renderer2.push(`<!--]--> <kbd class="key svelte-xb2c7p">${escape_html(getSymbol(key))}</kbd>`);
    }
    $$renderer2.push(`<!--]--></span>`);
  });
}
const searchSvg = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg">\n  <circle cx="11" cy="11" r="8"></circle>\n  <line x1="21" y1="21" x2="16.65" y2="16.65"></line>\n</svg>\n';
function CommandMenu($$renderer, $$props) {
  $$renderer.component(($$renderer2) => {
    let {
      items,
      open = false,
      placeholder = "Search commands...",
      emptyText = "No results found.",
      testId,
      itemIcon,
      searchIcon,
      onselect,
      onclose,
      classes
    } = $$props;
    let query = "";
    let activeIndex = 0;
    let filteredItems = derived(() => {
      if (query.trim() === "") {
        return items;
      }
      const lower = query.toLowerCase();
      return items.filter((item) => item.label.toLowerCase().includes(lower));
    });
    let groupedItems = derived(() => {
      const groups = new SvelteMap();
      for (const item of filteredItems()) {
        const group = item.group ?? "";
        if (!groups.has(group)) {
          groups.set(group, []);
        }
        const groupList = groups.get(group);
        if (Array.isArray(groupList)) {
          groupList.push(item);
        }
      }
      return groups;
    });
    let flatItems = derived(() => {
      const result = [];
      for (const [, groupItems] of groupedItems()) {
        for (const item of groupItems) {
          result.push(item);
        }
      }
      return result;
    });
    let flatIndexLookup = derived(() => {
      const map = new SvelteMap();
      for (let i = 0; i < flatItems().length; i++) {
        const item = flatItems().at(i);
        if (typeof item === "object") {
          map.set(item.value, i);
        }
      }
      return map;
    });
    function close() {
      open = false;
      query = "";
      activeIndex = 0;
      onclose?.();
    }
    function handleGlobalKeyDown(event) {
      if ((event.metaKey || event.ctrlKey) && event.key === "k") {
        event.preventDefault();
        if (open) {
          close();
        } else {
          open = true;
        }
      }
    }
    onDestroy(() => {
      if (typeof window !== "undefined") {
        document.body.style.overflow = "";
        window.removeEventListener("keydown", handleGlobalKeyDown);
      }
    });
    if (open) {
      $$renderer2.push("<!--[0-->");
      $$renderer2.push(`<div${attr_class(`command-menu-overlay ${stringify(classes ?? "")}`, "svelte-19oedql")} role="dialog" aria-modal="true" aria-label="Command menu" tabindex="-1"${attr("data-pw", typeof testId === "string" ? testId : null)}><div class="command-menu-dialog svelte-19oedql"><div class="command-menu-input-wrapper svelte-19oedql">`);
      if (typeof searchIcon === "function") {
        $$renderer2.push("<!--[0-->");
        searchIcon($$renderer2);
        $$renderer2.push(`<!---->`);
      } else {
        $$renderer2.push("<!--[-1-->");
        $$renderer2.push(`<span class="command-menu-search-icon svelte-19oedql">${html(searchSvg)}</span>`);
      }
      $$renderer2.push(`<!--]--> <input${attr("value", query)} type="text" class="command-menu-input svelte-19oedql"${attr("placeholder", placeholder)} autocomplete="off" spellcheck="false"${attr("data-pw", typeof testId === "string" ? `${testId}-input` : null)}/></div> <div class="command-menu-separator svelte-19oedql"></div> <div class="command-menu-list svelte-19oedql" role="listbox">`);
      if (flatItems().length === 0) {
        $$renderer2.push("<!--[0-->");
        $$renderer2.push(`<div class="command-menu-empty svelte-19oedql">${escape_html(emptyText)}</div>`);
      } else {
        $$renderer2.push("<!--[-1-->");
        $$renderer2.push(`<!--[-->`);
        const each_array = ensure_array_like(groupedItems());
        for (let $$index_2 = 0, $$length = each_array.length; $$index_2 < $$length; $$index_2++) {
          let [group, groupItems] = each_array[$$index_2];
          if (group !== "") {
            $$renderer2.push("<!--[0-->");
            $$renderer2.push(`<div class="command-menu-group-heading svelte-19oedql">${escape_html(group)}</div>`);
          } else {
            $$renderer2.push("<!--[-1-->");
          }
          $$renderer2.push(`<!--]--> <!--[-->`);
          const each_array_1 = ensure_array_like(groupItems);
          for (let $$index_1 = 0, $$length2 = each_array_1.length; $$index_1 < $$length2; $$index_1++) {
            let item = each_array_1[$$index_1];
            const index = flatIndexLookup().get(item.value) ?? -1;
            $$renderer2.push(`<button type="button"${attr_class("command-menu-item svelte-19oedql", void 0, { "active": index === activeIndex, "disabled": item.disabled })}${attr("data-active", index === activeIndex)} role="option"${attr("aria-selected", index === activeIndex)}${attr("aria-disabled", item.disabled)} tabindex="-1"${attr("data-pw", typeof testId === "string" ? `${testId}-item-${item.value}` : null)}>`);
            if (typeof itemIcon === "function") {
              $$renderer2.push("<!--[0-->");
              $$renderer2.push(`<span class="command-menu-item-icon svelte-19oedql">`);
              itemIcon($$renderer2, item);
              $$renderer2.push(`<!----></span>`);
            } else if (typeof item.icon === "string" && item.icon.length > 0) {
              $$renderer2.push("<!--[1-->");
              $$renderer2.push(`<div class="command-menu-item-icon-img-wrapper svelte-19oedql">`);
              Img($$renderer2, { src: item.icon, alt: "" });
              $$renderer2.push(`<!----></div>`);
            } else {
              $$renderer2.push("<!--[-1-->");
            }
            $$renderer2.push(`<!--]--> <span class="command-menu-item-label svelte-19oedql">${escape_html(item.label)}</span> `);
            if (typeof item.shortcut === "string" && item.shortcut.length > 0) {
              $$renderer2.push("<!--[0-->");
              $$renderer2.push(`<span class="command-menu-item-shortcut svelte-19oedql"><!--[-->`);
              const each_array_2 = ensure_array_like(item.shortcut.split("+"));
              for (let i = 0, $$length3 = each_array_2.length; i < $$length3; i++) {
                let key = each_array_2[i];
                $$renderer2.push(`<kbd class="command-menu-kbd svelte-19oedql">${escape_html(key.trim())}</kbd>`);
              }
              $$renderer2.push(`<!--]--></span>`);
            } else {
              $$renderer2.push("<!--[-1-->");
            }
            $$renderer2.push(`<!--]--></button>`);
          }
          $$renderer2.push(`<!--]-->`);
        }
        $$renderer2.push(`<!--]-->`);
      }
      $$renderer2.push(`<!--]--></div></div></div>`);
    } else {
      $$renderer2.push("<!--[-1-->");
    }
    $$renderer2.push(`<!--]-->`);
    bind_props($$props, { open });
  });
}
function CommandPalette($$renderer, $$props) {
  $$renderer.component(($$renderer2) => {
    let { commands, onClose, open = false } = $$props;
    const items = derived(() => commands.map((cmd, i) => ({ label: cmd.label, value: String(i) })));
    function handleSelect(item) {
      const index = parseInt(item.value, 10);
      if (commands[index]) {
        commands[index].action();
      }
    }
    let $$settled = true;
    let $$inner_renderer;
    function $$render_inner($$renderer3) {
      CommandMenu($$renderer3, {
        items: items(),
        placeholder: "Type a command...",
        emptyText: "No matching commands",
        onselect: handleSelect,
        onclose: onClose,
        classes: "command-palette",
        get open() {
          return open;
        },
        set open($$value) {
          open = $$value;
          $$settled = false;
        }
      });
    }
    do {
      $$settled = true;
      $$inner_renderer = $$renderer2.copy();
      $$render_inner($$inner_renderer);
    } while (!$$settled);
    $$renderer2.subsume($$inner_renderer);
    bind_props($$props, { open });
  });
}
const isMac = typeof navigator !== "undefined" && /Mac|iPhone|iPad/.test(navigator.userAgent);
const modLabel = isMac ? "⌘" : "Ctrl";
function getShortcutList() {
  return [
    { description: "Command palette", keys: `${modLabel}+K` },
    { description: "Keyboard shortcuts", keys: `${modLabel}+/` }
  ];
}
function ShortcutsHelp($$renderer, $$props) {
  $$renderer.component(($$renderer2) => {
    const { onClose, open } = $$props;
    const shortcuts = getShortcutList();
    if (open) {
      $$renderer2.push("<!--[0-->");
      {
        let content = function($$renderer3) {
          $$renderer3.push(`<div class="shortcuts-list svelte-1u7lstk"><!--[-->`);
          const each_array = ensure_array_like(shortcuts);
          for (let $$index = 0, $$length = each_array.length; $$index < $$length; $$index++) {
            let shortcut = each_array[$$index];
            $$renderer3.push(`<div class="shortcut-row svelte-1u7lstk"><span class="shortcut-desc svelte-1u7lstk">${escape_html(shortcut.description)}</span> `);
            KeyboardInput($$renderer3, { keys: shortcut.keys, classes: "shortcut-kbd" });
            $$renderer3.push(`<!----></div>`);
          }
          $$renderer3.push(`<!--]--></div>`);
        };
        Modal($$renderer2, {
          header: { text: "Keyboard Shortcuts" },
          onoverlayClick: onClose,
          classes: "shortcuts-modal",
          content
        });
      }
    } else {
      $$renderer2.push("<!--[-1-->");
    }
    $$renderer2.push(`<!--]-->`);
  });
}
function _page($$renderer, $$props) {
  $$renderer.component(($$renderer2) => {
    let terminal = null;
    let showShortcutsHelp = false;
    let showCommandPalette = false;
    const isRunning = derived(() => terminal?.status === "running");
    const commandName = derived(() => "terminal");
    const paletteCommands = derived(() => {
      const cmds = [
        { action: () => void goto(), label: "Go to Home" },
        {
          action: () => void goto(),
          label: "Go to Terminals"
        },
        { action: () => void goto(), label: "Go to Settings" },
        {
          action: () => {
            showShortcutsHelp = true;
          },
          label: "Show keyboard shortcuts"
        }
      ];
      if (isRunning()) {
        cmds.push({ action: () => void killTerminal(), label: "Kill terminal" });
      }
      return cmds;
    });
    async function killTerminal() {
      {
        return;
      }
    }
    onDestroy(() => {
    });
    let $$settled = true;
    let $$inner_renderer;
    function $$render_inner($$renderer3) {
      head("1tubujq", $$renderer3, ($$renderer4) => {
        $$renderer4.title(($$renderer5) => {
          $$renderer5.push(`<title>${escape_html(commandName())} - Terminal - Shooter</title>`);
        });
        $$renderer4.push(`<meta name="description" content="Interactive terminal session" class="svelte-1tubujq"/>`);
      });
      {
        $$renderer3.push("<!--[0-->");
        $$renderer3.push(`<div class="term-page svelte-1tubujq"><div class="term-topbar svelte-1tubujq"><div class="skeleton svelte-1tubujq" style="width: 120px; height: 20px;"></div></div> <div class="term-body-loading svelte-1tubujq"><div class="skeleton svelte-1tubujq" style="width: 100%; height: 100%;"></div></div></div>`);
      }
      $$renderer3.push(`<!--]--> `);
      ShortcutsHelp($$renderer3, {
        open: showShortcutsHelp,
        onClose: () => {
          showShortcutsHelp = false;
        }
      });
      $$renderer3.push(`<!----> `);
      CommandPalette($$renderer3, {
        commands: paletteCommands(),
        onClose: () => {
          showCommandPalette = false;
        },
        get open() {
          return showCommandPalette;
        },
        set open($$value) {
          showCommandPalette = $$value;
          $$settled = false;
        }
      });
      $$renderer3.push(`<!---->`);
    }
    do {
      $$settled = true;
      $$inner_renderer = $$renderer2.copy();
      $$render_inner($$inner_renderer);
    } while (!$$settled);
    $$renderer2.subsume($$inner_renderer);
  });
}

export { _page as default };
//# sourceMappingURL=_page.svelte-DskND_G9.js.map
