blob: 0b49f218f1eff522c3231a1ac6fbf7426381553f [file] [log] [blame]
philip.zeyliger26bc6592025-06-30 20:15:30 -07001/* eslint-disable @typescript-eslint/no-explicit-any */
Sean McCullough618bfb22025-06-25 20:52:30 +00002/**
3 * Demo module for sketch-container-status component
4 */
5
6import { DemoModule } from "./demo-framework/types";
7import {
8 demoUtils,
9 sampleContainerState,
10 lightUsageState,
11 heavyUsageState,
12} from "./demo-fixtures/index";
13
14const demo: DemoModule = {
15 title: "Container Status Demo",
16 description: "Display container status information with usage statistics",
17 imports: ["../sketch-container-status"],
18 styles: ["/dist/tailwind.css"],
19
20 setup: async (container: HTMLElement) => {
21 // Create demo sections
22 const basicSection = demoUtils.createDemoSection(
23 "Basic Container Status",
24 "Shows current container state with usage information",
25 );
26
27 const variationsSection = demoUtils.createDemoSection(
28 "Usage Variations",
29 "Different usage levels and states",
30 );
31
32 // Basic status component
33 const basicStatus = document.createElement(
34 "sketch-container-status",
35 ) as any;
36 basicStatus.id = "basic-status";
37 basicStatus.state = sampleContainerState;
38
39 // Light usage status
40 const lightStatus = document.createElement(
41 "sketch-container-status",
42 ) as any;
43 lightStatus.id = "light-status";
44 lightStatus.state = lightUsageState;
45
46 const lightLabel = document.createElement("h4");
47 lightLabel.textContent = "Light Usage";
banksean1ee0bc62025-07-22 23:24:18 +000048 lightLabel.style.cssText =
49 "margin: 20px 0 10px 0; color: var(--demo-label-color);";
Sean McCullough618bfb22025-06-25 20:52:30 +000050
51 // Heavy usage status
52 const heavyStatus = document.createElement(
53 "sketch-container-status",
54 ) as any;
55 heavyStatus.id = "heavy-status";
56 heavyStatus.state = heavyUsageState;
Sean McCullough49577492025-06-26 17:13:28 -070057 heavyStatus.lastCommit = {
58 hash: "deadbeef",
59 pushedBranch: "user/sketch/really-long-branch-name-that-stains-layout",
60 };
Sean McCullough618bfb22025-06-25 20:52:30 +000061 const heavyLabel = document.createElement("h4");
62 heavyLabel.textContent = "Heavy Usage";
banksean1ee0bc62025-07-22 23:24:18 +000063 heavyLabel.style.cssText =
64 "margin: 20px 0 10px 0; color: var(--demo-label-color);";
Sean McCullough618bfb22025-06-25 20:52:30 +000065
66 // Control buttons for interaction
67 const controlsDiv = document.createElement("div");
68 controlsDiv.style.cssText = "margin-top: 20px;";
69
70 const updateBasicButton = demoUtils.createButton(
71 "Update Basic Status",
72 () => {
73 const updatedState = {
74 ...sampleContainerState,
75 message_count: sampleContainerState.message_count + 1,
76 total_usage: {
77 ...sampleContainerState.total_usage!,
78 messages: sampleContainerState.total_usage!.messages + 1,
79 total_cost_usd: Number(
80 (sampleContainerState.total_usage!.total_cost_usd + 0.05).toFixed(
81 2,
82 ),
83 ),
84 },
85 };
86 basicStatus.state = updatedState;
87 },
88 );
89
90 const toggleSSHButton = demoUtils.createButton("Toggle SSH Status", () => {
91 const currentState = basicStatus.state;
92 basicStatus.state = {
93 ...currentState,
94 ssh_available: !currentState.ssh_available,
95 ssh_error: currentState.ssh_available ? "Connection failed" : undefined,
96 };
97 });
98
99 const resetButton = demoUtils.createButton("Reset to Defaults", () => {
100 basicStatus.state = sampleContainerState;
101 lightStatus.state = lightUsageState;
102 heavyStatus.state = heavyUsageState;
103 });
104
105 controlsDiv.appendChild(updateBasicButton);
106 controlsDiv.appendChild(toggleSSHButton);
107 controlsDiv.appendChild(resetButton);
108
109 // Assemble the demo
110 basicSection.appendChild(basicStatus);
111 basicSection.appendChild(controlsDiv);
112
113 variationsSection.appendChild(lightLabel);
114 variationsSection.appendChild(lightStatus);
115 variationsSection.appendChild(heavyLabel);
116 variationsSection.appendChild(heavyStatus);
117
118 container.appendChild(basicSection);
119 container.appendChild(variationsSection);
120
121 // Add some real-time updates
122 const updateInterval = setInterval(() => {
123 const states = [basicStatus, lightStatus, heavyStatus];
124 states.forEach((status) => {
125 if (status.state) {
126 const updatedState = {
127 ...status.state,
128 message_count:
129 status.state.message_count + Math.floor(Math.random() * 2),
130 };
131 if (Math.random() > 0.7) {
132 // 30% chance to update
133 status.state = updatedState;
134 }
135 }
136 });
137 }, 3000);
138
139 // Store interval for cleanup
140 (container as any).demoInterval = updateInterval;
141 },
142
143 cleanup: async () => {
144 // Clear any intervals
145 const container = document.getElementById("demo-container");
146 if (container && (container as any).demoInterval) {
147 clearInterval((container as any).demoInterval);
148 delete (container as any).demoInterval;
149 }
150 },
151};
152
153export default demo;