import { aw as head } from './index-CoYB03g7.js';
import { g as goto } from './client-Ds1brw-8.js';
import { B as Button } from './Button-D0hZ7JYt.js';
import { I as Input } from './Input-OmIiydSx.js';
import { B as Banner } from './Banner-BgaAs1rs.js';
import './root-D4IoFC8F.js';
import './index2-dSGQ9Eaa.js';
import './state.svelte-CmHqngc_.js';
import './close-DR469d4F.js';

function _page($$renderer, $$props) {
  $$renderer.component(($$renderer2) => {
    let error = "";
    let newLabel = "";
    let creating = false;
    function getConfig() {
      try {
        const saved = localStorage.getItem("shooter_config");
        return saved ? JSON.parse(saved) : null;
      } catch {
        return null;
      }
    }
    async function create() {
      const config = getConfig();
      if (!config || !newLabel.trim()) {
        return;
      }
      creating = true;
      try {
        const res = await fetch("/api/sos", {
          body: JSON.stringify({ label: newLabel.trim() }),
          headers: {
            Authorization: `Bearer ${config.apiKey}`,
            "Content-Type": "application/json"
          },
          method: "POST"
        });
        if (res.ok) {
          const created = await res.json();
          void goto(`/sos/${created.id}`);
        } else {
          const d = await res.json().catch(() => ({}));
          error = d.error ?? `Failed to create (${res.status})`;
        }
      } catch {
        error = "Network error — could not create super-session";
      } finally {
        creating = false;
      }
    }
    let $$settled = true;
    let $$inner_renderer;
    function $$render_inner($$renderer3) {
      head("1ggfn1w", $$renderer3, ($$renderer4) => {
        $$renderer4.title(($$renderer5) => {
          $$renderer5.push(`<title>Session Over Sessions - Shooter</title>`);
        });
      });
      $$renderer3.push(`<main class="main sos-list svelte-1ggfn1w"><div class="page-head svelte-1ggfn1w"><div><h1 class="svelte-1ggfn1w">Session Over Sessions</h1> <p class="subtitle svelte-1ggfn1w">Coordinate multiple running agents as one super-session.</p></div></div> <div class="create-row svelte-1ggfn1w">`);
      Input($$renderer3, {
        dataType: "text",
        placeholder: "New super-session label…",
        classes: "sos-create-input",
        get value() {
          return newLabel;
        },
        set value($$value) {
          newLabel = $$value;
          $$settled = false;
        }
      });
      $$renderer3.push(`<!----> `);
      Button($$renderer3, {
        text: creating ? "Creating…" : "Create",
        disabled: creating || !newLabel.trim(),
        onclick: create,
        classes: "btn-create"
      });
      $$renderer3.push(`<!----></div> `);
      if (error) {
        $$renderer3.push("<!--[0-->");
        Banner($$renderer3, { text: error, classes: "banner-error" });
      } else {
        $$renderer3.push("<!--[-1-->");
      }
      $$renderer3.push(`<!--]--> `);
      {
        $$renderer3.push("<!--[0-->");
        $$renderer3.push(`<p class="muted svelte-1ggfn1w">Loading…</p>`);
      }
      $$renderer3.push(`<!--]--></main>`);
    }
    do {
      $$settled = true;
      $$inner_renderer = $$renderer2.copy();
      $$render_inner($$inner_renderer);
    } while (!$$settled);
    $$renderer2.subsume($$inner_renderer);
  });
}

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