<script lang="ts">
import { onMount } from "svelte";
import { plans } from "../../../stores/plans.svelte.js";
import { workbench } from "../../../stores/workbench.svelte.js";
import SidebarHeader from "../SidebarHeader.svelte";
onMount(() => {
void plans.load();
});
function isActive(name: string): boolean {
const input = workbench.activeTab?.input;
return input?.kind === "plan" && input.name === name;
}
function formatDate(unixSecs: number): string {
return new Date(unixSecs * 1000).toLocaleDateString(undefined, {
month: "short",
day: "numeric",
year: "numeric",
});
}
</script>
<!--
Embedded inside the Sessions panel's "Plans" section, which provides the
header — this renders only the list.
-->
<div class="plans-sidebar">
<SidebarHeader
title="Plans"
onrefresh={() => plans.load()}
refreshing={plans.loading}
refreshTitle="Re-read the plans"
/>
{#if plans.loading && plans.plans.length === 0}
<div class="skel-list">
{#each { length: 4 } as _, i}
<div class="skel-plan-item">
<div class="skel" style="width: {40 + ((i * 27) % 45)}%; height: var(--wb-control-size-10);"></div>
<div class="skel" style="width: var(--wb-control-size-60); height: var(--wb-control-size-8); margin-top: var(--wb-spacing-4);"></div>
</div>
{/each}
</div>
{:else if plans.plans.length === 0}
<div class="plans-empty">No plans found.</div>
{:else}
<div class="plans-list">
{#each plans.plans as plan (plan.name)}
<button
class="plan-item"
class:active={isActive(plan.name)}
onclick={() => workbench.openPlan(plan.name)}
title={plan.name}
>
<span class="plan-label">{plans.labelFor(plan.name)}</span>
<span class="plan-date">{formatDate(plan.created_at)}</span>
</button>
{/each}
</div>
{/if}
</div>
<style>
.plans-sidebar {
flex: 1;
min-height: 0;
display: flex;
flex-direction: column;
}
.skel-list {
display: flex;
flex-direction: column;
padding: var(--wb-spacing-4) 0;
}
.skel-plan-item {
padding: var(--wb-spacing-6) var(--wb-spacing-12);
}
.plans-empty {
padding: var(--wb-spacing-16) var(--wb-spacing-12);
font-size: var(--wb-font-size-12);
color: var(--vscode-disabledForeground);
}
.plans-list {
flex: 1;
min-height: 0;
overflow-y: auto;
padding: var(--wb-spacing-4) 0;
}
.plan-item {
display: flex;
flex-direction: column;
gap: var(--wb-spacing-2);
width: 100%;
padding: var(--wb-spacing-6) var(--wb-spacing-12);
text-align: left;
background: none;
border: none;
cursor: pointer;
color: var(--vscode-editor-foreground);
transition: background 0.1s;
}
.plan-item:hover {
background: var(--vscode-list-hoverBackground);
}
.plan-item.active {
background: color-mix(in srgb, var(--vscode-focusBorder) 12%, transparent);
}
.plan-label {
font-size: var(--wb-font-size-12);
line-height: 1.4;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.plan-date {
font-size: var(--wb-font-size-11);
color: var(--vscode-disabledForeground);
}
</style>