import{b as s}from"./vendor-lit-B2r-dKc0.js";import{a as i}from"./vendor-mini-lit-CpUQub-j.js";import{r as d,p}from"./app-review-C3CmcSYC.js";import{setHashRoute as y}from"./app-routing-C_r2pdnC.js";import"./app-session-runtime-CeFJDILJ.js";import{g as P,r as R,a as I,s as N}from"./config-scope-JGNcscE4.js";import{al as w,Z as S,s as L,e as A,aa as B,j as C,X as O,P as E}from"./vendor-lucide-B9Yl1Gez.js";import"./vendor-marked-_iteVaMm.js";import"./app-panel-workspace-C3XDRCgE.js";import"./app-message-reducer-wATqnZGf.js";import"./vendor-sortable-B1o3v0Qs.js";import"./app-inbox-CaZD85aD.js";import"./app-pr-walkthrough-WipZACSB.js";let a=[],m=!0,x="",g=null,f=[],o=[],n="",u=!1;function te(){a=[],m=!0,x="",g=null,f=[],o=[],n="",u=!1}async function j(e=!0){e&&(m=!0,x="",d());try{const t=P(),r=t?`/api/slash-skills/details?projectId=${encodeURIComponent(t)}`:"/api/slash-skills/details",l=await p(r);if(l.ok){const c=await l.json();a=c.skills||[],f=c.directories||[]}else a=[],f=[];try{const c=await p("/api/project-config");if(c.ok){const h=await c.json();if(h.skill_directories)try{o=JSON.parse(h.skill_directories)}catch{o=[]}else o=[]}}catch{}}catch(t){x=t instanceof Error?t.message:String(t)}finally{m=!1,d()}}function _(e){g=g===e?null:e,d()}async function J(e){N(e),await j()}function b(){return s`
		<div class="flex items-center gap-2 px-4 py-3 border-b border-border">
			<button
				class="p-1 rounded-md hover:bg-secondary text-muted-foreground hover:text-foreground transition-colors"
				@click=${()=>y("landing")}
				title="Back"
			>${i(L,"sm")}</button>
			<h1 class="text-lg font-semibold flex items-center gap-2">
				${i(S,"sm")}
				Skills
			</h1>
		</div>
	`}function v(e){const r={project:"bg-blue-500/15 text-blue-700 dark:text-blue-400",personal:"bg-purple-500/15 text-purple-700 dark:text-purple-400",legacy:"bg-amber-500/15 text-amber-700 dark:text-amber-400","built-in":"bg-green-500/15 text-green-700 dark:text-green-400",custom:"bg-teal-500/15 text-teal-700 dark:text-teal-400"}[e]||"bg-muted text-muted-foreground";return s`<span class="inline-flex items-center px-1.5 py-0.5 text-[10px] font-medium rounded-full ${r}">${e}</span>`}function U(e){const t=`slash-${e.name}`,r=g===t,l=e.source==="built-in";return s`
		<div class="rounded-lg border border-border overflow-hidden">
			<button
				class="w-full flex items-center gap-3 px-4 py-3 text-left hover:bg-secondary/30 transition-colors cursor-pointer"
				@click=${()=>_(t)}
			>
				<span class="text-muted-foreground shrink-0">${i(w,"sm")}</span>
				<div class="flex-1 min-w-0">
					<div class="flex items-center gap-2">
						<span class="text-sm font-medium">/${e.name}</span>
						${v(e.source)}
					</div>
					<div class="text-xs text-muted-foreground mt-0.5 truncate">${e.description}</div>
				</div>
				${l?"":s`<span class="text-muted-foreground text-xs shrink-0">${r?"▾":"▸"}</span>`}
			</button>
			${r&&!l?s`
				<div class="border-t border-border px-4 py-3 bg-secondary/10">
					<div class="flex items-center gap-1.5 text-xs text-muted-foreground mb-3">
						${i(C,"xs")}
						<code class="text-[11px] break-all">${e.filePath}</code>
					</div>
					<div class="rounded-md border border-border bg-background p-3 overflow-x-auto">
						<pre class="text-xs font-mono whitespace-pre-wrap break-words text-foreground/80">${e.content}</pre>
					</div>
				</div>
			`:""}
		</div>
	`}async function D(){d();try{await p("/api/project-config",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({skill_directories:JSON.stringify(o)})});const e=await p("/api/slash-skills/details");if(e.ok){const t=await e.json();a=t.skills||[],f=t.directories||[],d()}}catch{}}async function k(){const e=n.trim();e&&(o=[...o,{path:e}],n="",await D())}async function F(e){o=o.filter((t,r)=>r!==e),await D()}function T(){const e=f.filter(t=>!t.isCustom);return s`
		<div class="rounded-lg border border-border overflow-hidden">
			<button
				class="w-full flex items-center gap-2 px-4 py-3 text-left hover:bg-secondary/30 transition-colors cursor-pointer"
				@click=${()=>{u=!u,d()}}
			>
				<span class="text-muted-foreground shrink-0">${i(u?A:B,"sm")}</span>
				<span class="text-muted-foreground shrink-0">${i(C,"sm")}</span>
				<span class="text-sm font-semibold">Skill Directories</span>
			</button>
			${u?s`
				<div class="border-t border-border px-4 py-3 flex flex-col gap-3">
					<!-- Default directories -->
					${e.length>0?s`
						<div class="flex flex-col gap-1.5">
							<div class="text-xs font-medium text-muted-foreground uppercase tracking-wide">Default</div>
							${e.map(t=>s`
								<div class="flex items-center gap-2 text-xs text-muted-foreground py-1 px-2 rounded bg-secondary/20">
									<code class="flex-1 text-[11px] break-all">${t.path}</code>
									${v(t.source)}
								</div>
							`)}
						</div>
					`:""}

					<!-- Custom directories -->
					<div class="flex flex-col gap-1.5">
						<div class="text-xs font-medium text-muted-foreground uppercase tracking-wide">Custom</div>
						${o.length>0?o.map((t,r)=>s`
							<div class="flex items-center gap-2 text-xs py-1 px-2 rounded bg-secondary/20">
								<code class="flex-1 text-[11px] break-all">${t.path}</code>
								${v("custom")}
								<button
									class="p-0.5 rounded hover:bg-destructive/15 text-muted-foreground hover:text-destructive transition-colors shrink-0"
									title="Remove directory"
									@click=${()=>F(r)}
								>${i(O,"xs")}</button>
							</div>
						`):s`<div class="text-xs text-muted-foreground italic">No custom directories configured.</div>`}
					</div>

					<!-- Add row -->
					<div class="flex items-center gap-2">
						<input
							type="text"
							class="flex-1 text-xs px-2 py-1.5 rounded border border-border bg-background text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring"
							placeholder="~/my-skills or /absolute/path"
							.value=${n}
							@input=${t=>{n=t.target.value,d()}}
							@keydown=${t=>{t.key==="Enter"&&n.trim()&&k()}}
						/>
						<button
							class="inline-flex items-center gap-1 text-xs px-2.5 py-1.5 rounded border border-border hover:bg-secondary transition-colors disabled:opacity-40 disabled:cursor-not-allowed"
							?disabled=${!n.trim()}
							@click=${k}
						>${i(E,"xs")} Add</button>
					</div>

					<div class="text-[11px] text-muted-foreground">
						Default directories are always scanned. Custom directories are additive.
					</div>
				</div>
			`:""}
		</div>
	`}function $(e){return e.length===0?s`<p class="text-sm text-muted-foreground italic">No skills found.</p>`:s`<div class="flex flex-col gap-2">${e.map(U)}</div>`}function se(){if(m)return s`
			<div class="flex-1 flex flex-col h-full">
				${b()}
				<div class="flex-1 flex items-center justify-center">
					<div class="text-sm text-muted-foreground">Loading skills…</div>
				</div>
			</div>
		`;if(x)return s`
			<div class="flex-1 flex flex-col h-full">
				${b()}
				<div class="flex-1 flex items-center justify-center">
					<div class="text-center">
						<p class="text-sm text-red-500 mb-2">${x}</p>
						<button class="text-xs text-muted-foreground hover:text-foreground underline" @click=${j}>Retry</button>
					</div>
				</div>
			</div>
		`;const e=a.filter(l=>l.source!=="built-in"),t=a.filter(l=>l.source==="built-in"),r=a.length;return s`
		<div class="flex-1 flex flex-col h-full">
			${b()}
			${R(I(),J)}
			<div class="flex-1 overflow-y-auto">
				<div class="max-w-3xl mx-auto px-4 py-6 flex flex-col gap-6">
					<div class="flex items-center justify-between">
						<div class="text-sm text-muted-foreground">
							${r} skill${r!==1?"s":""} available
						</div>
						<button
							class="text-xs text-muted-foreground hover:text-foreground transition-colors"
							@click=${()=>{y("settings","directories")}}
						>Manage scan directories &rarr;</button>
					</div>

					${T()}

					<div>
						<h2 class="text-sm font-semibold text-foreground mb-3 flex items-center gap-2">
							${i(w,"sm")}
							Slash Skills
							<span class="text-xs font-normal text-muted-foreground">(from .claude/skills/, .bobbit/skills/, and custom directories)</span>
						</h2>
						${e.length>0?$(e):s`<p class="text-sm text-muted-foreground italic">No custom skills found. Add SKILL.md files to <code class="text-[11px]">.claude/skills/</code> or <code class="text-[11px]">.bobbit/skills/</code> to define skills.</p>`}
					</div>

					${t.length>0?s`
						<div>
							<h2 class="text-sm font-semibold text-foreground mb-3 flex items-center gap-2">
								${i(S,"sm")}
								Built-in
							</h2>
							${$(t)}
						</div>
					`:""}
				</div>
			</div>
		</div>
	`}export{te as clearSkillsPageState,j as loadSkillsPageData,se as renderSkillsPage};
