import{a as s,f as l,i as N,s as Q,j as Ee}from"../chunks/DoGIJDSZ.js";import{c,g as t,r as i,t as P,p as Ue,w as Ae,d as g,s as k,q as Je,v as Me,D as ze,A as F,b as e,x as A,$ as Fe,B as xe}from"../chunks/kzeZOqU5.js";import{e as ve,k as Ge,s as ee,i as He,a as Ve,B as V,I as Ie,c as ce,b as Xe,d as Ye}from"../chunks/aiM7Bbhi.js";import{h as Ze}from"../chunks/BQJR1fvD.js";import{A as We}from"../chunks/DzuS5Nbr.js";import{i as et}from"../chunks/gQJcRhou.js";import"../chunks/Dk1NUsIU.js";import{P as tt}from"../chunks/C87ZRWX0.js";var rt=l("<div><!></div>"),at=l("<div></div>");function nt(w,v){var _=at();ve(_,21,()=>v.steps,He,(d,C,T)=>{var x=rt();let K;var u=c(x);Ge(u,{get onclick(){return v.onhandleStepClick},get label(){return t(C).label},get icon(){return t(C).icon},stepIndex:T+1}),i(x),P(()=>K=ee(x,1,"step-container svelte-dvxh34",null,K,{"active-step":v.currentStepIndex===T,"completed-step":v.currentStepIndex>T})),s(d,x)}),i(_),P(()=>ee(_,1,`container ${v.classes??""??""}`,"svelte-dvxh34")),s(w,_)}var ot=l('<div class="card-description svelte-15b0v7e"> </div>'),st=l('<div class="card-header svelte-15b0v7e"><div class="card-title svelte-15b0v7e"> </div> <!></div>'),it=l('<div><!> <div class="card-content svelte-15b0v7e"><!></div></div>');function X(w,v){Ue(v,!0);var _=it(),d=c(_);{var C=K=>{var u=st(),I=c(u),p=c(I,!0);i(I);var E=g(I,2);{var G=L=>{var B=ot(),J=c(B,!0);i(B),P(()=>Q(J,v.description)),s(L,B)};N(E,L=>{typeof v.description=="string"&&v.description.length>0&&L(G)})}i(u),P(()=>Q(p,v.title)),s(K,u)};N(d,K=>{typeof v.title=="string"&&v.title.length>0&&K(C)})}var T=g(d,2),x=c(T);Ve(x,()=>v.children),i(T),i(_),P(()=>ee(_,1,`card ${v.classes??""??""}`,"svelte-15b0v7e")),s(w,_),Ae()}function Y(w){return w instanceof Error?w.message:typeof w=="string"?w:String(w)}function lt(){return Te()!==null}async function ct(){const w=Te();if(!w)throw new Error("Scanner not available");return w()}function Te(){if(typeof window>"u")return null;const w=window.ShooterBridge?.scanner;if(w&&typeof w.scan=="function")return()=>w.scan();const v=window.ShooterNativeBridge?.scanner;return v&&typeof v.scan=="function"?()=>v.scan():null}const Pe=`<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
  <path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"/>
  <polyline points="22 4 12 14.01 9 11.01"/>
</svg>
`,vt=`<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
  <polygon points="5 3 19 12 5 21 5 3"/>
</svg>
`,Re=`<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
  <circle cx="12" cy="12" r="10"/>
  <line x1="15" y1="9" x2="9" y2="15"/>
  <line x1="9" y1="9" x2="15" y2="15"/>
</svg>
`;var dt=l('<meta name="description" content="Configure notification system settings"/>'),ut=l(`<!> <!> <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>`,1),gt=l('<p class="input-help svelte-1gp6n77">Loading…</p>'),pt=l('<p class="input-help svelte-1gp6n77" style="color: var(--color-error, #f87171);"> </p>'),ft=l(`<p class="input-help svelte-1gp6n77">No devices registered yet. Open the Shooter app on your phone with this server's URL +
              API key — it registers automatically. Every notification fans out to all devices here.</p>`),ht=l('<span class="device-badge svelte-1gp6n77">this device</span>'),mt=l('<li class="device-row svelte-1gp6n77"><div class="device-meta svelte-1gp6n77"><span class="device-name svelte-1gp6n77"> <!></span> <span class="device-sub svelte-1gp6n77"> </span></div> <!></li>'),_t=l('<ul class="device-list svelte-1gp6n77"></ul>'),yt=l("<!> Test Connection",1),wt=l(`<p class="qr-description svelte-1gp6n77">Scan the QR code shown on your server's settings page to auto-configure the
                connection.</p> <!>`,1),St=l('<p class="qr-server-url svelte-1gp6n77">Server: <code class="svelte-1gp6n77"> </code></p>'),bt=l('<div class="qr-container svelte-1gp6n77"><img 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> <!>',1),kt=l('<div class="qr-placeholder svelte-1gp6n77"><p class="qr-loading-text svelte-1gp6n77">Generating QR code...</p></div>'),Ct=l('<p class="qr-error svelte-1gp6n77"> </p>'),xt=l(`<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>`),It=l("<!> <!>",1),Pt=l('<div class="qr-section svelte-1gp6n77"><!></div>'),Rt=l('<div class="provider-row svelte-1gp6n77"><!> <span class="provider-label svelte-1gp6n77"> </span> <span> </span></div>'),Ut=l('<div class="active-provider svelte-1gp6n77">Active: <strong> </strong></div>'),At=l('<div class="active-provider svelte-1gp6n77">Auto-detected from configured keys</div>'),Tt=l('<p class="ai-help svelte-1gp6n77">Run <code class="svelte-1gp6n77">shooter setup</code> to configure AI providers for summaries.</p>'),Bt=l('<div class="ai-providers svelte-1gp6n77"><!> <!></div>'),Dt=l('<p class="danger-description svelte-1gp6n77">Clear all saved configuration data from this device.</p> <!>',1),qt=l('<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"><!> <!> <!> <div class="button-group svelte-1gp6n77"><!> <!></div></section> <aside class="settings-sidebar svelte-1gp6n77"><!> <!> <!> <!></aside></div></div></main>');function Jt(w,v){Ue(v,!0);let _=k(""),d=k(""),C=k(Je([])),T=k(!1),x=k(""),K=k(""),u=k(""),I=k(!1),p=k(""),E=k(""),G=k(""),L=k(!1),B=k(""),J=k(!1),Be=k(!1),de=!1,W=k(!1);async function De(){if(!t(d).trim()){e(B,"Save an API key first to generate a QR code");return}e(L,!0),e(B,""),e(E,""),e(G,"");try{const r=await fetch("/api/qr-config",{headers:{Authorization:`Bearer ${t(d).trim()}`}});if(!r.ok){const n=await r.json();e(B,n.error||"Failed to generate QR code",!0);return}const a=await r.json();e(E,a.dataUrl,!0),e(G,a.serverUrl,!0)}catch(r){e(B,`Network error: ${Y(r)}`)}finally{e(L,!1)}}async function qe(){e(W,!0),e(u,""),e(p,"");try{const r=await ct();try{const a=JSON.parse(r);typeof a.serverUrl=="string"&&a.serverUrl&&e(_,a.serverUrl,!0),typeof a.apiKey=="string"&&a.apiKey&&e(d,a.apiKey,!0),await ae();const n=t(p);n!=="error"&&n!=="warning"&&(e(u,"Configuration updated from QR code"),e(p,"success"))}catch{e(u,"Invalid QR code data"),e(p,"error")}}catch(r){const a=Y(r);a!=="cancelled"&&(e(u,`Scanner error: ${a}`),e(p,"error"))}finally{e(W,!1)}}function te(){return typeof window>"u"?null:window.ShooterBridge?window.ShooterBridge:window.ShooterNativeBridge?window.ShooterNativeBridge:null}function re(){return window.location.origin}function ue(){const r=te();if(r&&!de)try{const a=JSON.parse(r.getConfig?.()??"{}");a.serverUrl&&e(_,a.serverUrl,!0),a.apiKey&&e(d,a.apiKey,!0);const n=r.getDeviceId?.();n&&e(K,n,!0),de=!0}catch{}e(J,lt(),!0)}Me(()=>{{const r=window.location.hash.slice(1);if(r){const a=new URLSearchParams(r),n=a.get("key"),h=a.get("url");n&&(e(d,n,!0),h&&e(_,h,!0),ae(),window.history.replaceState({},"",window.location.pathname))}if(!t(d))try{const a=localStorage.getItem("shooter_config");if(a){const n=JSON.parse(a);et(n)?(n.apiKey&&e(d,n.apiKey,!0),n.serverUrl&&e(_,n.serverUrl,!0),n.deviceToken&&localStorage.setItem("shooter_config",JSON.stringify({...n,deviceToken:null}))):localStorage.removeItem("shooter_config")}}catch{}if(ue(),t(_)||e(_,re(),!0),e(Be,!0),ne(),!t(J)){const a=setInterval(()=>{ue(),t(J)&&clearInterval(a)},200),n=setTimeout(()=>{clearInterval(a)},3e3);return()=>{clearInterval(a),clearTimeout(n)}}}});async function ae(){e(I,!0),e(u,""),e(p,"");try{const r=t(_).trim().replace(/\/+$/,"");localStorage.setItem("shooter_config",JSON.stringify({apiKey:t(d).trim(),deviceToken:null,lastUpdated:Date.now(),serverUrl:r||re()}));const a=te();a&&a.saveConfig?.(JSON.stringify({apiKey:t(d).trim(),serverUrl:r||re()})),(await fetch("/api/health")).ok?(e(u,"Configuration saved successfully"),e(p,"success")):(e(u,"Configuration saved but system health check failed"),e(p,"warning")),ne()}catch(r){e(u,`Configuration failed: ${Y(r)}`),e(p,"error")}e(I,!1)}async function Ne(){if(!t(d).trim()){e(u,"API key is required for testing"),e(p,"error");return}e(I,!0),e(u,""),e(p,"");try{const r={data:{source:"config-test",timestamp:Date.now()},message:`Configuration test at ${new Date().toLocaleTimeString()}`,title:"Configuration Test"},a=await fetch("/api/notify",{body:JSON.stringify(r),headers:{Authorization:`Bearer ${t(d)}`,"Content-Type":"application/json"},method:"POST"}),n=await a.json();a.ok?(e(u,"Test notification sent successfully"),e(p,"success")):(e(u,`Test failed: ${typeof n.error=="string"?n.error:"Unknown error"}`),e(p,"error"))}catch(r){e(u,`Network error: ${Y(r)}`),e(p,"error")}e(I,!1)}function Qe(){{localStorage.removeItem("shooter_config"),e(_,typeof window<"u"?window.location.origin:"",!0),e(d,""),e(C,[],!0),e(u,"Configuration cleared"),e(p,"success");const r=te();r&&r.saveConfig?.(JSON.stringify({apiKey:"",serverUrl:""}))}}async function ne(){if(!t(d).trim()){e(C,[],!0),e(x,"");return}e(T,!0);try{const r=await fetch("/api/device-token",{headers:{Authorization:`Bearer ${t(d).trim()}`}});if(r.ok){const a=await r.json();e(C,Array.isArray(a.devices)?a.devices:[],!0),e(x,"")}else e(C,[],!0),e(x,r.status===401?"Could not load devices: the API key was rejected (401). Check the key above.":`Could not load devices (HTTP ${r.status}).`,!0)}catch(r){e(C,[],!0),e(x,`Could not load devices: ${Y(r)}`)}e(T,!1)}async function Ke(r){e(u,""),e(p,"");try{const a=await fetch("/api/device-token",{body:JSON.stringify({id:r}),headers:{Authorization:`Bearer ${t(d).trim()}`,"Content-Type":"application/json"},method:"DELETE"});if(!a.ok){const n=await a.json().catch(()=>({}));e(u,`Failed to remove device: ${n.error??a.statusText}`),e(p,"error");return}}catch(a){e(u,`Failed to remove device: ${Y(a)}`),e(p,"error");return}await ne()}var oe=qt();Ze("1gp6n77",r=>{var a=dt();ze(()=>{Fe.title="Settings - Shooter"}),s(r,a)});var ge=c(oe),pe=g(c(ge),4),se=c(pe),fe=c(se);X(fe,{title:"Server Configuration",description:"Configure server connection and credentials",children:(r,a)=>{var n=ut(),h=F(n);Ie(h,{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 t(_)},set value(U){e(_,U,!0)}});var R=g(h,2);Ie(R,{name:"apiKey",label:"API Key",dataType:"password",placeholder:"Enter your API key",infoMessage:"Required for sending notifications",get value(){return t(d)},set value(U){e(d,U,!0)}}),xe(2),s(r,n)},$$slots:{default:!0}});var he=g(fe,2);X(he,{title:"Registered Devices",description:"Phones that receive push notifications",children:(r,a)=>{var n=Ee(),h=F(n);{var R=y=>{var o=gt();s(y,o)},U=y=>{var o=pt(),f=c(o,!0);i(o),P(()=>Q(f,t(x))),s(y,o)},j=y=>{var o=ft();s(y,o)},D=y=>{var o=_t();ve(o,21,()=>t(C),f=>f.id,(f,S)=>{var q=mt(),O=c(q),M=c(O),m=c(M),b=g(m);{var $=z=>{var Z=ht();s(z,Z)};N(b,z=>{t(S).deviceId&&t(S).deviceId===t(K)&&z($)})}i(M);var H=g(M,2),ie=c(H);i(H),i(O);var le=g(O,2);V(le,{classes:"btn-secondary",onclick:()=>{Ke(t(S).id)},text:"Remove"}),i(q),P(()=>{Q(m,`${(t(S).friendlyName||t(S).deviceId||"Unknown device")??""} `),Q(ie,`${t(S).platform??""} · ${t(S).appEnv??""} · ${t(S).tokenMasked??""}`)}),s(f,q)}),i(o),s(y,o)};N(h,y=>{t(T)?y(R):t(x)?y(U,1):t(C).length===0?y(j,2):y(D,-1)})}s(r,n)},$$slots:{default:!0}});var me=g(he,2);{var je=r=>{const a=A(()=>t(p)==="success"?Pe:t(p)==="error"?Re:We);{const n=R=>{ce(R,{get svg(){return t(a)},classes:"icon-16"})};let h=A(()=>t(p)||"info");Xe(r,{get text(){return t(u)},get classes(){return`banner-${t(h)??""}`},icon:n,$$slots:{icon:!0}})}};N(me,r=>{t(u)&&r(je)})}var _e=g(me,2),ye=c(_e);{let r=A(()=>t(I)||!t(d).trim());V(ye,{classes:"btn-secondary",onclick:Ne,get disabled(){return t(r)},children:(a,n)=>{var h=yt(),R=F(h);{var U=j=>{ce(j,{get svg(){return vt},classes:"icon-14"})};N(R,j=>{t(I)||j(U)})}xe(),s(a,h)},$$slots:{default:!0}})}var Oe=g(ye,2);{let r=A(()=>t(I)||!t(d).trim());V(Oe,{classes:"btn-primary",onclick:ae,get disabled(){return t(r)},get showLoader(){return t(I)},text:"Save Changes"})}i(_e),i(se);var we=g(se,2),Se=c(we);X(Se,{title:"Setup Guide",children:(r,a)=>{{let n=A(()=>t(d).trim()&&t(C).length>0?2:t(d).trim()?1:0);nt(r,{steps:[{label:"Get API Key"},{label:"Register a Device"},{label:"Test Connection"}],get currentStepIndex(){return t(n)},classes:"setup-stepper"})}},$$slots:{default:!0}});var be=g(Se,2);{let r=A(()=>t(J)?"Scan a QR code to connect":"Scan to connect your mobile app");X(be,{title:"Mobile App Setup",get description(){return t(r)},children:(a,n)=>{var h=Pt(),R=c(h);{var U=D=>{var y=wt(),o=g(F(y),2);{let f=A(()=>t(W)?"Scanning...":"Scan QR Code");V(o,{classes:"btn-secondary btn-sm",onclick:qe,get disabled(){return t(W)},get text(){return t(f)}})}s(D,y)},j=D=>{var y=It(),o=F(y);{var f=m=>{var b=bt(),$=F(b),H=c($);i($);var ie=g($,4);{var le=z=>{var Z=St(),Ce=g(c(Z)),Le=c(Ce,!0);i(Ce),i(Z),P(()=>Q(Le,t(G))),s(z,Z)};N(ie,z=>{t(G)&&z(le)})}P(()=>Ye(H,"src",t(E))),s(m,b)},S=m=>{var b=kt();s(m,b)},q=m=>{var b=Ct(),$=c(b,!0);i(b),P(()=>Q($,t(B))),s(m,b)},O=m=>{var b=xt();s(m,b)};N(o,m=>{t(E)?m(f):t(L)?m(S,1):t(B)?m(q,2):m(O,-1)})}var M=g(o,2);{let m=A(()=>t(L)||!t(d).trim()),b=A(()=>t(E)?"Regenerate QR Code":"Generate QR Code");V(M,{classes:"btn-secondary btn-sm",onclick:De,get disabled(){return t(m)},get text(){return t(b)}})}s(D,y)};N(R,D=>{t(J)?D(U):D(j,-1)})}i(h),s(a,h)},$$slots:{default:!0}})}var ke=g(be,2);X(ke,{title:"AI Providers",description:"NeuroLink-powered summaries and AI features",children:(r,a)=>{var n=Bt(),h=c(n);ve(h,17,()=>tt,o=>o.id,(o,f)=>{var S=Rt(),q=c(S);{let H=A(()=>v.data.aiProviders[t(f).id]?Pe:Re);ce(q,{get svg(){return t(H)},classes:"icon-14"})}var O=g(q,2),M=c(O,!0);i(O);var m=g(O,2);let b;var $=c(m,!0);i(m),i(S),P(()=>{Q(M,t(f).label),b=ee(m,1,"provider-status svelte-1gp6n77",null,b,{configured:v.data.aiProviders[t(f).id]}),Q($,v.data.aiProviders[t(f).id]?"configured":"not configured")}),s(o,S)});var R=g(h,2);{var U=o=>{var f=Ut(),S=g(c(f)),q=c(S,!0);i(S),i(f),P(()=>Q(q,v.data.activeProvider)),s(o,f)},j=o=>{var f=At();s(o,f)},D=A(()=>Object.values(v.data.aiProviders).some(Boolean)),y=o=>{var f=Tt();s(o,f)};N(R,o=>{v.data.activeProvider?o(U):t(D)?o(j,1):o(y,-1)})}i(n),s(r,n)},$$slots:{default:!0}});var $e=g(ke,2);X($e,{title:"Danger Zone",children:(r,a)=>{var n=Dt(),h=g(F(n),2);V(h,{classes:"btn-danger btn-sm",onclick:Qe,text:"Clear Configuration"}),s(r,n)},$$slots:{default:!0}}),i(we),i(pe),i(ge),i(oe),s(w,oe),Ae()}export{Jt as component};
