blob: da0e435676bc146ddc6214eae39f3ac36f239225 [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";
48 lightLabel.style.cssText = "margin: 20px 0 10px 0; color: #24292f;";
49
50 // Heavy usage status
51 const heavyStatus = document.createElement(
52 "sketch-container-status",
53 ) as any;
54 heavyStatus.id = "heavy-status";
55 heavyStatus.state = heavyUsageState;
Sean McCullough49577492025-06-26 17:13:28 -070056 heavyStatus.lastCommit = {
57 hash: "deadbeef",
58 pushedBranch: "user/sketch/really-long-branch-name-that-stains-layout",
59 };
Sean McCullough618bfb22025-06-25 20:52:30 +000060 const heavyLabel = document.createElement("h4");
61 heavyLabel.textContent = "Heavy Usage";
62 heavyLabel.style.cssText = "margin: 20px 0 10px 0; color: #24292f;";
63
64 // Control buttons for interaction
65 const controlsDiv = document.createElement("div");
66 controlsDiv.style.cssText = "margin-top: 20px;";
67
68 const updateBasicButton = demoUtils.createButton(
69 "Update Basic Status",
70 () => {
71 const updatedState = {
72 ...sampleContainerState,
73 message_count: sampleContainerState.message_count + 1,
74 total_usage: {
75 ...sampleContainerState.total_usage!,
76 messages: sampleContainerState.total_usage!.messages + 1,
77 total_cost_usd: Number(
78 (sampleContainerState.total_usage!.total_cost_usd + 0.05).toFixed(
79 2,
80 ),
81 ),
82 },
83 };
84 basicStatus.state = updatedState;
85 },
86 );
87
88 const toggleSSHButton = demoUtils.createButton("Toggle SSH Status", () => {
89 const currentState = basicStatus.state;
90 basicStatus.state = {
91 ...currentState,
92 ssh_available: !currentState.ssh_available,
93 ssh_error: currentState.ssh_available ? "Connection failed" : undefined,
94 };
95 });
96
97 const resetButton = demoUtils.createButton("Reset to Defaults", () => {
98 basicStatus.state = sampleContainerState;
99 lightStatus.state = lightUsageState;
100 heavyStatus.state = heavyUsageState;
101 });
102
103 controlsDiv.appendChild(updateBasicButton);
104 controlsDiv.appendChild(toggleSSHButton);
105 controlsDiv.appendChild(resetButton);
106
107 // Assemble the demo
108 basicSection.appendChild(basicStatus);
109 basicSection.appendChild(controlsDiv);
110
111 variationsSection.appendChild(lightLabel);
112 variationsSection.appendChild(lightStatus);
113 variationsSection.appendChild(heavyLabel);
114 variationsSection.appendChild(heavyStatus);
115
116 container.appendChild(basicSection);
117 container.appendChild(variationsSection);
118
119 // Add some real-time updates
120 const updateInterval = setInterval(() => {
121 const states = [basicStatus, lightStatus, heavyStatus];
122 states.forEach((status) => {
123 if (status.state) {
124 const updatedState = {
125 ...status.state,
126 message_count:
127 status.state.message_count + Math.floor(Math.random() * 2),
128 };
129 if (Math.random() > 0.7) {
130 // 30% chance to update
131 status.state = updatedState;
132 }
133 }
134 });
135 }, 3000);
136
137 // Store interval for cleanup
138 (container as any).demoInterval = updateInterval;
139 },
140
141 cleanup: async () => {
142 // Clear any intervals
143 const container = document.getElementById("demo-container");
144 if (container && (container as any).demoInterval) {
145 clearInterval((container as any).demoInterval);
146 delete (container as any).demoInterval;
147 }
148 },
149};
150
151export default demo;