import { k as head, h as attr_class, d as stringify, l as escape_html, o as ensure_array_like, aj as attr, al as spread_props, ak as bind_props, n as derived } from './index-BHoOpAe1.js';
import './markdown-W_mTBct0.js';
import { B as Button, h as html } from './Button-DPcpECFE.js';
import { I as Input } from './Input-M7rFN1IJ.js';
import { I as Icon } from './Icon-C2-613_Z.js';
import { c as closeSvg } from './close-DR469d4F.js';
import 'dompurify';
import 'marked';

function Banner($$renderer, $$props) {
  $$renderer.component(($$renderer2) => {
    let {
      text,
      icon,
      linkText,
      dismissible = false,
      visible = true,
      testId,
      rightContent,
      dismissIcon,
      onclick,
      ondismiss,
      classes
    } = $$props;
    let interactive = derived(() => typeof onclick === "function");
    function handleDismiss(event) {
      event.stopPropagation();
      visible = false;
      ondismiss?.();
    }
    if (visible) {
      $$renderer2.push("<!--[0-->");
      $$renderer2.push(`<div${attr_class(`banner ${stringify(classes ?? "")}`, "svelte-1gyjig")}${attr("role", interactive() ? "button" : null)}${attr("tabindex", interactive() ? 0 : null)}${attr("data-pw", typeof testId === "string" ? testId : null)}>`);
      if (typeof icon === "function") {
        $$renderer2.push("<!--[0-->");
        $$renderer2.push(`<div class="banner-icon svelte-1gyjig">`);
        icon($$renderer2);
        $$renderer2.push(`<!----></div>`);
      } else {
        $$renderer2.push("<!--[-1-->");
      }
      $$renderer2.push(`<!--]--> <div class="banner-text svelte-1gyjig">${escape_html(text)} `);
      if (typeof linkText === "string" && linkText.length > 0) {
        $$renderer2.push("<!--[0-->");
        $$renderer2.push(`<span class="banner-link-text svelte-1gyjig">${escape_html(linkText)}</span>`);
      } else {
        $$renderer2.push("<!--[-1-->");
      }
      $$renderer2.push(`<!--]--></div> `);
      if (typeof rightContent === "function") {
        $$renderer2.push("<!--[0-->");
        $$renderer2.push(`<div class="banner-right svelte-1gyjig">`);
        rightContent($$renderer2);
        $$renderer2.push(`<!----></div>`);
      } else {
        $$renderer2.push("<!--[-1-->");
      }
      $$renderer2.push(`<!--]--> `);
      if (dismissible) {
        $$renderer2.push("<!--[0-->");
        $$renderer2.push(`<div class="banner-dismiss svelte-1gyjig">`);
        Button($$renderer2, spread_props([
          { onclick: handleDismiss, ariaLabel: "Dismiss" },
          typeof testId === "string" ? { testId: `${testId}-dismiss` } : {},
          {
            children: ($$renderer3) => {
              if (typeof dismissIcon === "function") {
                $$renderer3.push("<!--[0-->");
                dismissIcon($$renderer3);
                $$renderer3.push(`<!---->`);
              } else {
                $$renderer3.push("<!--[-1-->");
                $$renderer3.push(`${html(closeSvg)}`);
              }
              $$renderer3.push(`<!--]-->`);
            },
            $$slots: { default: true }
          }
        ]));
        $$renderer2.push(`<!----></div>`);
      } else {
        $$renderer2.push("<!--[-1-->");
      }
      $$renderer2.push(`<!--]--></div>`);
    } else {
      $$renderer2.push("<!--[-1-->");
    }
    $$renderer2.push(`<!--]-->`);
    bind_props($$props, { visible });
  });
}
function Step($$renderer, $$props) {
  $$renderer.component(($$renderer2) => {
    let { stepIndex, label, icon, classes } = $$props;
    $$renderer2.push(`<div${attr_class(`step ${stringify(classes ?? "")}`, "svelte-1l1id7p")} role="button" tabindex="0">`);
    if (typeof icon === "string" && icon.length > 0) {
      $$renderer2.push("<!--[0-->");
      $$renderer2.push(`<div class="step-icon-container"><img class="step-icon"${attr("src", icon)} alt=""/></div>`);
    } else {
      $$renderer2.push("<!--[-1-->");
      $$renderer2.push(`<div class="step-index-container svelte-1l1id7p"><div class="step-index-text svelte-1l1id7p">${escape_html(stepIndex)}</div></div>`);
    }
    $$renderer2.push(`<!--]--> <div class="step-text svelte-1l1id7p">${escape_html(label)}</div> <div class="separator svelte-1l1id7p"></div></div>`);
  });
}
function Stepper($$renderer, $$props) {
  let { steps, currentStepIndex, classes } = $$props;
  $$renderer.push(`<div${attr_class(`container ${stringify(classes ?? "")}`, "svelte-vrgjs2")}><!--[-->`);
  const each_array = ensure_array_like(steps);
  for (let stepIndex = 0, $$length = each_array.length; stepIndex < $$length; stepIndex++) {
    let currentStep = each_array[stepIndex];
    $$renderer.push(`<div${attr_class("step-container svelte-vrgjs2", void 0, {
      "active-step": currentStepIndex === stepIndex,
      "completed-step": currentStepIndex > stepIndex
    })}>`);
    Step($$renderer, {
      label: currentStep.label,
      icon: currentStep.icon,
      stepIndex: stepIndex + 1
    });
    $$renderer.push(`<!----></div>`);
  }
  $$renderer.push(`<!--]--></div>`);
}
function Card($$renderer, $$props) {
  $$renderer.component(($$renderer2) => {
    let { children, title, description, classes } = $$props;
    $$renderer2.push(`<div${attr_class(`card ${stringify(classes ?? "")}`, "svelte-qdre9c")}>`);
    if (typeof title === "string" && title.length > 0) {
      $$renderer2.push("<!--[0-->");
      $$renderer2.push(`<div class="card-header svelte-qdre9c"><div class="card-title svelte-qdre9c">${escape_html(title)}</div> `);
      if (typeof description === "string" && description.length > 0) {
        $$renderer2.push("<!--[0-->");
        $$renderer2.push(`<div class="card-description svelte-qdre9c">${escape_html(description)}</div>`);
      } else {
        $$renderer2.push("<!--[-1-->");
      }
      $$renderer2.push(`<!--]--></div>`);
    } else {
      $$renderer2.push("<!--[-1-->");
    }
    $$renderer2.push(`<!--]--> <div class="card-content svelte-qdre9c">`);
    children($$renderer2);
    $$renderer2.push(`<!----></div></div>`);
  });
}
function toErrorMessage(err) {
  if (err instanceof Error) {
    return err.message;
  }
  if (typeof err === "string") {
    return err;
  }
  return String(err);
}
const PROVIDERS = [
  {
    cors: "proxy",
    envKeys: ["GOOGLE_AI_API_KEY"],
    id: "google-ai",
    label: "Google AI",
    model: "gemini-3.1-flash-lite-preview"
  },
  {
    cors: "proxy",
    envKeys: ["ANTHROPIC_API_KEY"],
    id: "anthropic",
    label: "Anthropic",
    model: "claude-haiku-4-5-20251001"
  },
  {
    cors: "proxy",
    envKeys: ["OPENAI_API_KEY"],
    id: "openai",
    label: "OpenAI",
    model: "gpt-4o-mini"
  },
  {
    cors: "proxy",
    envKeys: ["MISTRAL_API_KEY"],
    id: "mistral",
    label: "Mistral",
    model: "mistral-small-2506"
  },
  {
    cors: "direct",
    envKeys: ["LITELLM_API_KEY", "LITELLM_BASE_URL"],
    extraEnvKeys: ["LITELLM_MODEL"],
    id: "litellm",
    label: "LiteLLM",
    model: "open-large"
  }
];
const AlertTriangleSvg = '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">\n  <path d="M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"/>\n  <line x1="12" y1="9" x2="12" y2="13"/>\n  <line x1="12" y1="17" x2="12.01" y2="17"/>\n</svg>\n';
const CheckCircleSvg = '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">\n  <path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"/>\n  <polyline points="22 4 12 14.01 9 11.01"/>\n</svg>\n';
const PlaySvg = '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">\n  <polygon points="5 3 19 12 5 21 5 3"/>\n</svg>\n';
const XCircleSvg = '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">\n  <circle cx="12" cy="12" r="10"/>\n  <line x1="15" y1="9" x2="9" y2="15"/>\n  <line x1="9" y1="9" x2="15" y2="15"/>\n</svg>\n';
function _page($$renderer, $$props) {
  $$renderer.component(($$renderer2) => {
    const { data } = $$props;
    let serverUrl = "";
    let apiKey = "";
    let deviceToken = "";
    let result = "";
    let loading = false;
    let statusType = "";
    let qrDataUrl = "";
    let qrServerUrl = "";
    let qrLoading = false;
    let qrError = "";
    async function fetchQrCode() {
      if (!apiKey.trim()) {
        qrError = "Save an API key first to generate a QR code";
        return;
      }
      qrLoading = true;
      qrError = "";
      qrDataUrl = "";
      qrServerUrl = "";
      try {
        const response = await fetch("/api/qr-config", { headers: { Authorization: `Bearer ${apiKey.trim()}` } });
        if (!response.ok) {
          const data3 = await response.json();
          qrError = data3.error || "Failed to generate QR code";
          return;
        }
        const data2 = await response.json();
        qrDataUrl = data2.dataUrl;
        qrServerUrl = data2.serverUrl;
      } catch (error) {
        qrError = `Network error: ${toErrorMessage(error)}`;
      } finally {
        qrLoading = false;
      }
    }
    function getNativeBridge() {
      if (typeof window === "undefined") {
        return null;
      }
      if (window.ShooterBridge) {
        return window.ShooterBridge;
      }
      if (window.ShooterNativeBridge) {
        return window.ShooterNativeBridge;
      }
      return null;
    }
    function getDefaultServerUrl() {
      return window.location.origin;
    }
    async function saveConfiguration() {
      loading = true;
      result = "";
      statusType = "";
      try {
        const trimmedUrl = serverUrl.trim().replace(/\/+$/, "");
        localStorage.setItem("shooter_config", JSON.stringify({
          apiKey: apiKey.trim(),
          deviceToken: deviceToken.trim(),
          lastUpdated: Date.now(),
          serverUrl: trimmedUrl || getDefaultServerUrl()
        }));
        const bridge = getNativeBridge();
        if (bridge) {
          bridge.saveConfig?.(JSON.stringify({
            apiKey: apiKey.trim(),
            serverUrl: trimmedUrl || getDefaultServerUrl()
          }));
        }
        const response = await fetch("/api/health");
        if (response.ok) {
          result = "Configuration saved successfully";
          statusType = "success";
        } else {
          result = "Configuration saved but system health check failed";
          statusType = "warning";
        }
      } catch (error) {
        result = `Configuration failed: ${toErrorMessage(error)}`;
        statusType = "error";
      }
      loading = false;
    }
    async function testConfiguration() {
      if (!apiKey.trim()) {
        result = "API key is required for testing";
        statusType = "error";
        return;
      }
      loading = true;
      result = "";
      statusType = "";
      try {
        const testPayload = {
          data: { source: "config-test", timestamp: Date.now() },
          message: `Configuration test at ${(/* @__PURE__ */ new Date()).toLocaleTimeString()}`,
          title: "Configuration Test"
        };
        if (deviceToken.trim()) {
          testPayload.deviceToken = deviceToken.trim();
        }
        const response = await fetch("/api/notify", {
          body: JSON.stringify(testPayload),
          headers: {
            Authorization: `Bearer ${apiKey}`,
            "Content-Type": "application/json"
          },
          method: "POST"
        });
        const data2 = await response.json();
        if (response.ok) {
          result = "Test notification sent successfully";
          statusType = "success";
        } else {
          result = `Test failed: ${typeof data2.error === "string" ? data2.error : "Unknown error"}`;
          statusType = "error";
        }
      } catch (error) {
        result = `Network error: ${toErrorMessage(error)}`;
        statusType = "error";
      }
      loading = false;
    }
    function clearConfiguration() {
    }
    let $$settled = true;
    let $$inner_renderer;
    function $$render_inner($$renderer3) {
      head("1gp6n77", $$renderer3, ($$renderer4) => {
        $$renderer4.title(($$renderer5) => {
          $$renderer5.push(`<title>Settings - Shooter</title>`);
        });
        $$renderer4.push(`<meta name="description" content="Configure notification system settings"/>`);
      });
      $$renderer3.push(`<main class="main"><div class="settings-container svelte-1gp6n77"><div style="margin-bottom: var(--space-4);"><a href="/" class="back-link">← Back to Projects</a></div> <div class="page-header"><h1 class="page-title">Settings</h1> <p class="page-description">Configure your API credentials and notification preferences</p></div> <div class="settings-grid svelte-1gp6n77"><section class="settings-section svelte-1gp6n77">`);
      Card($$renderer3, {
        title: "Server Configuration",
        description: "Configure server connection and credentials",
        children: ($$renderer4) => {
          Input($$renderer4, {
            name: "serverUrl",
            label: "Server URL",
            dataType: "text",
            placeholder: "https://shooter.breezehq.dev",
            infoMessage: "Base URL of your Shooter server. Apps will reload with this URL on next launch.",
            get value() {
              return serverUrl;
            },
            set value($$value) {
              serverUrl = $$value;
              $$settled = false;
            }
          });
          $$renderer4.push(`<!----> `);
          Input($$renderer4, {
            name: "apiKey",
            label: "API Key",
            dataType: "password",
            placeholder: "Enter your API key",
            infoMessage: "Required for sending notifications",
            get value() {
              return apiKey;
            },
            set value($$value) {
              apiKey = $$value;
              $$settled = false;
            }
          });
          $$renderer4.push(`<!----> <p class="input-help svelte-1gp6n77">Find this in your <code class="svelte-1gp6n77">~/.shooter/.env</code> file. Run <code class="svelte-1gp6n77">shooter setup</code> to generate
            one.</p> `);
          Input($$renderer4, {
            name: "deviceToken",
            label: "Device Token",
            dataType: "text",
            placeholder: "64-character hex string",
            infoMessage: "Device token from app registration",
            classes: "input-mono",
            get value() {
              return deviceToken;
            },
            set value($$value) {
              deviceToken = $$value;
              $$settled = false;
            }
          });
          $$renderer4.push(`<!----> <p class="input-help svelte-1gp6n77">Optional — only needed for iOS/Android push notifications.</p>`);
        }
      });
      $$renderer3.push(`<!----> `);
      if (result) {
        $$renderer3.push("<!--[0-->");
        const bannerSvg = statusType === "success" ? CheckCircleSvg : statusType === "error" ? XCircleSvg : AlertTriangleSvg;
        {
          let icon = function($$renderer4) {
            Icon($$renderer4, { svg: bannerSvg, classes: "icon-16" });
          };
          Banner($$renderer3, {
            text: result,
            classes: `banner-${stringify(statusType || "info")}`,
            icon,
            $$slots: { icon: true }
          });
        }
      } else {
        $$renderer3.push("<!--[-1-->");
      }
      $$renderer3.push(`<!--]--> <div class="button-group svelte-1gp6n77">`);
      Button($$renderer3, {
        classes: "btn-secondary",
        onclick: testConfiguration,
        disabled: loading || !apiKey.trim(),
        children: ($$renderer4) => {
          if (!loading) {
            $$renderer4.push("<!--[0-->");
            Icon($$renderer4, { svg: PlaySvg, classes: "icon-14" });
          } else {
            $$renderer4.push("<!--[-1-->");
          }
          $$renderer4.push(`<!--]--> Test Connection`);
        },
        $$slots: { default: true }
      });
      $$renderer3.push(`<!----> `);
      Button($$renderer3, {
        classes: "btn-primary",
        onclick: saveConfiguration,
        disabled: loading || !apiKey.trim(),
        showLoader: loading,
        text: "Save Changes"
      });
      $$renderer3.push(`<!----></div></section> <aside class="settings-sidebar svelte-1gp6n77">`);
      Card($$renderer3, {
        title: "Setup Guide",
        children: ($$renderer4) => {
          Stepper($$renderer4, {
            steps: [
              { label: "Get API Key" },
              { label: "Find Device Token" },
              { label: "Test Connection" }
            ],
            currentStepIndex: apiKey.trim() && deviceToken.trim() ? 2 : apiKey.trim() ? 1 : 0,
            classes: "setup-stepper"
          });
        }
      });
      $$renderer3.push(`<!----> `);
      Card($$renderer3, {
        title: "Mobile App Setup",
        description: "Scan to connect your mobile app",
        children: ($$renderer4) => {
          $$renderer4.push(`<div class="qr-section svelte-1gp6n77">`);
          {
            $$renderer4.push("<!--[-1-->");
            if (qrDataUrl) {
              $$renderer4.push("<!--[0-->");
              $$renderer4.push(`<div class="qr-container svelte-1gp6n77"><img${attr("src", qrDataUrl)} alt="QR code for mobile app pairing" class="qr-image svelte-1gp6n77"/></div> <p class="qr-hint svelte-1gp6n77">Scan this QR code with the Shooter iOS or Android app to connect.</p> `);
              if (qrServerUrl) {
                $$renderer4.push("<!--[0-->");
                $$renderer4.push(`<p class="qr-server-url svelte-1gp6n77">Server: <code class="svelte-1gp6n77">${escape_html(qrServerUrl)}</code></p>`);
              } else {
                $$renderer4.push("<!--[-1-->");
              }
              $$renderer4.push(`<!--]-->`);
            } else if (qrLoading) {
              $$renderer4.push("<!--[1-->");
              $$renderer4.push(`<div class="qr-placeholder svelte-1gp6n77"><p class="qr-loading-text svelte-1gp6n77">Generating QR code...</p></div>`);
            } else if (qrError) {
              $$renderer4.push("<!--[2-->");
              $$renderer4.push(`<p class="qr-error svelte-1gp6n77">${escape_html(qrError)}</p>`);
            } else {
              $$renderer4.push("<!--[-1-->");
              $$renderer4.push(`<p class="qr-description svelte-1gp6n77">Generate a QR code containing your server URL and API key. Your mobile app can
                  scan it to auto-configure the connection.</p>`);
            }
            $$renderer4.push(`<!--]--> `);
            Button($$renderer4, {
              classes: "btn-secondary btn-sm",
              onclick: fetchQrCode,
              disabled: qrLoading || !apiKey.trim(),
              text: qrDataUrl ? "Regenerate QR Code" : "Generate QR Code"
            });
            $$renderer4.push(`<!---->`);
          }
          $$renderer4.push(`<!--]--></div>`);
        }
      });
      $$renderer3.push(`<!----> `);
      Card($$renderer3, {
        title: "AI Providers",
        description: "NeuroLink-powered summaries and AI features",
        children: ($$renderer4) => {
          $$renderer4.push(`<div class="ai-providers svelte-1gp6n77"><!--[-->`);
          const each_array = ensure_array_like(PROVIDERS);
          for (let $$index = 0, $$length = each_array.length; $$index < $$length; $$index++) {
            let provider = each_array[$$index];
            $$renderer4.push(`<div class="provider-row svelte-1gp6n77">`);
            Icon($$renderer4, {
              svg: data.aiProviders[provider.id] ? CheckCircleSvg : XCircleSvg,
              classes: "icon-14"
            });
            $$renderer4.push(`<!----> <span class="provider-label svelte-1gp6n77">${escape_html(provider.label)}</span> <span${attr_class("provider-status svelte-1gp6n77", void 0, { "configured": data.aiProviders[provider.id] })}>${escape_html(data.aiProviders[provider.id] ? "configured" : "not configured")}</span></div>`);
          }
          $$renderer4.push(`<!--]--> `);
          if (data.activeProvider) {
            $$renderer4.push("<!--[0-->");
            $$renderer4.push(`<div class="active-provider svelte-1gp6n77">Active: <strong>${escape_html(data.activeProvider)}</strong></div>`);
          } else if (Object.values(data.aiProviders).some(Boolean)) {
            $$renderer4.push("<!--[1-->");
            $$renderer4.push(`<div class="active-provider svelte-1gp6n77">Auto-detected from configured keys</div>`);
          } else {
            $$renderer4.push("<!--[-1-->");
            $$renderer4.push(`<p class="ai-help svelte-1gp6n77">Run <code class="svelte-1gp6n77">shooter setup</code> to configure AI providers for summaries.</p>`);
          }
          $$renderer4.push(`<!--]--></div>`);
        }
      });
      $$renderer3.push(`<!----> `);
      Card($$renderer3, {
        title: "Danger Zone",
        children: ($$renderer4) => {
          $$renderer4.push(`<p class="danger-description svelte-1gp6n77">Clear all saved configuration data from this device.</p> `);
          Button($$renderer4, {
            classes: "btn-danger btn-sm",
            onclick: clearConfiguration,
            text: "Clear Configuration"
          });
          $$renderer4.push(`<!---->`);
        }
      });
      $$renderer3.push(`<!----></aside></div></div></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-DfZBq0p5.js.map
